Skip to content

Commit eebee75

Browse files
committed
feat(editor): add search, recovery and editor preference rules
1 parent c001967 commit eebee75

13 files changed

Lines changed: 1150 additions & 4 deletions

File tree

‎rust/contracts/rust-core-api.md‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6253,3 +6253,65 @@ and deduplicated. No setting values cross windows: receivers read their own
62536253
project layers. Native owners must recheck window/project lifetime on delivery.
62546254
Invalid surface input returns `plugin.settings.invalidSurface`; owner mismatch
62556255
returns `plugin.settings.ownerChanged`. Shared vectors: `rust/fixtures/plugins/settings-surfaces.json`.
6256+
6257+
6258+
### Editor essentials (desktop internal commands)
6259+
6260+
`editor.find` executes through `lithe_core_execute_document_json(request, bytes, length)`.
6261+
The caller owns valid UTF-8 bytes for the synchronous call; Core borrows them only until
6262+
return, retains no pointer or text cache, and returns its normal owned response string
6263+
(free with `lithe_core_free_string`). A null buffer is valid only at length zero.
6264+
The ordinary JSON entry point rejects this command with `missing_document`.
6265+
Cancellation uses the operation ID registry, including cancellation checks between matches.
6266+
The host must run on a worker and guard the document snapshot and query generation before
6267+
applying ranges or a replacement. This ABI adds no public plugin host methods.
6268+
6269+
The payload is `{query, caseSensitive?:false, wholeWord?:false, regex?:false,
6270+
range?:{start,end}, replacement?:string, replaceStart?:number, caret?:0, backwards?:false}`.
6271+
All offsets are original UTF-8 byte offsets, half-open and on rune boundaries. An omitted
6272+
range searches the whole snapshot. Regex uses Unicode case folding/word boundaries and
6273+
multiline anchors; regex replacement expands `$1`/`${name}` captures; literal replacement
6274+
preserves dollar signs. `replaceStart` selects only that match; omitted means replace all.
6275+
Results are `{matches:[{start,end}],edits:[{start,end,text}],selected:number|null,truncated}`.
6276+
Scoped requests also return `range`, adjusted for the planned replacement lengths so the
6277+
selection remains valid after applying a bulk edit.
6278+
Limits: 64 MiB source, 4096-byte query, 10,000 returned matches, 8 MiB total inserted text,
6279+
1 MiB compiled regex and 2 MiB DFA. A truncated search is useful for navigation but bulk
6280+
replacement fails atomically. Invalid requests return `invalid_request` with stable details:
6281+
`invalid_request`, `missing_document`, `invalid_range`, `invalid_pattern`, `query_too_large`,
6282+
`source_too_large`, `source_too_large_or_invalid`, `replacement_too_large`, `too_many_matches`.
6283+
Source, query and replacement are never included in errors or diagnostic logs.
6284+
6285+
`editor.preferences.resolve` accepts optional `lineNumbers`, `whitespace`, `cursorStyle`
6286+
(`line`, `block`, `underline`), `cursorBlink` and `autoSaveDelayMilliseconds`. It returns
6287+
actual values and minimum/maximum delay. Defaults: true, false, line, true, 1500 ms;
6288+
unknown styles resolve to line and delay clamps to 250–60,000 ms.
6289+
6290+
`editor.recent.reduce` accepts `entries`, optional `event:{kind,path,name,line,column}`,
6291+
`query` and `onlyEdited`. It returns bounded `entries` and filtered `results`. Paths are
6292+
opaque host-owned workspace-relative identities, position is zero-based UTF-16. Kinds are
6293+
opened/edited/removed. Logical sequence numbers produce deterministic MRU order independent
6294+
of clocks; edit recency survives subsequent opens. Up to 80 entries, 4096-byte query,
6295+
32,768-byte path, 1024-byte name. Native storage and rendering belong to the host.
6296+
6297+
`editor.recovery.decide` accepts `{baseHash,diskHash?,scratch?,bytes?,saved?,discarded?}`.
6298+
It returns action `remove`, `tooLarge`, `restoreScratch`, `restore`, or `restoreConflict`,
6299+
plus `maxDocumentBytes` (64 MiB), `maxStorageBytes` (256 MiB), `maxDocuments` (64).
6300+
Hash equality is a native fact (including actual encoding bytes where applicable).
6301+
Missing or changed disk data retains a conflict; it never authorizes an overwrite.
6302+
The native adapter owns private atomic checkpoint files in application data, quota
6303+
accounting, write serialization, and explicit save/discard cleanup. Recovery is independent
6304+
of auto-save. A save/remove queued after a checkpoint must win over that checkpoint.
6305+
6306+
`keymap.schemes.reduce` accepts `{state:{active,schemes:[{id,name,bindings}]},current?,
6307+
operation?,id?,name?,bindings?}` and returns `{state,bindings}` for the active scheme.
6308+
Empty state migrates current overrides into default. Operations: empty (resolve), update,
6309+
select, saveAs (clone active), rename and delete. Default cannot be renamed/deleted;
6310+
deleting the active custom scheme selects default. Up to 16 schemes; names trim to 1–64
6311+
characters without controls and are case-insensitively unique; IDs are ASCII alphanumeric,
6312+
hyphen or underscore, up to 64 bytes. Bindings use existing explicit-modifier key syntax.
6313+
Failures use `invalid_request` plus stable details such as `invalid_name`, `duplicate_name`,
6314+
`too_many_schemes`, `missing_scheme`, `default_is_fixed` and `invalid_binding`.
6315+
No third-party keymap import or plugin protocol change is introduced.
6316+
6317+
Executable vectors: `rust/fixtures/editor/ide-essentials-v1.json` (C ABI tests).
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
{
2+
"version": 1,
3+
"cases": [
4+
{
5+
"name": "unicode-original-byte-offsets",
6+
"command": "editor.find",
7+
"document": "😀 αβ αβ",
8+
"payload": {
9+
"query": "αβ"
10+
},
11+
"expected": {
12+
"matches": [
13+
{
14+
"start": 5,
15+
"end": 9
16+
},
17+
{
18+
"start": 10,
19+
"end": 14
20+
}
21+
],
22+
"edits": [],
23+
"selected": 0,
24+
"truncated": false
25+
}
26+
},
27+
{
28+
"name": "regex-capture-expansion",
29+
"command": "editor.find",
30+
"document": "one two",
31+
"payload": {
32+
"query": "(one)",
33+
"regex": true,
34+
"replacement": "${1}!"
35+
},
36+
"expected": {
37+
"matches": [
38+
{
39+
"start": 0,
40+
"end": 3
41+
}
42+
],
43+
"edits": [
44+
{
45+
"start": 0,
46+
"end": 3,
47+
"text": "one!"
48+
}
49+
],
50+
"selected": 0,
51+
"truncated": false
52+
}
53+
},
54+
{
55+
"name": "preferences-defaults",
56+
"command": "editor.preferences.resolve",
57+
"payload": {},
58+
"expected": {
59+
"lineNumbers": true,
60+
"whitespace": false,
61+
"cursorStyle": "line",
62+
"cursorBlink": true,
63+
"autoSaveDelayMilliseconds": 1500,
64+
"minimumAutoSaveDelayMilliseconds": 250,
65+
"maximumAutoSaveDelayMilliseconds": 60000
66+
}
67+
},
68+
{
69+
"name": "changed-disk-keeps-conflict",
70+
"command": "editor.recovery.decide",
71+
"payload": {
72+
"baseHash": "old",
73+
"diskHash": "new",
74+
"bytes": 20
75+
},
76+
"expected": {
77+
"action": "restoreConflict",
78+
"maxDocumentBytes": 67108864,
79+
"maxStorageBytes": 268435456,
80+
"maxDocuments": 64
81+
}
82+
},
83+
{
84+
"name": "recent-edit-records-position",
85+
"command": "editor.recent.reduce",
86+
"payload": {
87+
"event": {
88+
"kind": "edited",
89+
"path": "src/a.txt",
90+
"name": "a.txt",
91+
"line": 2,
92+
"column": 3
93+
}
94+
},
95+
"expected": {
96+
"entries": [
97+
{
98+
"path": "src/a.txt",
99+
"name": "a.txt",
100+
"line": 2,
101+
"column": 3,
102+
"opened": 1,
103+
"edited": 1
104+
}
105+
],
106+
"results": [
107+
{
108+
"path": "src/a.txt",
109+
"name": "a.txt",
110+
"line": 2,
111+
"column": 3,
112+
"opened": 1,
113+
"edited": 1
114+
}
115+
]
116+
}
117+
},
118+
{
119+
"name": "migrate-empty-keymap",
120+
"command": "keymap.schemes.reduce",
121+
"payload": {
122+
"state": {}
123+
},
124+
"expected": {
125+
"state": {
126+
"active": "default",
127+
"schemes": [
128+
{
129+
"id": "default",
130+
"name": "",
131+
"bindings": {}
132+
}
133+
]
134+
},
135+
"bindings": {}
136+
}
137+
},
138+
{
139+
"name": "selection-shrinks-with-replacement",
140+
"command": "editor.find",
141+
"document": "x alpha alpha y",
142+
"payload": {
143+
"query": "alpha",
144+
"range": {
145+
"start": 2,
146+
"end": 13
147+
},
148+
"replacement": "a"
149+
},
150+
"expected": {
151+
"matches": [
152+
{
153+
"start": 2,
154+
"end": 7
155+
},
156+
{
157+
"start": 8,
158+
"end": 13
159+
}
160+
],
161+
"edits": [
162+
{
163+
"start": 2,
164+
"end": 7,
165+
"text": "a"
166+
},
167+
{
168+
"start": 8,
169+
"end": 13,
170+
"text": "a"
171+
}
172+
],
173+
"selected": 0,
174+
"truncated": false,
175+
"range": {
176+
"start": 2,
177+
"end": 5
178+
}
179+
}
180+
}
181+
]
182+
}

‎rust/lithe-core/include/lithe_core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const char *lithe_core_version(void);
1313
int32_t lithe_core_is_plain_text(const uint8_t *bytes, size_t length);
1414
int32_t lithe_core_git_askpass(const char *prompt);
1515
char *lithe_core_execute_json(const char *request);
16+
/* Immutable source borrowed only until return; response uses lithe_core_free_string. */
17+
char *lithe_core_execute_document_json(const char *request, const uint8_t *bytes, size_t length);
1618
char *lithe_core_execute_json_with_events(const char *request, void (*callback)(const char *, void *), void *context);
1719
char *lithe_core_lsp_provider_catalog_json(const char *workspace_root);
1820
int32_t lithe_core_cancel(const char *operation_id);

0 commit comments

Comments
 (0)