Skip to content

Commit

Permalink
allow to resolve completion items via an argument, #44846
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Apr 13, 2018
1 parent 5da6916 commit 8973bea
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/vs/editor/contrib/suggest/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,20 @@ registerDefaultLanguageCommand('_executeCompletionItemProvider', (model, positio
suggestions: []
};

return provideSuggestionItems(model, position).then(items => {
let resolving: Thenable<any>[] = [];
let maxItemsToResolve = args['maxItemsToResolve'] || 0;

for (const { container, suggestion } of items) {
result.incomplete = result.incomplete || container.incomplete;
result.suggestions.push(suggestion);
return provideSuggestionItems(model, position).then(items => {
for (const item of items) {
if (resolving.length < maxItemsToResolve) {
resolving.push(item.resolve());
}
result.incomplete = result.incomplete || item.container.incomplete;
result.suggestions.push(item.suggestion);
}

}).then(() => {
return TPromise.join(resolving);
}).then(() => {
return result;
});
});
Expand Down
10 changes: 6 additions & 4 deletions src/vs/workbench/api/node/extHostApiCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export class ExtHostApiCommands {
args: [
{ name: 'uri', description: 'Uri of a text document', constraint: URI },
{ name: 'position', description: 'Position in a text document', constraint: types.Position },
{ name: 'triggerCharacter', description: '(optional) Trigger completion when the user types the character, like `,` or `(`', constraint: value => value === void 0 || typeof value === 'string' }
{ name: 'triggerCharacter', description: '(optional) Trigger completion when the user types the character, like `,` or `(`', constraint: value => value === void 0 || typeof value === 'string' },
{ name: 'itemResolveCount', description: '(optional) Number of completions to resolve (too large numbers slow down completions)', constraint: value => value === void 0 || typeof value === 'number' }
],
returns: 'A promise that resolves to a CompletionList-instance.'
});
Expand Down Expand Up @@ -392,11 +393,12 @@ export class ExtHostApiCommands {
});
}

private _executeCompletionItemProvider(resource: URI, position: types.Position, triggerCharacter: string): Thenable<types.CompletionList> {
private _executeCompletionItemProvider(resource: URI, position: types.Position, triggerCharacter: string, maxItemsToResolve: number): Thenable<types.CompletionList> {
const args = {
resource,
position: position && typeConverters.fromPosition(position),
triggerCharacter
triggerCharacter,
maxItemsToResolve
};
return this._commands.executeCommand<modes.ISuggestResult>('_executeCompletionItemProvider', args).then(result => {
if (result) {
Expand Down Expand Up @@ -528,4 +530,4 @@ function tryMapWith<T, R>(f: (x: T) => R) {
}
return undefined;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,39 @@ suite('ExtHostLanguageFeatureCommands', function () {
});
});

test('Suggest, resolve completion items', async function () {

let resolveCount = 0;

disposables.push(extHost.registerCompletionItemProvider(defaultSelector, <vscode.CompletionItemProvider>{
provideCompletionItems(): any {
let a = new types.CompletionItem('item1');
let b = new types.CompletionItem('item2');
let c = new types.CompletionItem('item3');
let d = new types.CompletionItem('item4');
return new types.CompletionList([a, b, c, d], false);
},
resolveCompletionItem(item) {
resolveCount += 1;
return item;
}
}, []));

await rpcProtocol.sync();

let list = await commands.executeCommand<vscode.CompletionList>(
'vscode.executeCompletionItemProvider',
model.uri,
new types.Position(0, 4),
undefined,
2 // maxItemsToResolve
);

assert.ok(list instanceof types.CompletionList);
assert.equal(resolveCount, 2);

});

// --- quickfix

test('QuickFix, back and forth', function () {
Expand Down

0 comments on commit 8973bea

Please sign in to comment.