mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
adopt API changes in tests and extensions
This commit is contained in:
parent
24f9000e97
commit
14704a7e92
|
@ -49,9 +49,9 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
|
||||||
}
|
}
|
||||||
function updateLabel(item: CompletionItem) {
|
function updateLabel(item: CompletionItem) {
|
||||||
if (item.kind === CompletionItemKind.Color) {
|
if (item.kind === CompletionItemKind.Color) {
|
||||||
item.label2 = {
|
item.label = {
|
||||||
name: item.label,
|
label: item.label as string,
|
||||||
type: (item.documentation as string)
|
description: (item.documentation as string)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,13 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||||
|
|
||||||
public resolveSuggestion(_resource: Uri | undefined, item: CompletionItem): Thenable<CompletionItem | null> | null {
|
public resolveSuggestion(_resource: Uri | undefined, item: CompletionItem): Thenable<CompletionItem | null> | null {
|
||||||
if (item.kind === CompletionItemKind.Property && item.documentation === '') {
|
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) {
|
if (documentation) {
|
||||||
item.documentation = documentation;
|
item.documentation = documentation;
|
||||||
return item;
|
return item;
|
||||||
|
|
|
@ -109,8 +109,11 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||||
const proposed: { [key: string]: boolean } = {};
|
const proposed: { [key: string]: boolean } = {};
|
||||||
const collector: ISuggestionsCollector = {
|
const collector: ISuggestionsCollector = {
|
||||||
add: (suggestion: CompletionItem) => {
|
add: (suggestion: CompletionItem) => {
|
||||||
if (!proposed[suggestion.label]) {
|
const key = typeof suggestion.label === 'string'
|
||||||
proposed[suggestion.label] = true;
|
? suggestion.label
|
||||||
|
: suggestion.label.label;
|
||||||
|
if (!proposed[key]) {
|
||||||
|
proposed[key] = true;
|
||||||
suggestion.range = { replacing: overwriteRange, inserting: new Range(overwriteRange.start, overwriteRange.start) };
|
suggestion.range = { replacing: overwriteRange, inserting: new Range(overwriteRange.start, overwriteRange.start) };
|
||||||
items.push(suggestion);
|
items.push(suggestion);
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,7 +235,13 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||||
|
|
||||||
public resolveSuggestion(resource: Uri | undefined, item: CompletionItem): Thenable<CompletionItem | null> | null {
|
public resolveSuggestion(resource: Uri | undefined, item: CompletionItem): Thenable<CompletionItem | null> | null {
|
||||||
if (item.kind === CompletionItemKind.Property && !item.documentation) {
|
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) {
|
if (info) {
|
||||||
item.documentation = this.getDocumentation(info.description, info.version, info.homepage);
|
item.documentation = this.getDocumentation(info.description, info.version, info.homepage);
|
||||||
return item;
|
return item;
|
||||||
|
|
|
@ -72,7 +72,7 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||||
// Render "fancy" when source is a workspace path
|
// Render "fancy" when source is a workspace path
|
||||||
const qualifierCandidate = vscode.workspace.asRelativePath(tsEntry.source);
|
const qualifierCandidate = vscode.workspace.asRelativePath(tsEntry.source);
|
||||||
if (qualifierCandidate !== tsEntry.source) {
|
if (qualifierCandidate !== tsEntry.source) {
|
||||||
this.label2 = { name: tsEntry.name, qualifier: qualifierCandidate };
|
this.label = { label: tsEntry.name, description: qualifierCandidate };
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,7 +81,7 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||||
|
|
||||||
const { sourceDisplay, isSnippet } = tsEntry;
|
const { sourceDisplay, isSnippet } = tsEntry;
|
||||||
if (sourceDisplay) {
|
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;
|
this.preselect = tsEntry.isRecommended;
|
||||||
|
@ -113,11 +113,11 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||||
const kindModifiers = parseKindModifier(tsEntry.kindModifiers);
|
const kindModifiers = parseKindModifier(tsEntry.kindModifiers);
|
||||||
if (kindModifiers.has(PConst.KindModifiers.optional)) {
|
if (kindModifiers.has(PConst.KindModifiers.optional)) {
|
||||||
if (!this.insertText) {
|
if (!this.insertText) {
|
||||||
this.insertText = this.label;
|
this.insertText = this.textLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.filterText) {
|
if (!this.filterText) {
|
||||||
this.filterText = this.label;
|
this.filterText = this.textLabel;
|
||||||
}
|
}
|
||||||
this.label += '?';
|
this.label += '?';
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,10 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||||
this.resolveRange();
|
this.resolveRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get textLabel() {
|
||||||
|
return typeof this.label === 'string' ? this.label : this.label.label;
|
||||||
|
}
|
||||||
|
|
||||||
private _resolvedPromise?: {
|
private _resolvedPromise?: {
|
||||||
readonly requestToken: vscode.CancellationTokenSource;
|
readonly requestToken: vscode.CancellationTokenSource;
|
||||||
readonly promise: Promise<ResolvedCompletionItem | undefined>;
|
readonly promise: Promise<ResolvedCompletionItem | undefined>;
|
||||||
|
@ -216,7 +220,7 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||||
if (this.useCodeSnippet) {
|
if (this.useCodeSnippet) {
|
||||||
const shouldCompleteFunction = await this.isValidFunctionCompletionContext(client, filepath, this.position, this.document, token);
|
const shouldCompleteFunction = await this.isValidFunctionCompletionContext(client, filepath, this.position, this.document, token);
|
||||||
if (shouldCompleteFunction) {
|
if (shouldCompleteFunction) {
|
||||||
const { snippet, parameterCount } = snippetForFunctionCall(this, detail.displayParts);
|
const { snippet, parameterCount } = snippetForFunctionCall({ ...this, label: this.textLabel }, detail.displayParts);
|
||||||
this.insertText = snippet;
|
this.insertText = snippet;
|
||||||
if (parameterCount > 0) {
|
if (parameterCount > 0) {
|
||||||
//Fix for https://github.com/microsoft/vscode/issues/104059
|
//Fix for https://github.com/microsoft/vscode/issues/104059
|
||||||
|
@ -408,8 +412,8 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||||
private getFuzzyWordRange() {
|
private getFuzzyWordRange() {
|
||||||
if (this.completionContext.useFuzzyWordRangeLogic) {
|
if (this.completionContext.useFuzzyWordRangeLogic) {
|
||||||
// Try getting longer, prefix based range for completions that span words
|
// 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 text = this.completionContext.line.slice(Math.max(0, this.position.character - this.textLabel.length), this.position.character).toLowerCase();
|
||||||
const entryName = this.label.toLowerCase();
|
const entryName = this.textLabel.toLowerCase();
|
||||||
for (let i = entryName.length; i >= 0; --i) {
|
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)) {
|
if (text.endsWith(entryName.substr(0, i)) && (!this.completionContext.wordRange || this.completionContext.wordRange.start.character > this.position.character - i)) {
|
||||||
return new vscode.Range(
|
return new vscode.Range(
|
||||||
|
|
|
@ -94,8 +94,8 @@ suite('SnippetsService', function () {
|
||||||
assert.strictEqual(result.incomplete, undefined);
|
assert.strictEqual(result.incomplete, undefined);
|
||||||
assert.strictEqual(result.suggestions.length, 1);
|
assert.strictEqual(result.suggestions.length, 1);
|
||||||
assert.deepStrictEqual(result.suggestions[0].label, {
|
assert.deepStrictEqual(result.suggestions[0].label, {
|
||||||
name: 'bar',
|
label: 'bar',
|
||||||
type: 'barTest'
|
description: 'barTest'
|
||||||
});
|
});
|
||||||
assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 1);
|
assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 1);
|
||||||
assert.strictEqual(result.suggestions[0].insertText, 'barCodeSnippet');
|
assert.strictEqual(result.suggestions[0].insertText, 'barCodeSnippet');
|
||||||
|
@ -129,14 +129,14 @@ suite('SnippetsService', function () {
|
||||||
assert.strictEqual(result.incomplete, undefined);
|
assert.strictEqual(result.incomplete, undefined);
|
||||||
assert.strictEqual(result.suggestions.length, 2);
|
assert.strictEqual(result.suggestions.length, 2);
|
||||||
assert.deepStrictEqual(result.suggestions[0].label, {
|
assert.deepStrictEqual(result.suggestions[0].label, {
|
||||||
name: 'bar',
|
label: 'bar',
|
||||||
type: 'barTest'
|
description: 'barTest'
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.suggestions[0].insertText, 's1');
|
assert.strictEqual(result.suggestions[0].insertText, 's1');
|
||||||
assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 1);
|
assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 1);
|
||||||
assert.deepStrictEqual(result.suggestions[1].label, {
|
assert.deepStrictEqual(result.suggestions[1].label, {
|
||||||
name: 'bar-bar',
|
label: 'bar-bar',
|
||||||
type: 'name'
|
description: 'name'
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.suggestions[1].insertText, 's2');
|
assert.strictEqual(result.suggestions[1].insertText, 's2');
|
||||||
assert.strictEqual((result.suggestions[1].range as any).insert.startColumn, 1);
|
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.incomplete, undefined);
|
||||||
assert.strictEqual(result.suggestions.length, 1);
|
assert.strictEqual(result.suggestions.length, 1);
|
||||||
assert.deepStrictEqual(result.suggestions[0].label, {
|
assert.deepStrictEqual(result.suggestions[0].label, {
|
||||||
name: 'bar-bar',
|
label: 'bar-bar',
|
||||||
type: 'name'
|
description: 'name'
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.suggestions[0].insertText, 's2');
|
assert.strictEqual(result.suggestions[0].insertText, 's2');
|
||||||
assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 1);
|
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.incomplete, undefined);
|
||||||
assert.strictEqual(result.suggestions.length, 2);
|
assert.strictEqual(result.suggestions.length, 2);
|
||||||
assert.deepStrictEqual(result.suggestions[0].label, {
|
assert.deepStrictEqual(result.suggestions[0].label, {
|
||||||
name: 'bar',
|
label: 'bar',
|
||||||
type: 'barTest'
|
description: 'barTest'
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.suggestions[0].insertText, 's1');
|
assert.strictEqual(result.suggestions[0].insertText, 's1');
|
||||||
assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 5);
|
assert.strictEqual((result.suggestions[0].range as any).insert.startColumn, 5);
|
||||||
assert.deepStrictEqual(result.suggestions[1].label, {
|
assert.deepStrictEqual(result.suggestions[1].label, {
|
||||||
name: 'bar-bar',
|
label: 'bar-bar',
|
||||||
type: 'name'
|
description: 'name'
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.suggestions[1].insertText, 's2');
|
assert.strictEqual(result.suggestions[1].insertText, 's2');
|
||||||
assert.strictEqual((result.suggestions[1].range as any).insert.startColumn, 1);
|
assert.strictEqual((result.suggestions[1].range as any).insert.startColumn, 1);
|
||||||
|
@ -254,12 +254,12 @@ suite('SnippetsService', function () {
|
||||||
assert.strictEqual(result.suggestions.length, 2);
|
assert.strictEqual(result.suggestions.length, 2);
|
||||||
let [first, second] = result.suggestions;
|
let [first, second] = result.suggestions;
|
||||||
assert.deepStrictEqual(first.label, {
|
assert.deepStrictEqual(first.label, {
|
||||||
name: 'first',
|
label: 'first',
|
||||||
type: 'first'
|
description: 'first'
|
||||||
});
|
});
|
||||||
assert.deepStrictEqual(second.label, {
|
assert.deepStrictEqual(second.label, {
|
||||||
name: 'second',
|
label: 'second',
|
||||||
type: 'second'
|
description: 'second'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -344,8 +344,8 @@ suite('SnippetsService', function () {
|
||||||
|
|
||||||
assert.strictEqual(result.suggestions.length, 1);
|
assert.strictEqual(result.suggestions.length, 1);
|
||||||
assert.deepStrictEqual(result.suggestions[0].label, {
|
assert.deepStrictEqual(result.suggestions[0].label, {
|
||||||
name: 'mytemplate',
|
label: 'mytemplate',
|
||||||
type: 'mytemplate'
|
description: 'mytemplate'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue