Skip to content

Commit 00911c6

Browse files
Merge pull request #6028 from ShamanicArts/forceAutocomplete
feat: Add shortcut to force autocomplete (VSCode)
2 parents f1d034c + 573478a commit 00911c6

File tree

10 files changed

+67
-7
lines changed

10 files changed

+67
-7
lines changed

binary/package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/autocomplete/CompletionProvider.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export class CompletionProvider {
127127
public async provideInlineCompletionItems(
128128
input: AutocompleteInput,
129129
token: AbortSignal | undefined,
130+
force?: boolean,
130131
): Promise<AutocompleteOutcome | undefined> {
131132
try {
132133
// Create abort signal if not given
@@ -146,8 +147,12 @@ export class CompletionProvider {
146147
const options = await this._getAutocompleteOptions(llm);
147148

148149
// Debounce
149-
if (await this.debouncer.delayAndShouldDebounce(options.debounceDelay)) {
150-
return undefined;
150+
if (!force) {
151+
if (
152+
await this.debouncer.delayAndShouldDebounce(options.debounceDelay)
153+
) {
154+
return undefined;
155+
}
151156
}
152157

153158
if (llm.promptTemplates?.autocomplete) {

core/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/autocomplete/how-to-use-it.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ Reject a full suggestion with <kbd>Esc</kbd>
2323
### Partially accepting a suggestion
2424

2525
For more granular control, use <kbd>cmd/ctrl</kbd> + <kbd>→</kbd> to accept parts of the suggestion word-by-word.
26+
27+
### Forcing a suggestion (VS Code)
28+
29+
If you want to trigger a suggestion immediately without waiting, or if you've dismissed a suggestion and want a new one, you can force it by using the keyboard shortcut **<kbd>cmd/ctrl</kbd> + <kbd>alt</kbd> + <kbd>space</kbd>**.

extensions/vscode/e2e/actions/Autocomplete.actions.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from "chai";
2-
import { TextEditor } from "vscode-extension-tester";
2+
import { TextEditor, VSBrowser, Workbench } from "vscode-extension-tester";
33

44
import { DEFAULT_TIMEOUT } from "../constants";
55
import { AutocompleteSelectors } from "../selectors/Autocomplete.selectors";
@@ -29,4 +29,17 @@ export class AutocompleteActions {
2929
);
3030
expect(ghostText1).to.equal(messagePair1.llmResponse);
3131
}
32+
33+
public static async forceCompletion(editor: TextEditor): Promise<string> {
34+
await editor.setText("def main():\n ");
35+
await editor.moveCursor(2, 5);
36+
37+
await new Workbench().executeCommand("Continue: Force Autocomplete");
38+
39+
const ghostText = await TestUtils.waitForSuccess(() =>
40+
AutocompleteSelectors.getGhostTextContent(VSBrowser.instance.driver)
41+
);
42+
43+
return ghostText;
44+
}
3245
}

extensions/vscode/e2e/tests/Autocomplete.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { expect } from "chai";
12
import { EditorView, TextEditor } from "vscode-extension-tester";
23

34
import { AutocompleteActions } from "../actions/Autocomplete.actions";
@@ -23,4 +24,8 @@ describe("Autocomplete", () => {
2324
it("Should display completions", async () => {
2425
await AutocompleteActions.testCompletions(editor);
2526
}).timeout(DEFAULT_TIMEOUT.XL);
27+
it("Should force a completion using the command", async () => {
28+
const ghostText = await AutocompleteActions.forceCompletion(editor);
29+
expect(ghostText).to.not.be.empty;
30+
}).timeout(DEFAULT_TIMEOUT.XL);
2631
});

extensions/vscode/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@
225225
"title": "Toggle Autocomplete Enabled",
226226
"group": "Continue"
227227
},
228+
{
229+
"command": "continue.forceAutocomplete",
230+
"title": "Continue: Force Autocomplete",
231+
"category": "Continue"
232+
},
228233
{
229234
"command": "continue.selectFilesAsContext",
230235
"category": "Continue",
@@ -411,6 +416,12 @@
411416
"key": "ctrl+k ctrl+a",
412417
"when": "!terminalFocus"
413418
},
419+
{
420+
"command": "continue.forceAutocomplete",
421+
"key": "ctrl+alt+space",
422+
"mac": "cmd+alt+space",
423+
"when": "editorTextFocus && !editorHasSelection && !editorReadOnly && !inSnippetMode"
424+
},
414425
{
415426
"command": "continue.applyCodeFromChat",
416427
"mac": "alt+a",

extensions/vscode/src/autocomplete/completionProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ export class ContinueCompletionProvider
189189
// Handle commit message input box
190190
let manuallyPassPrefix: string | undefined = undefined;
191191

192+
// handle manual autocompletion trigger
193+
const wasManuallyTriggered =
194+
context.triggerKind === vscode.InlineCompletionTriggerKind.Invoke;
195+
192196
const input: AutocompleteInput = {
193197
pos,
194198
manuallyPassFileContents,
@@ -208,6 +212,7 @@ export class ContinueCompletionProvider
208212
await this.completionProvider.provideInlineCompletionItems(
209213
input,
210214
signal,
215+
wasManuallyTriggered,
211216
);
212217

213218
if (!outcome || !outcome.completion) {

extensions/vscode/src/commands.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,18 @@ const getCommandsMap: (
624624
}
625625
}
626626
},
627+
"continue.forceAutocomplete": async () => {
628+
captureCommandTelemetry("forceAutocomplete");
629+
630+
// 1. Explicitly hide any existing suggestion. This clears VS Code's cache for the current position.
631+
await vscode.commands.executeCommand("editor.action.inlineSuggest.hide");
632+
633+
// 2. Now trigger a new one. VS Code has no cached suggestion, so it's forced to call our provider.
634+
await vscode.commands.executeCommand(
635+
"editor.action.inlineSuggest.trigger",
636+
);
637+
},
638+
627639
"continue.openTabAutocompleteConfigMenu": async () => {
628640
captureCommandTelemetry("openTabAutocompleteConfigMenu");
629641

gui/src/pages/config/KeyboardShortcuts.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ const vscodeShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [
7575
shortcut: "cmd K cmd A",
7676
description: "Toggle Autocomplete Enabled",
7777
},
78+
{
79+
shortcut: "cmd alt space",
80+
description: "Force an Autocomplete Trigger",
81+
},
7882
{
7983
shortcut: "cmd K cmd M",
8084
description: "Toggle Full Screen",

0 commit comments

Comments
 (0)