opencode-quill 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +27 -26
- package/package.json +1 -1
- package/src/ghost.ts +138 -33
- package/src/keymap.ts +11 -3
- package/src/predictor.ts +27 -9
- package/src/tui.tsx +17 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ All notable changes are documented in this file using
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.10.0] - 2026-11-27
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **composer:** Show an alternatives picker above the active word (#36)
|
|
12
|
+
|
|
13
|
+
## [0.9.2] - 2026-11-27
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- **predictor:** Prefer supported and unambiguous spelling repairs (#35)
|
|
18
|
+
|
|
7
19
|
## [0.9.1] - 2026-11-27
|
|
8
20
|
|
|
9
21
|
### Fixed
|
|
@@ -187,6 +199,8 @@ All notable changes are documented in this file using
|
|
|
187
199
|
- `/quill` command and command palette action to toggle autocomplete.
|
|
188
200
|
- Local installer script, full test suite, CI workflows, and release tooling.
|
|
189
201
|
|
|
202
|
+
[0.10.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.9.2...v0.10.0
|
|
203
|
+
[0.9.2]: https://github.com/ozandogrultan/opencode-quill/compare/v0.9.1...v0.9.2
|
|
190
204
|
[0.9.1]: https://github.com/ozandogrultan/opencode-quill/compare/v0.9.0...v0.9.1
|
|
191
205
|
[0.9.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.8.0...v0.9.0
|
|
192
206
|
[0.8.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.7.1...v0.8.0
|
package/README.md
CHANGED
|
@@ -201,9 +201,9 @@ Restart OpenCode after editing `cli.json`.
|
|
|
201
201
|
| `minSuggestedWordLength` | `number` | `0` | Minimum number of characters in a suggested word, for both prose and shell suggestions; `0` allows any length. |
|
|
202
202
|
| `acceptKeys` | `string[]` | `["tab", "right"]` | Keys that accept and insert the active word suggestion. |
|
|
203
203
|
| `dismissKeys` | `string[]` | `["escape"]` | Keys that dismiss the visible suggestion without inserting. |
|
|
204
|
-
| `cycleNextKeys` | `string[]` | `[]` | Opt-in keys
|
|
205
|
-
| `cyclePreviousKeys` | `string[]` | `[]` | Opt-in keys
|
|
206
|
-
| `summonKeys` | `string[]` | `[]` | Opt-in keys to
|
|
204
|
+
| `cycleNextKeys` | `string[]` | `[]` | Opt-in keys to select the next alternative and open the picker, for example `["alt+n"]`. |
|
|
205
|
+
| `cyclePreviousKeys` | `string[]` | `[]` | Opt-in keys to select the previous alternative and open the picker, for example `["alt+p"]`. |
|
|
206
|
+
| `summonKeys` | `string[]` | `[]` | Opt-in keys to open the picker or summon candidates on demand, for example `["ctrl+y"]`. |
|
|
207
207
|
|
|
208
208
|
`completeAtLineEnd` uses prose context only up to the cursor while checking
|
|
209
209
|
code and attachment ranges across the full draft. It inserts only missing
|
|
@@ -212,32 +212,28 @@ replacements remain limited to chip-free draft ends. The suggestion must fit
|
|
|
212
212
|
the visible cursor row; it never overwrites the next line. Acceptance preserves
|
|
213
213
|
later lines, attachment metadata, host callbacks, and native undo/redo.
|
|
214
214
|
|
|
215
|
-
Quill shows one inline suggestion by default.
|
|
216
|
-
|
|
217
|
-
when space allows. Cycling changes only the ghost text; Tab accepts the
|
|
218
|
-
selected suggestion. The list wraps and skips alternatives that do not fit on
|
|
219
|
-
the cursor row. Without a visible alternative, cycle keys fall through.
|
|
215
|
+
Quill shows one inline suggestion by default. To open the alternatives picker
|
|
216
|
+
with Ctrl+Y, add this to the Quill plugin's `options`:
|
|
220
217
|
|
|
221
|
-
|
|
222
|
-
candidates for the current draft when no suggestion is visible. It falls
|
|
223
|
-
through when Quill has no eligible candidate. Editing the draft or moving the
|
|
224
|
-
cursor resets the summoned list.
|
|
225
|
-
|
|
226
|
-
Custom keybindings can also be overridden using OpenCode's standard
|
|
227
|
-
`keybinds` map in `cli.json`:
|
|
228
|
-
|
|
229
|
-
```jsonc
|
|
218
|
+
```json
|
|
230
219
|
{
|
|
231
|
-
"
|
|
232
|
-
"quill.accept": "tab",
|
|
233
|
-
"quill.dismiss": "ctrl+g",
|
|
234
|
-
"quill.next": "alt+n",
|
|
235
|
-
"quill.previous": "alt+p",
|
|
236
|
-
"quill.summon": "ctrl+y"
|
|
237
|
-
}
|
|
220
|
+
"summonKeys": ["ctrl+y"]
|
|
238
221
|
}
|
|
239
222
|
```
|
|
240
223
|
|
|
224
|
+
Press Ctrl+Y to see the available words above the active word. If no
|
|
225
|
+
automatic suggestion appears, Ctrl+Y can summon lower-confidence candidates.
|
|
226
|
+
While the list is visible, Up and Down move the highlight and the inline ghost previews the
|
|
227
|
+
selection. Tab accepts it, Escape closes the list, and editing the draft or
|
|
228
|
+
moving the cursor resets it. Enter keeps its usual behavior.
|
|
229
|
+
|
|
230
|
+
For direct cycling, optionally set `cycleNextKeys` to `["alt+n"]` and
|
|
231
|
+
`cyclePreviousKeys` to `["alt+p"]`. These open the picker and cycle immediately,
|
|
232
|
+
even without a summon key. If there isn't room above the word, the cycle keys
|
|
233
|
+
still work inline. With only a summon key, press it again to cycle inline.
|
|
234
|
+
Cycling skips suggestions that don't fit on the cursor row. Up and Down keep
|
|
235
|
+
their normal behavior when no picker is visible.
|
|
236
|
+
|
|
241
237
|
Quill's accept/dismiss/cycle layer runs in base mode at priority `2`, only in
|
|
242
238
|
the focused normal composer. A visible suggestion takes Tab/Right for
|
|
243
239
|
acceptance and Escape for dismissal. With no eligible visible suggestion,
|
|
@@ -306,8 +302,13 @@ Quill learns from your own submitted prompts, never from assistant output:
|
|
|
306
302
|
Corrections require at least three typed letters. Short words are eligible
|
|
307
303
|
only for whole-word letter swaps that preserve the first letter; other edits
|
|
308
304
|
and mistyped longer prefixes require at least five letters, except for
|
|
309
|
-
apostrophe contractions, including missing apostrophes.
|
|
310
|
-
|
|
305
|
+
apostrophe contractions, including missing apostrophes. A missing apostrophe
|
|
306
|
+
can be restored even when the typed word exists if the contraction has
|
|
307
|
+
repeated evidence and accounts for more than half of the learned continuations
|
|
308
|
+
after the previous word. Deletions repair only doubled letters. A final letter
|
|
309
|
+
after an otherwise known word does not trigger a longer typo completion
|
|
310
|
+
by substitution alone.
|
|
311
|
+
Equally scored spelling repairs are withheld unless explicitly summoned.
|
|
311
312
|
Unknown tokens such as `json`, `yaml`, `bool`, `opts`,
|
|
312
313
|
and `enum` are left unchanged, and uncertain typos such as `fucn` can produce
|
|
313
314
|
no suggestion. Context repair uses the same edit guards and confidence checks
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-quill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "OpenCode prompt autocomplete: local n-gram word and next-word prediction shown as inline ghost text in the TUI composer, accepted with Tab.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/ghost.ts
CHANGED
|
@@ -12,6 +12,39 @@ export type Composer = {
|
|
|
12
12
|
enabled: boolean
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
type Alternatives = {
|
|
16
|
+
summon?: string
|
|
17
|
+
cycle: boolean
|
|
18
|
+
accept?: string
|
|
19
|
+
dismiss?: string
|
|
20
|
+
colors: {
|
|
21
|
+
text: RGBA
|
|
22
|
+
muted: RGBA
|
|
23
|
+
background: RGBA
|
|
24
|
+
selectedText: RGBA
|
|
25
|
+
selectedBackground: RGBA
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type CandidateMemo = {
|
|
30
|
+
text: string
|
|
31
|
+
offset: number
|
|
32
|
+
marks: string
|
|
33
|
+
revision: number
|
|
34
|
+
predictor: WordPredictor
|
|
35
|
+
predictions: Prediction[]
|
|
36
|
+
index: number
|
|
37
|
+
summoned: boolean
|
|
38
|
+
prefix: string
|
|
39
|
+
picker: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type PaintedSuggestion = {
|
|
43
|
+
memo: CandidateMemo
|
|
44
|
+
prediction: Prediction
|
|
45
|
+
picker?: { geometry: string; drawn: boolean }
|
|
46
|
+
}
|
|
47
|
+
|
|
15
48
|
export function dimGhostColor(muted: RGBA): RGBA {
|
|
16
49
|
return RGBA.fromValues(muted.r, muted.g, muted.b, muted.a * 0.55)
|
|
17
50
|
}
|
|
@@ -40,9 +73,9 @@ export function findComposer(marker: Renderable | undefined, isEditor: (node: Re
|
|
|
40
73
|
}
|
|
41
74
|
|
|
42
75
|
export class ComposerGhost {
|
|
43
|
-
private shown:
|
|
76
|
+
private shown: PaintedSuggestion | undefined
|
|
44
77
|
private dismissed: { text: string; offset: number } | undefined
|
|
45
|
-
private memo:
|
|
78
|
+
private memo: CandidateMemo | undefined
|
|
46
79
|
private disposed = false
|
|
47
80
|
private readonly draw: (buffer: OptimizedBuffer, delta: number) => void
|
|
48
81
|
|
|
@@ -54,7 +87,7 @@ export class ComposerGhost {
|
|
|
54
87
|
private readonly renderer: CliRenderer,
|
|
55
88
|
private readonly completeAtLineEnd = false,
|
|
56
89
|
private readonly shellPredictor?: WordPredictor,
|
|
57
|
-
private readonly
|
|
90
|
+
private readonly alternatives?: () => Alternatives,
|
|
58
91
|
) {
|
|
59
92
|
this.draw = (buffer) => { if (!this.disposed) this.paint(buffer) }
|
|
60
93
|
renderer.addPostProcessFn(this.draw)
|
|
@@ -107,21 +140,64 @@ export class ComposerGhost {
|
|
|
107
140
|
const revision = predictor.modelRevision
|
|
108
141
|
if (this.memo?.text === text && this.memo.offset === offset && this.memo.marks === signature && this.memo.revision === revision && this.memo.predictor === predictor) return this.memo.predictions[this.memo.index]
|
|
109
142
|
const query = completionQuery(text, offset, this.protectedRanges(marks), this.completeAtLineEnd, predictor.grammar)
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
143
|
+
const allowReplacement = marks.length === 0 && offset === text.length
|
|
144
|
+
const predictions = query ? predictor.candidates(query, undefined, false, allowReplacement) : []
|
|
145
|
+
if (!allowReplacement && predictions[0]?.replace) predictions.length = 0
|
|
146
|
+
else if (!allowReplacement) predictions.splice(0, predictions.length, ...predictions.filter((prediction) => !prediction.replace))
|
|
113
147
|
const last = this.shown
|
|
114
|
-
if (query && !query.next && offset === text.length && last && last.offset === last.text.length &&
|
|
115
|
-
const typed = text.slice(last.text.length)
|
|
148
|
+
if (query && !query.next && offset === text.length && last && last.memo === this.memo && last.memo.offset === last.memo.text.length && last.memo.index === 0 && !last.memo.summoned && last.memo.revision === revision && last.memo.predictor === predictor && last.memo.marks === signature && !last.prediction.replace && text.startsWith(last.memo.text)) {
|
|
149
|
+
const typed = text.slice(last.memo.text.length)
|
|
116
150
|
if (typed && last.prediction.suffix.startsWith(typed) && typed.length < last.prediction.suffix.length) {
|
|
117
151
|
const sticky = { ...last.prediction, suffix: last.prediction.suffix.slice(typed.length) }
|
|
118
152
|
predictions.splice(0, predictions.length, sticky, ...predictions.filter((prediction) => prediction.word !== sticky.word))
|
|
119
153
|
}
|
|
120
154
|
}
|
|
121
|
-
this.memo = { text, offset, marks: signature, revision, predictor, predictions, index: 0, summoned: false }
|
|
155
|
+
this.memo = { text, offset, marks: signature, revision, predictor, predictions, index: 0, summoned: false, prefix: query?.prefix ?? "", picker: false }
|
|
122
156
|
return predictions[0]
|
|
123
157
|
}
|
|
124
158
|
|
|
159
|
+
private pickerGeometry(): string {
|
|
160
|
+
const { visualCol, visualRow } = this.editor.visualCursor
|
|
161
|
+
return [this.renderer.width, this.renderer.height, this.editor.screenX, this.editor.screenY,
|
|
162
|
+
this.editor.width, visualCol, visualRow].join(":")
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private paintPicker(buffer: OptimizedBuffer, x: number, y: number, fitting: Prediction[], prediction: Prediction, options: Alternatives): boolean {
|
|
166
|
+
const { prefix } = this.memo!
|
|
167
|
+
const prefixWidth = this.editor.editBuffer.measureText(prefix)
|
|
168
|
+
const cursor = this.editor.visualCursor
|
|
169
|
+
if (cursor.visualRow !== 0 || cursor.visualCol < prefixWidth || y < fitting.length) return false
|
|
170
|
+
const terms = fitting.map((candidate) => candidate.replace ? candidate.suffix : prefix + candidate.suffix)
|
|
171
|
+
const measure = (text: string) => this.editor.editBuffer.measureText(text)
|
|
172
|
+
const termWidth = Math.max(...terms.map(measure)) + 3
|
|
173
|
+
const left = Math.max(0, this.editor.screenX)
|
|
174
|
+
const right = Math.min(buffer.width, this.editor.screenX + this.editor.width)
|
|
175
|
+
if (termWidth > Math.min(48, right - left)) return false
|
|
176
|
+
const start = Math.max(left, Math.min(x - prefixWidth - 2, right - termWidth))
|
|
177
|
+
const fullHelp = ["↑/↓ move", options.accept && `${options.accept} accept`, options.dismiss && `${options.dismiss} close`].filter(Boolean).join(" · ")
|
|
178
|
+
const help = y > fitting.length
|
|
179
|
+
? [fullHelp, "↑/↓ move"].find((label) => measure(label) + 3 <= Math.min(48, right - start))
|
|
180
|
+
: undefined
|
|
181
|
+
const width = Math.max(termWidth, help ? measure(help) + 3 : 0)
|
|
182
|
+
const height = fitting.length + Number(!!help)
|
|
183
|
+
const top = y - height
|
|
184
|
+
const { colors } = options
|
|
185
|
+
buffer.pushScissorRect(start, top, width, height)
|
|
186
|
+
try {
|
|
187
|
+
buffer.fillRect(start, top, width, height, colors.background)
|
|
188
|
+
terms.forEach((term, index) => {
|
|
189
|
+
const selected = fitting[index] === prediction
|
|
190
|
+
if (selected) buffer.fillRect(start, top + index, width, 1, colors.selectedBackground)
|
|
191
|
+
buffer.drawText(`${selected ? "› " : " "}${term}`, start, top + index,
|
|
192
|
+
selected ? colors.selectedText : colors.text, selected ? colors.selectedBackground : colors.background)
|
|
193
|
+
})
|
|
194
|
+
if (help) buffer.drawText(help, start + 2, y - 1, colors.muted, colors.background)
|
|
195
|
+
} finally {
|
|
196
|
+
buffer.popScissorRect()
|
|
197
|
+
}
|
|
198
|
+
return true
|
|
199
|
+
}
|
|
200
|
+
|
|
125
201
|
private paint(buffer: OptimizedBuffer): void {
|
|
126
202
|
if (this.editor.isDestroyed) {
|
|
127
203
|
this.shown = undefined
|
|
@@ -131,6 +207,7 @@ export class ComposerGhost {
|
|
|
131
207
|
const offset = this.offset()
|
|
132
208
|
const prediction = this.prediction(text, offset)
|
|
133
209
|
if (!prediction) {
|
|
210
|
+
if (this.memo) this.memo.picker = false
|
|
134
211
|
this.shown = undefined
|
|
135
212
|
return
|
|
136
213
|
}
|
|
@@ -143,39 +220,49 @@ export class ComposerGhost {
|
|
|
143
220
|
}
|
|
144
221
|
const x = this.editor.screenX + cursor.visualCol
|
|
145
222
|
const y = this.editor.screenY + cursor.visualRow
|
|
223
|
+
const memo = this.memo!
|
|
224
|
+
const fitting = memo.predictions.length > 1 ? memo.predictions.filter((candidate) => this.fits(candidate)) : []
|
|
225
|
+
const options = fitting.length > 1 ? this.alternatives?.() : undefined
|
|
226
|
+
const attempted = memo.picker && fitting.length > 1
|
|
227
|
+
const picker = !!options && attempted && this.paintPicker(buffer, x, y, fitting, prediction, options)
|
|
146
228
|
buffer.pushScissorRect(x, y, room, 1)
|
|
147
229
|
try {
|
|
148
230
|
const color = this.color()
|
|
149
231
|
buffer.drawText(ghost, x, y, color, this.editor.backgroundColor)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
232
|
+
if (options && !picker && (options.summon || options.cycle || memo.picker)) {
|
|
233
|
+
const counter = ` ${fitting.indexOf(prediction) + 1}/${fitting.length}`
|
|
234
|
+
const hint = options.summon && (!attempted || !options.cycle)
|
|
235
|
+
? ` ${options.summon} ${attempted ? "cycles" : "for"} ${fitting.length} choices`
|
|
236
|
+
: counter
|
|
237
|
+
const width = this.editor.editBuffer.measureText(ghost)
|
|
238
|
+
for (const label of hint === counter ? [counter] : [hint, counter]) {
|
|
239
|
+
if (width + this.editor.editBuffer.measureText(label) > room) continue
|
|
240
|
+
buffer.drawText(label, x + width, y, dimGhostColor(color), this.editor.backgroundColor)
|
|
241
|
+
break
|
|
159
242
|
}
|
|
160
243
|
}
|
|
161
244
|
} finally {
|
|
162
245
|
buffer.popScissorRect()
|
|
163
246
|
}
|
|
164
|
-
this.shown = {
|
|
247
|
+
this.shown = { memo, prediction, picker: attempted ? { geometry: this.pickerGeometry(), drawn: picker } : undefined }
|
|
165
248
|
}
|
|
166
249
|
|
|
167
250
|
accept(): boolean {
|
|
168
251
|
const shown = this.shown
|
|
169
252
|
if (!shown || !this.visible()) return false
|
|
253
|
+
const { memo } = shown
|
|
254
|
+
const prediction = memo.predictions[memo.index]
|
|
255
|
+
if (prediction !== shown.prediction && (!this.pickerVisible() || !this.fits(prediction))) return false
|
|
170
256
|
const marks = this.editor.extmarks.getAll()
|
|
171
|
-
if (!completionQuery(
|
|
172
|
-
if ((marks.length ||
|
|
257
|
+
if (!completionQuery(memo.text, memo.offset, this.protectedRanges(marks), this.completeAtLineEnd, memo.predictor.grammar)) return false
|
|
258
|
+
if ((marks.length || memo.offset !== memo.text.length) && prediction.replace) return false
|
|
259
|
+
memo.picker = false
|
|
173
260
|
this.shown = undefined
|
|
174
|
-
if (
|
|
175
|
-
this.editor.replaceText(
|
|
261
|
+
if (prediction.replace) {
|
|
262
|
+
this.editor.replaceText(memo.text.slice(0, memo.text.length - prediction.replace) + prediction.suffix)
|
|
176
263
|
this.editor.gotoBufferEnd()
|
|
177
264
|
} else {
|
|
178
|
-
this.editor.insertText(
|
|
265
|
+
this.editor.insertText(prediction.suffix)
|
|
179
266
|
}
|
|
180
267
|
this.editor.requestRender()
|
|
181
268
|
return true
|
|
@@ -183,24 +270,41 @@ export class ComposerGhost {
|
|
|
183
270
|
|
|
184
271
|
dismiss(): boolean {
|
|
185
272
|
if (!this.visible()) return false
|
|
186
|
-
|
|
273
|
+
const { memo } = this.shown!
|
|
274
|
+
if (!this.pickerVisible()) this.dismissed = { text: memo.text, offset: memo.offset }
|
|
275
|
+
memo.picker = false
|
|
187
276
|
this.shown = undefined
|
|
188
277
|
this.editor.requestRender()
|
|
189
278
|
return true
|
|
190
279
|
}
|
|
191
280
|
|
|
192
281
|
visible(): boolean {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
282
|
+
const shown = this.shown
|
|
283
|
+
if (this.disposed || !shown || shown.memo !== this.memo || !eligibleComposer(this.view())) return false
|
|
284
|
+
const { memo, prediction } = shown
|
|
285
|
+
return this.editor.plainText === memo.text && this.offset() === memo.offset &&
|
|
286
|
+
this.marksKey() === memo.marks && this.active() === memo.predictor && memo.predictor.modelRevision === memo.revision && this.fits(prediction)
|
|
196
287
|
}
|
|
197
288
|
|
|
198
289
|
canCycle(): boolean {
|
|
199
290
|
return this.visible() && this.memo!.predictions.some((prediction, index) => index !== this.memo!.index && this.fits(prediction))
|
|
200
291
|
}
|
|
201
292
|
|
|
293
|
+
pickerVisible(): boolean {
|
|
294
|
+
const picker = this.shown?.picker
|
|
295
|
+
return picker?.drawn === true && this.visible() && picker.geometry === this.pickerGeometry()
|
|
296
|
+
}
|
|
297
|
+
|
|
202
298
|
summon(): boolean {
|
|
203
|
-
if (this.
|
|
299
|
+
if (this.visible()) {
|
|
300
|
+
if (!this.canCycle()) return false
|
|
301
|
+
const picker = this.shown!.picker
|
|
302
|
+
if (picker?.drawn === false && picker.geometry === this.pickerGeometry()) return this.cycle(1)
|
|
303
|
+
this.memo!.picker = true
|
|
304
|
+
this.editor.requestRender()
|
|
305
|
+
return true
|
|
306
|
+
}
|
|
307
|
+
if (this.disposed || !eligibleComposer(this.view())) return false
|
|
204
308
|
const text = this.editor.plainText
|
|
205
309
|
const offset = this.offset()
|
|
206
310
|
const automatic = this.prediction(text, offset)
|
|
@@ -209,11 +313,12 @@ export class ComposerGhost {
|
|
|
209
313
|
const marks = this.editor.extmarks.getAll()
|
|
210
314
|
const query = completionQuery(text, offset, this.protectedRanges(marks), this.completeAtLineEnd, predictor.grammar)
|
|
211
315
|
if (!query) return false
|
|
212
|
-
const
|
|
213
|
-
|
|
316
|
+
const allowReplacement = marks.length === 0 && offset === text.length
|
|
317
|
+
const predictions = predictor.candidates(query, 5, true, allowReplacement).filter((prediction) =>
|
|
318
|
+
(allowReplacement || !prediction.replace) && this.fits(prediction))
|
|
214
319
|
if (!predictions.length) return false
|
|
215
320
|
this.dismissed = undefined
|
|
216
|
-
this.memo = { text, offset, marks: this.marksKey(), revision: predictor.modelRevision, predictor, predictions, index: 0, summoned: true }
|
|
321
|
+
this.memo = { text, offset, marks: this.marksKey(), revision: predictor.modelRevision, predictor, predictions, index: 0, summoned: true, prefix: query.prefix, picker: predictions.length > 1 }
|
|
217
322
|
this.editor.requestRender()
|
|
218
323
|
return true
|
|
219
324
|
}
|
|
@@ -224,7 +329,7 @@ export class ComposerGhost {
|
|
|
224
329
|
do {
|
|
225
330
|
memo.index = (memo.index + direction + memo.predictions.length) % memo.predictions.length
|
|
226
331
|
} while (!this.fits(memo.predictions[memo.index]))
|
|
227
|
-
|
|
332
|
+
memo.picker = true
|
|
228
333
|
this.editor.requestRender()
|
|
229
334
|
return true
|
|
230
335
|
}
|
package/src/keymap.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { KeymapLayer } from "@opencode/plugin/tui/context"
|
|
2
2
|
import type { Options } from "./options"
|
|
3
3
|
|
|
4
|
-
type Suggestion = { visible(): boolean; accept(): boolean; dismiss(): boolean; canCycle(): boolean; cycle(direction: 1 | -1): boolean; summon(): boolean }
|
|
4
|
+
type Suggestion = { visible(): boolean; accept(): boolean; dismiss(): boolean; canCycle(): boolean; cycle(direction: 1 | -1): boolean; summon(): boolean; pickerVisible(): boolean }
|
|
5
5
|
|
|
6
6
|
export function completionLayer(options: Options, suggestion: () => Suggestion | undefined): KeymapLayer {
|
|
7
7
|
return {
|
|
@@ -25,16 +25,24 @@ export function completionLayer(options: Options, suggestion: () => Suggestion |
|
|
|
25
25
|
...([["next", 1, options.cycleNextKeys], ["previous", -1, options.cyclePreviousKeys]] as const).map(([name, direction, keys]) => ({
|
|
26
26
|
id: `quill.${name}`,
|
|
27
27
|
title: `${name === "next" ? "Next" : "Previous"} word suggestion`,
|
|
28
|
-
bind: keys.
|
|
28
|
+
bind: keys.join(",") || undefined,
|
|
29
29
|
enabled: () => suggestion()?.canCycle() === true,
|
|
30
30
|
run: () => suggestion()?.cycle(direction) ? undefined : false,
|
|
31
31
|
})),
|
|
32
32
|
{
|
|
33
33
|
id: "quill.summon",
|
|
34
34
|
title: "Summon word suggestions",
|
|
35
|
-
bind: options.summonKeys.
|
|
35
|
+
bind: options.summonKeys.join(",") || undefined,
|
|
36
36
|
run: () => suggestion()?.summon() ? undefined : false,
|
|
37
37
|
},
|
|
38
|
+
...([["down", 1], ["up", -1]] as const).map(([bind, direction]) => ({
|
|
39
|
+
bind,
|
|
40
|
+
enabled: () => suggestion()?.pickerVisible() === true,
|
|
41
|
+
run: () => {
|
|
42
|
+
const current = suggestion()
|
|
43
|
+
return current?.pickerVisible() && current.cycle(direction) ? undefined : false
|
|
44
|
+
},
|
|
45
|
+
})),
|
|
38
46
|
],
|
|
39
47
|
}
|
|
40
48
|
}
|
package/src/predictor.ts
CHANGED
|
@@ -168,7 +168,7 @@ function editKind(source: string, target: string, targetLength = target.length):
|
|
|
168
168
|
return doubled ? "delete" : undefined
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
function typoWeight(prefix: string, word: string, wholeWord = false): number {
|
|
171
|
+
function typoWeight(prefix: string, word: string, wholeWord = false, protectEnding = false): number {
|
|
172
172
|
const prefixLength = prefix.length
|
|
173
173
|
const wordLength = word.length
|
|
174
174
|
if (prefixLength < 3) return 0
|
|
@@ -184,7 +184,7 @@ function typoWeight(prefix: string, word: string, wholeWord = false): number {
|
|
|
184
184
|
if (prefixLength < 5 || wordLength <= prefixLength) return 0
|
|
185
185
|
const partial = editKind(prefix, word, prefixLength)
|
|
186
186
|
if (partial === "transpose") return 0.06
|
|
187
|
-
if (partial === "substitute") return 0.02
|
|
187
|
+
if (partial === "substitute" && !(protectEnding && word.startsWith(prefix.slice(0, -1)))) return 0.02
|
|
188
188
|
if (wordLength > prefixLength + 1 && editKind(prefix, word, prefixLength + 1) === "insert") return 0.03
|
|
189
189
|
if (editKind(prefix, word, prefixLength - 1) === "delete") return 0.02
|
|
190
190
|
return 0
|
|
@@ -333,7 +333,7 @@ export class WordPredictor {
|
|
|
333
333
|
return resolved
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
candidates(query: CompletionQuery, limit = 5, summoned = false): Prediction[] {
|
|
336
|
+
candidates(query: CompletionQuery, limit = 5, summoned = false, allowContractionReplacement = true): Prediction[] {
|
|
337
337
|
const maximum = Number.isFinite(limit) ? Math.max(0, Math.min(5, Math.floor(limit))) : 5
|
|
338
338
|
if (!maximum) return []
|
|
339
339
|
const prefix = this.grammar.normalize(query.prefix)
|
|
@@ -341,12 +341,26 @@ export class WordPredictor {
|
|
|
341
341
|
const words = query.words ?? (this.grammar.prose ? proseWords(query.before) : [])
|
|
342
342
|
const local = new Map<string, number>()
|
|
343
343
|
for (const word of words) increment(local, word.text)
|
|
344
|
-
const
|
|
344
|
+
const rawContext = leftContext(query.before, words)
|
|
345
|
+
const context = this.resolveContext(rawContext, local)
|
|
345
346
|
const previous = context.at(-1)
|
|
346
347
|
const pair = context.length === 2 ? context.join("\0") : undefined
|
|
347
348
|
const evidence = this.bigramTotals.get(previous ?? "")?.total ?? 0
|
|
348
349
|
if (query.next && evidence < 2) return []
|
|
349
350
|
if (!query.next && prefixLength < 2 && evidence < 2) return []
|
|
351
|
+
const typedPrevious = rawContext.at(-1)
|
|
352
|
+
if (allowContractionReplacement && this.grammar.prose && !query.next && prefixLength >= 3 && typedPrevious && /^[a-z]+$/.test(prefix)) {
|
|
353
|
+
const ending = /n(t)$|(d|ll|re|ve)$/.exec(prefix)
|
|
354
|
+
if (ending && prefixLength + 1 >= this.minSuggestedWordLength) {
|
|
355
|
+
const apostrophe = prefix.length - (ending[1] ?? ending[2]).length
|
|
356
|
+
const word = `${prefix.slice(0, apostrophe)}'${prefix.slice(apostrophe)}`
|
|
357
|
+
const count = this.personal.bigrams.get(`${typedPrevious}\0${word}`) ?? 0
|
|
358
|
+
const total = this.bigramTotals.get(typedPrevious)?.total ?? 0
|
|
359
|
+
if (count >= 2 && count > total / 2) {
|
|
360
|
+
return [{ word, suffix: applyCase(query.prefix, this.forms.get(word) ?? word), confidence: count / total, replace: query.prefix.length }]
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
350
364
|
const slash = prefix.includes("/")
|
|
351
365
|
const followed = (word: string) => (previous ? this.personal.bigrams.get(`${previous}\0${word}`) ?? 0 : 0) >= 2 ||
|
|
352
366
|
(pair ? this.personal.trigrams.get(`${pair}\0${word}`) ?? 0 : 0) >= 2
|
|
@@ -363,8 +377,9 @@ export class WordPredictor {
|
|
|
363
377
|
}
|
|
364
378
|
}
|
|
365
379
|
for (const word of local.keys()) if (!word.includes("/") && word.startsWith(prefix) && (query.next || !slash) && eligible(word)) candidates.set(word, 1)
|
|
366
|
-
const suggest = (): Prediction[] => {
|
|
380
|
+
const suggest = (typos = false): Prediction[] => {
|
|
367
381
|
const ranked: { word: string; score: number; weight: number }[] = []
|
|
382
|
+
const retained = typos ? Math.max(2, maximum) : maximum
|
|
368
383
|
let sum = 0
|
|
369
384
|
for (const [word, weight] of candidates) {
|
|
370
385
|
const base = this.score(word, context, weight < 1) + (query.next ? 0 : 0.003 * Math.min(local.get(word) ?? 0, 3))
|
|
@@ -373,8 +388,10 @@ export class WordPredictor {
|
|
|
373
388
|
if (this.minSuggestedWordLength && word !== prefix && [...word].length < this.minSuggestedWordLength) continue
|
|
374
389
|
ranked.push({ word, score, weight })
|
|
375
390
|
ranked.sort((a, b) => b.score - a.score)
|
|
376
|
-
if (ranked.length >
|
|
391
|
+
if (ranked.length > retained + (this.grammar.prose && candidates.has(prefix) && !query.next ? 1 : 0)) ranked.pop()
|
|
377
392
|
}
|
|
393
|
+
const [best, runnerUp] = ranked
|
|
394
|
+
if (typos && !summoned && best && runnerUp && best.weight < 1 && best.score === runnerUp.score) return []
|
|
378
395
|
const predictions: Prediction[] = []
|
|
379
396
|
const exact = query.next ? 0 : ranked.find(({ word }) => word === prefix)?.score ?? 0
|
|
380
397
|
const short = prefixLength < 2
|
|
@@ -410,16 +427,17 @@ export class WordPredictor {
|
|
|
410
427
|
}
|
|
411
428
|
const completion = suggest()
|
|
412
429
|
if (completion.length || query.next || prefixLength < 3 || slash || prefix.endsWith("'") || candidates.has(prefix) || !this.grammar.prose) return completion
|
|
430
|
+
const protectEnding = this.known.has(prefix.slice(0, -1))
|
|
413
431
|
for (const word of this.nearbyWords(prefix)) {
|
|
414
432
|
if (candidates.has(word)) continue
|
|
415
|
-
const weight = typoWeight(prefix, word)
|
|
433
|
+
const weight = typoWeight(prefix, word, false, protectEnding)
|
|
416
434
|
if (weight > 0) candidates.set(word, weight)
|
|
417
435
|
}
|
|
418
436
|
for (const word of local.keys()) {
|
|
419
437
|
if (candidates.has(word) || word.includes("/")) continue
|
|
420
|
-
const weight = typoWeight(prefix, word)
|
|
438
|
+
const weight = typoWeight(prefix, word, false, protectEnding)
|
|
421
439
|
if (weight > 0) candidates.set(word, weight)
|
|
422
440
|
}
|
|
423
|
-
return suggest()
|
|
441
|
+
return suggest(true)
|
|
424
442
|
}
|
|
425
443
|
}
|
package/src/tui.tsx
CHANGED
|
@@ -71,8 +71,23 @@ export default Plugin.define({
|
|
|
71
71
|
selected: context.renderer.hasSelection,
|
|
72
72
|
enabled: !disposed && settings.enabled && (!shell || shellEnabled()) && currentEditor() === editor,
|
|
73
73
|
}
|
|
74
|
-
}, () => dimGhostColor(context.theme.text.muted), context.renderer, options.completeAtLineEnd, shellPredictor,
|
|
75
|
-
|
|
74
|
+
}, () => dimGhostColor(context.theme.text.muted), context.renderer, options.completeAtLineEnd, shellPredictor, () => {
|
|
75
|
+
const shortcut = (id: string) => context.keymap.shortcuts(id).map((key) => key.trim()).find((key) => key && !/[\u0000-\u001f\u007f-\u009f]/u.test(key))
|
|
76
|
+
const { text, background } = context.theme
|
|
77
|
+
return {
|
|
78
|
+
summon: shortcut("quill.summon"),
|
|
79
|
+
cycle: !!(shortcut("quill.next") || shortcut("quill.previous")),
|
|
80
|
+
accept: shortcut("quill.accept"),
|
|
81
|
+
dismiss: shortcut("quill.dismiss"),
|
|
82
|
+
colors: {
|
|
83
|
+
text: text.base,
|
|
84
|
+
muted: text.muted,
|
|
85
|
+
background: background.raised.base,
|
|
86
|
+
selectedText: text.selection,
|
|
87
|
+
selectedBackground: background.selection,
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
})
|
|
76
91
|
}
|
|
77
92
|
|
|
78
93
|
const sessionInfo = (sessionID: string) =>
|