From 743d9e54cd0667f9b6b61f736569880b62e67577 Mon Sep 17 00:00:00 2001 From: Pierre Tardy Date: Wed, 21 Jun 2023 20:40:40 +0200 Subject: [PATCH] fix the inlineCompletion example 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 --- inline-completions/package.json | 12 +---- inline-completions/src/extension.ts | 31 ++--------- ...e.proposed.inlineCompletionsAdditions.d.ts | 52 ------------------- 3 files changed, 6 insertions(+), 89 deletions(-) delete mode 100644 inline-completions/vscode.proposed.inlineCompletionsAdditions.d.ts diff --git a/inline-completions/package.json b/inline-completions/package.json index 3e5c3bd5c..412575e72 100644 --- a/inline-completions/package.json +++ b/inline-completions/package.json @@ -1,7 +1,4 @@ { - "enabledApiProposals": [ - "inlineCompletionsAdditions" - ], "name": "inline-completion-sample", "displayName": "Inline Completion Sample", "description": "Sample showing how to implement an inline completion provider", @@ -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", diff --git a/inline-completions/src/extension.ts b/inline-completions/src/extension.ts index 6f7e9b8d8..d6f30e0af 100644 --- a/inline-completions/src/extension.ts +++ b/inline-completions/src/extension.ts @@ -17,7 +17,6 @@ export function activate(context: vscode.ExtensionContext) { const result: vscode.InlineCompletionList = { items: [], - commands: [], }; let offset = 1; @@ -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); } diff --git a/inline-completions/vscode.proposed.inlineCompletionsAdditions.d.ts b/inline-completions/vscode.proposed.inlineCompletionsAdditions.d.ts deleted file mode 100644 index 8412aca06..000000000 --- a/inline-completions/vscode.proposed.inlineCompletionsAdditions.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -declare module 'vscode' { - - // https://github.com/microsoft/vscode/issues/124024 @hediet @alexdima - - export interface InlineCompletionItem { - /** - * If set to `true`, unopened closing brackets are removed and unclosed opening brackets are closed. - * Defaults to `false`. - */ - completeBracketPairs?: boolean; - } - - export interface InlineCompletionItemProvider { - /** - * @param completionItem The completion item that was shown. - * @param updatedInsertText The actual insert text (after brackets were fixed). - */ - // eslint-disable-next-line local/vscode-dts-provider-naming - handleDidShowCompletionItem?(completionItem: InlineCompletionItem, updatedInsertText: string): void; - - /** - * 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. - */ - // eslint-disable-next-line local/vscode-dts-provider-naming - handleDidPartiallyAcceptCompletionItem?(completionItem: InlineCompletionItem, acceptedLength: number): void; - } - - // When finalizing `commands`, make sure to add a corresponding constructor parameter. - export interface InlineCompletionList { - /** - * A list of commands associated with the inline completions of this list. - */ - commands?: Command[]; - - /** - * When set, overrides the user setting of `editor.inlineSuggest.suppressSuggestions`. - */ - suppressSuggestions?: boolean; - - /** - * When set and the user types a suggestion without derivating from it, the inline suggestion is not updated. - * Defaults to false (might change). - */ - enableForwardStability?: boolean; - } -}