diff --git a/extensions/css-language-features/client/src/cssClient.ts b/extensions/css-language-features/client/src/cssClient.ts index de53a8821f3..ca97338f35f 100644 --- a/extensions/css-language-features/client/src/cssClient.ts +++ b/extensions/css-language-features/client/src/cssClient.ts @@ -49,9 +49,9 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua } function updateLabel(item: CompletionItem) { if (item.kind === CompletionItemKind.Color) { - item.label2 = { - name: item.label, - type: (item.documentation as string) + item.label = { + label: item.label as string, + description: (item.documentation as string) }; } } diff --git a/extensions/npm/src/features/bowerJSONContribution.ts b/extensions/npm/src/features/bowerJSONContribution.ts index 4fb0f0633b4..e02fd11ac8c 100644 --- a/extensions/npm/src/features/bowerJSONContribution.ts +++ b/extensions/npm/src/features/bowerJSONContribution.ts @@ -143,7 +143,13 @@ export class BowerJSONContribution implements IJSONContribution { public resolveSuggestion(_resource: Uri | undefined, item: CompletionItem): Thenable | null { if (item.kind === CompletionItemKind.Property && item.documentation === '') { - return this.getInfo(item.label).then(documentation => { + + let label = item.label; + if (typeof label !== 'string') { + label = label.label; + } + + return this.getInfo(label).then(documentation => { if (documentation) { item.documentation = documentation; return item; diff --git a/extensions/npm/src/features/jsonContributions.ts b/extensions/npm/src/features/jsonContributions.ts index dcd5411e445..cf65a5b0851 100644 --- a/extensions/npm/src/features/jsonContributions.ts +++ b/extensions/npm/src/features/jsonContributions.ts @@ -109,8 +109,11 @@ export class JSONCompletionItemProvider implements CompletionItemProvider { const proposed: { [key: string]: boolean } = {}; const collector: ISuggestionsCollector = { add: (suggestion: CompletionItem) => { - if (!proposed[suggestion.label]) { - proposed[suggestion.label] = true; + const key = typeof suggestion.label === 'string' + ? suggestion.label + : suggestion.label.label; + if (!proposed[key]) { + proposed[key] = true; suggestion.range = { replacing: overwriteRange, inserting: new Range(overwriteRange.start, overwriteRange.start) }; items.push(suggestion); } diff --git a/extensions/npm/src/features/packageJSONContribution.ts b/extensions/npm/src/features/packageJSONContribution.ts index c1bd6fd4c93..378f51b0b7d 100644 --- a/extensions/npm/src/features/packageJSONContribution.ts +++ b/extensions/npm/src/features/packageJSONContribution.ts @@ -235,7 +235,13 @@ export class PackageJSONContribution implements IJSONContribution { public resolveSuggestion(resource: Uri | undefined, item: CompletionItem): Thenable | null { if (item.kind === CompletionItemKind.Property && !item.documentation) { - return this.fetchPackageInfo(item.label, resource).then(info => { + + let name = item.label; + if (typeof name !== 'string') { + name = name.label; + } + + return this.fetchPackageInfo(name, resource).then(info => { if (info) { item.documentation = this.getDocumentation(info.description, info.version, info.homepage); return item; diff --git a/extensions/typescript-language-features/src/languageFeatures/completions.ts b/extensions/typescript-language-features/src/languageFeatures/completions.ts index 844d3455e14..f7452c95bff 100644 --- a/extensions/typescript-language-features/src/languageFeatures/completions.ts +++ b/extensions/typescript-language-features/src/languageFeatures/completions.ts @@ -72,7 +72,7 @@ class MyCompletionItem extends vscode.CompletionItem { // Render "fancy" when source is a workspace path const qualifierCandidate = vscode.workspace.asRelativePath(tsEntry.source); if (qualifierCandidate !== tsEntry.source) { - this.label2 = { name: tsEntry.name, qualifier: qualifierCandidate }; + this.label = { label: tsEntry.name, description: qualifierCandidate }; } } else { @@ -81,7 +81,7 @@ class MyCompletionItem extends vscode.CompletionItem { const { sourceDisplay, isSnippet } = tsEntry; if (sourceDisplay) { - this.label2 = { name: tsEntry.name, qualifier: Previewer.plainWithLinks(sourceDisplay, client) }; + this.label = { label: tsEntry.name, description: Previewer.plainWithLinks(sourceDisplay, client) }; } this.preselect = tsEntry.isRecommended; @@ -113,11 +113,11 @@ class MyCompletionItem extends vscode.CompletionItem { const kindModifiers = parseKindModifier(tsEntry.kindModifiers); if (kindModifiers.has(PConst.KindModifiers.optional)) { if (!this.insertText) { - this.insertText = this.label; + this.insertText = this.textLabel; } if (!this.filterText) { - this.filterText = this.label; + this.filterText = this.textLabel; } this.label += '?'; } @@ -146,6 +146,10 @@ class MyCompletionItem extends vscode.CompletionItem { this.resolveRange(); } + private get textLabel() { + return typeof this.label === 'string' ? this.label : this.label.label; + } + private _resolvedPromise?: { readonly requestToken: vscode.CancellationTokenSource; readonly promise: Promise; @@ -216,7 +220,7 @@ class MyCompletionItem extends vscode.CompletionItem { if (this.useCodeSnippet) { const shouldCompleteFunction = await this.isValidFunctionCompletionContext(client, filepath, this.position, this.document, token); if (shouldCompleteFunction) { - const { snippet, parameterCount } = snippetForFunctionCall(this, detail.displayParts); + const { snippet, parameterCount } = snippetForFunctionCall({ ...this, label: this.textLabel }, detail.displayParts); this.insertText = snippet; if (parameterCount > 0) { //Fix for https://github.com/microsoft/vscode/issues/104059 @@ -408,8 +412,8 @@ class MyCompletionItem extends vscode.CompletionItem { private getFuzzyWordRange() { if (this.completionContext.useFuzzyWordRangeLogic) { // Try getting longer, prefix based range for completions that span words - const text = this.completionContext.line.slice(Math.max(0, this.position.character - this.label.length), this.position.character).toLowerCase(); - const entryName = this.label.toLowerCase(); + const text = this.completionContext.line.slice(Math.max(0, this.position.character - this.textLabel.length), this.position.character).toLowerCase(); + const entryName = this.textLabel.toLowerCase(); for (let i = entryName.length; i >= 0; --i) { if (text.endsWith(entryName.substr(0, i)) && (!this.completionContext.wordRange || this.completionContext.wordRange.start.character > this.position.character - i)) { return new vscode.Range( diff --git a/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts b/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts index a18faaea0ea..f3ba9f7cc5e 100644 --- a/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts +++ b/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts @@ -94,8 +94,8 @@ suite('SnippetsService', function () { assert.strictEqual(result.incomplete, undefined); assert.strictEqual(result.suggestions.length, 1); assert.deepStrictEqual(result.suggestions[0].label, { - name: 'bar', - type: 'barTest' + label: 'bar', + description: 'barTest' }); assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 1); assert.strictEqual(result.suggestions[0].insertText, 'barCodeSnippet'); @@ -129,14 +129,14 @@ suite('SnippetsService', function () { assert.strictEqual(result.incomplete, undefined); assert.strictEqual(result.suggestions.length, 2); assert.deepStrictEqual(result.suggestions[0].label, { - name: 'bar', - type: 'barTest' + label: 'bar', + description: 'barTest' }); assert.strictEqual(result.suggestions[0].insertText, 's1'); assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 1); assert.deepStrictEqual(result.suggestions[1].label, { - name: 'bar-bar', - type: 'name' + label: 'bar-bar', + description: 'name' }); assert.strictEqual(result.suggestions[1].insertText, 's2'); assert.strictEqual((result.suggestions[1].range as any).insert.startColumn, 1); @@ -146,8 +146,8 @@ suite('SnippetsService', function () { assert.strictEqual(result.incomplete, undefined); assert.strictEqual(result.suggestions.length, 1); assert.deepStrictEqual(result.suggestions[0].label, { - name: 'bar-bar', - type: 'name' + label: 'bar-bar', + description: 'name' }); assert.strictEqual(result.suggestions[0].insertText, 's2'); assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 1); @@ -157,14 +157,14 @@ suite('SnippetsService', function () { assert.strictEqual(result.incomplete, undefined); assert.strictEqual(result.suggestions.length, 2); assert.deepStrictEqual(result.suggestions[0].label, { - name: 'bar', - type: 'barTest' + label: 'bar', + description: 'barTest' }); assert.strictEqual(result.suggestions[0].insertText, 's1'); assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 5); assert.deepStrictEqual(result.suggestions[1].label, { - name: 'bar-bar', - type: 'name' + label: 'bar-bar', + description: 'name' }); assert.strictEqual(result.suggestions[1].insertText, 's2'); assert.strictEqual((result.suggestions[1].range as any).insert.startColumn, 1); @@ -254,12 +254,12 @@ suite('SnippetsService', function () { assert.strictEqual(result.suggestions.length, 2); let [first, second] = result.suggestions; assert.deepStrictEqual(first.label, { - name: 'first', - type: 'first' + label: 'first', + description: 'first' }); assert.deepStrictEqual(second.label, { - name: 'second', - type: 'second' + label: 'second', + description: 'second' }); }); }); @@ -344,8 +344,8 @@ suite('SnippetsService', function () { assert.strictEqual(result.suggestions.length, 1); assert.deepStrictEqual(result.suggestions[0].label, { - name: 'mytemplate', - type: 'mytemplate' + label: 'mytemplate', + description: 'mytemplate' }); });