Skip to content

Commit

Permalink
fix the inlineCompletion example
Browse files Browse the repository at this point in the history
Now that the extension is GA, the code sample does not need the proposed API
the API has been simplified a bit since the proposal, so the code has been simplified as well
  • Loading branch information
tardyp committed Jun 22, 2023
1 parent 6686321 commit 743d9e5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 89 deletions.
12 changes: 1 addition & 11 deletions inline-completions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"enabledApiProposals": [
"inlineCompletionsAdditions"
],
"name": "inline-completion-sample",
"displayName": "Inline Completion Sample",
"description": "Sample showing how to implement an inline completion provider",
Expand All @@ -24,14 +21,7 @@
"command": "extension.inline-completion-settings",
"title": "My Inline Completion Demo Settings"
}
],
"menus": {
"editor/inlineCompletions/actions": [
{
"command": "extension.inline-completion-settings"
}
]
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
Expand Down
31 changes: 5 additions & 26 deletions inline-completions/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export function activate(context: vscode.ExtensionContext) {

const result: vscode.InlineCompletionList = {
items: [],
commands: [],
};

let offset = 1;
Expand All @@ -41,41 +40,21 @@ export function activate(context: vscode.ExtensionContext) {
? document.lineAt(position.line).text.length
: parseInt(end, 10);
const flags = matches[3];
const completeBracketPairs = flags.includes('b');
const isSnippet = flags.includes('s');
const text = matches[4].replace(/\\n/g, '\n');

result.items.push({
insertText: isSnippet ? new vscode.SnippetString(text) : text,
range: new Range(position.line, startInt, position.line, endInt),
completeBracketPairs,
});
}

if (result.items.length > 0) {
result.commands!.push({
command: 'demo-ext.command1',
title: 'My Inline Completion Demo Command',
arguments: [1, 2],
command:{
command: 'demo-ext.command1',
title: 'My Inline Completion Demo Command',
arguments: [1, 2],
}
});
}
return result;
},

handleDidShowCompletionItem(completionItem: vscode.InlineCompletionItem): void {
console.log('handleDidShowCompletionItem');
},

/**
* Is called when an inline completion item was accepted partially.
* @param acceptedLength The length of the substring of the inline completion that was accepted already.
*/
handleDidPartiallyAcceptCompletionItem(
completionItem: vscode.InlineCompletionItem,
acceptedLength: number
): void {
console.log('handleDidPartiallyAcceptCompletionItem');
},
};
vscode.languages.registerInlineCompletionItemProvider({ pattern: '**' }, provider);
}
52 changes: 0 additions & 52 deletions inline-completions/vscode.proposed.inlineCompletionsAdditions.d.ts

This file was deleted.

0 comments on commit 743d9e5

Please sign in to comment.