mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
add CompletionList to tackle #2224
This commit is contained in:
@@ -12,7 +12,7 @@ import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
|
||||
import {Range as EditorRange} from 'vs/editor/common/core/range';
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeConverters from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import {Range, DocumentHighlightKind, Disposable, Diagnostic, SignatureHelp} from 'vs/workbench/api/node/extHostTypes';
|
||||
import {Range, DocumentHighlightKind, Disposable, Diagnostic, SignatureHelp, CompletionList} from 'vs/workbench/api/node/extHostTypes';
|
||||
import {IPosition, IRange, ISingleEditOperation} from 'vs/editor/common/editorCommon';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
import {ExtHostModelService} from 'vs/workbench/api/node/extHostDocuments';
|
||||
@@ -487,7 +487,7 @@ class SuggestAdapter implements modes.ISuggestSupport {
|
||||
|
||||
private _documents: ExtHostModelService;
|
||||
private _provider: vscode.CompletionItemProvider;
|
||||
private _cache: { [key: string]: vscode.CompletionItem[] } = Object.create(null);
|
||||
private _cache: { [key: string]: CompletionList } = Object.create(null);
|
||||
|
||||
constructor(documents: ExtHostModelService, provider: vscode.CompletionItemProvider) {
|
||||
this._documents = documents;
|
||||
@@ -503,7 +503,7 @@ class SuggestAdapter implements modes.ISuggestSupport {
|
||||
const key = resource.toString();
|
||||
delete this._cache[key];
|
||||
|
||||
return asWinJsPromise(token => this._provider.provideCompletionItems(doc, pos, token)).then(value => {
|
||||
return asWinJsPromise<vscode.CompletionItem[]|vscode.CompletionList>(token => this._provider.provideCompletionItems(doc, pos, token)).then(value => {
|
||||
|
||||
let defaultSuggestions: modes.ISuggestResult = {
|
||||
suggestions: [],
|
||||
@@ -511,10 +511,19 @@ class SuggestAdapter implements modes.ISuggestSupport {
|
||||
};
|
||||
let allSuggestions: modes.ISuggestResult[] = [defaultSuggestions];
|
||||
|
||||
let list: CompletionList;
|
||||
if (Array.isArray(value)) {
|
||||
list = new CompletionList(value);
|
||||
} else if (value instanceof CompletionList) {
|
||||
list = value;
|
||||
defaultSuggestions.incomplete = list.isIncomplete;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const item = value[i];
|
||||
const suggestion = <ISuggestion2> TypeConverters.Suggest.from(item);
|
||||
for (let i = 0; i < list.items.length; i++) {
|
||||
const item = list.items[i];
|
||||
const suggestion = <ISuggestion2> TypeConverters.Suggest.from(<any>item);
|
||||
|
||||
if (item.textEdit) {
|
||||
|
||||
@@ -534,7 +543,8 @@ class SuggestAdapter implements modes.ISuggestSupport {
|
||||
|
||||
allSuggestions.push({
|
||||
currentWord: doc.getText(<any>editRange),
|
||||
suggestions: [suggestion]
|
||||
suggestions: [suggestion],
|
||||
incomplete: list.isIncomplete
|
||||
});
|
||||
|
||||
} else {
|
||||
@@ -546,7 +556,7 @@ class SuggestAdapter implements modes.ISuggestSupport {
|
||||
}
|
||||
|
||||
// cache for details call
|
||||
this._cache[key] = value;
|
||||
this._cache[key] = list;
|
||||
|
||||
return allSuggestions;
|
||||
});
|
||||
@@ -556,11 +566,11 @@ class SuggestAdapter implements modes.ISuggestSupport {
|
||||
if (typeof this._provider.resolveCompletionItem !== 'function') {
|
||||
return TPromise.as(suggestion);
|
||||
}
|
||||
let items = this._cache[resource.toString()];
|
||||
if (!items) {
|
||||
let list = this._cache[resource.toString()];
|
||||
if (!list) {
|
||||
return TPromise.as(suggestion);
|
||||
}
|
||||
let item = items[Number((<ISuggestion2> suggestion).id)];
|
||||
let item = list.items[Number((<ISuggestion2> suggestion).id)];
|
||||
if (!item) {
|
||||
return TPromise.as(suggestion);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user