From 1ba18afb075b81c6b89642b70e00bd8c29642991 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 16 Jan 2020 17:18:17 +0100 Subject: [PATCH] move API proposal to stable API, #10266 --- src/vs/vscode.d.ts | 12 +++++++----- src/vs/vscode.proposed.d.ts | 19 ------------------- .../api/common/extHostLanguageFeatures.ts | 6 ++---- .../api/common/extHostTypeConverters.ts | 10 ++++++++-- src/vs/workbench/api/common/extHostTypes.ts | 3 +-- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index cf02afe365e..a2b3112bc80 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -3413,15 +3413,17 @@ declare module 'vscode' { insertText?: string | SnippetString; /** - * A range of text that should be replaced by this completion item. + * A range or a insert and replace range selecting the text that should be replaced by this completion item. * - * Defaults to a range from the start of the [current word](#TextDocument.getWordRangeAtPosition) to the - * current position. + * When omitted, the range of the [current word](#TextDocument.getWordRangeAtPosition) is used as replace-range + * and as insert-range the start of the [current word](#TextDocument.getWordRangeAtPosition) to the + * current position is used. * - * *Note:* The range must be a [single line](#Range.isSingleLine) and it must + * *Note 1:* A range must be a [single line](#Range.isSingleLine) and it must * [contain](#Range.contains) the position at which completion has been [requested](#CompletionItemProvider.provideCompletionItems). + * *Note 2:* A insert range must be a prefix of a replace range, that means it must be contained and starting at the same position. */ - range?: Range; + range?: Range | { inserting: Range; replacing: Range; }; /** * An optional set of characters that when pressed while this completion is active will accept it first and diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index c6103fbe208..0de7f957f3f 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1285,25 +1285,6 @@ declare module 'vscode' { //#endregion - //#region insert/replace completions: https://github.com/microsoft/vscode/issues/10266 - - export interface CompletionItem { - - /** - * A range or a insert and replace range selecting the text that should be replaced by this completion item. - * - * When omitted, the range of the [current word](#TextDocument.getWordRangeAtPosition) is used as replace-range - * and as insert-range the start of the [current word](#TextDocument.getWordRangeAtPosition) to the - * current position is used. - * - * *Note 1:* A range must be a [single line](#Range.isSingleLine) and it must - * [contain](#Range.contains) the position at which completion has been [requested](#CompletionItemProvider.provideCompletionItems). - * *Note 2:* A insert range must be a prefix of a replace range, that means it must be contained and starting at the same position. - */ - range2?: Range | { inserting: Range; replacing: Range; }; - } - - //#endregion //#region allow QuickPicks to skip sorting: https://github.com/microsoft/vscode/issues/73904 diff --git a/src/vs/workbench/api/common/extHostLanguageFeatures.ts b/src/vs/workbench/api/common/extHostLanguageFeatures.ts index 20cc1a12f77..f3cb6fade93 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatures.ts @@ -918,8 +918,6 @@ class SuggestAdapter { range = item.textEdit.range; } else if (item.range) { range = item.range; - } else if (item.range2) { - range = item.range2; } if (range) { @@ -955,12 +953,12 @@ class SuggestAdapter { } private static _mustNotChangeHash(item: vscode.CompletionItem) { - const res = JSON.stringify([item.label, item.sortText, item.filterText, item.insertText, item.range, item.range2]); + const res = JSON.stringify([item.label, item.sortText, item.filterText, item.insertText, item.range]); return res; } private static _mustNotChangeDiff(hash: string, item: vscode.CompletionItem): string | void { - const thisArr = [item.label, item.sortText, item.filterText, item.insertText, item.range, item.range2]; + const thisArr = [item.label, item.sortText, item.filterText, item.insertText, item.range]; const thisHash = JSON.stringify(thisArr); if (hash === thisHash) { return; diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 093a3219eb5..6875799dc69 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -842,8 +842,14 @@ export namespace CompletionItem { result.filterText = suggestion.filterText; result.preselect = suggestion.preselect; result.commitCharacters = suggestion.commitCharacters; - result.range = editorRange.Range.isIRange(suggestion.range) ? Range.to(suggestion.range) : undefined; - result.range2 = editorRange.Range.isIRange(suggestion.range) ? undefined : { inserting: Range.to(suggestion.range.insert), replacing: Range.to(suggestion.range.replace) }; + + // range + if (editorRange.Range.isIRange(suggestion.range)) { + result.range = Range.to(suggestion.range); + } else if (typeof suggestion.range === 'object') { + result.range = { inserting: Range.to(suggestion.range.insert), replacing: Range.to(suggestion.range.replace) }; + } + result.keepWhitespace = typeof suggestion.insertTextRules === 'undefined' ? false : Boolean(suggestion.insertTextRules & modes.CompletionItemInsertTextRule.KeepWhitespace); // 'insertText'-logic if (typeof suggestion.insertTextRules !== 'undefined' && suggestion.insertTextRules & modes.CompletionItemInsertTextRule.InsertAsSnippet) { diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index eeb89627d62..037eb2b99a4 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -1364,8 +1364,7 @@ export class CompletionItem implements vscode.CompletionItem { preselect?: boolean; insertText?: string | SnippetString; keepWhitespace?: boolean; - range?: Range; - range2?: Range | { inserting: Range; replacing: Range; }; + range?: Range | { inserting: Range; replacing: Range; }; commitCharacters?: string[]; textEdit?: TextEdit; additionalTextEdits?: TextEdit[]; -- GitLab