mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
add CompletionList to tackle #2224
This commit is contained in:
@@ -82,6 +82,7 @@ export class ExtHostAPIImplementation {
|
||||
SignatureHelp: typeof vscode.SignatureHelp;
|
||||
CompletionItem: typeof vscode.CompletionItem;
|
||||
CompletionItemKind: typeof vscode.CompletionItemKind;
|
||||
CompletionList: typeof vscode.CompletionList;
|
||||
IndentAction: typeof vscode.IndentAction;
|
||||
OverviewRulerLane: typeof vscode.OverviewRulerLane;
|
||||
TextEditorRevealType: typeof vscode.TextEditorRevealType;
|
||||
@@ -124,6 +125,7 @@ export class ExtHostAPIImplementation {
|
||||
this.SignatureHelp = extHostTypes.SignatureHelp;
|
||||
this.CompletionItem = <any>extHostTypes.CompletionItem;
|
||||
this.CompletionItemKind = <any>extHostTypes.CompletionItemKind;
|
||||
this.CompletionList = extHostTypes.CompletionList;
|
||||
this.ViewColumn = <any>extHostTypes.ViewColumn;
|
||||
this.StatusBarAlignment = <any>extHostTypes.StatusBarAlignment;
|
||||
this.IndentAction = <any>Modes.IndentAction;
|
||||
|
||||
@@ -103,7 +103,7 @@ class ExtHostApiCommands {
|
||||
{ name: 'uri', description: 'Uri of a text document', constraint: URI },
|
||||
{ name: 'position', description: 'Position in a text document', constraint: types.Position }
|
||||
],
|
||||
returns: 'A promise that resolves to an array of CompletionItem-instances.'
|
||||
returns: 'A promise that resolves to a CompletionList-instance.'
|
||||
});
|
||||
this._register('vscode.executeCodeActionProvider', this._executeCodeActionProvider, {
|
||||
description: 'Execute code action provider.',
|
||||
@@ -265,7 +265,7 @@ class ExtHostApiCommands {
|
||||
});
|
||||
}
|
||||
|
||||
private _executeCompletionItemProvider(resource: URI, position: types.Position, triggerCharacter: string): Thenable<types.CompletionItem[]> {
|
||||
private _executeCompletionItemProvider(resource: URI, position: types.Position, triggerCharacter: string): Thenable<types.CompletionItem[]|types.CompletionList> {
|
||||
const args = {
|
||||
resource,
|
||||
position: position && typeConverters.fromPosition(position),
|
||||
@@ -274,15 +274,17 @@ class ExtHostApiCommands {
|
||||
return this._commands.executeCommand<modes.ISuggestResult[][]>('_executeCompletionItemProvider', args).then(value => {
|
||||
if (value) {
|
||||
let items: types.CompletionItem[] = [];
|
||||
let incomplete: boolean;
|
||||
for (let group of value) {
|
||||
for (let suggestions of group) {
|
||||
incomplete = suggestions.incomplete || incomplete;
|
||||
for (let suggestion of suggestions.suggestions) {
|
||||
const item = typeConverters.Suggest.to(suggestions, position, suggestion);
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
return new types.CompletionList(<any>items, incomplete);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -640,7 +640,7 @@ export enum CompletionItemKind {
|
||||
export class CompletionItem {
|
||||
|
||||
label: string;
|
||||
kind: CompletionItemKind;
|
||||
kind: CompletionItemKind
|
||||
detail: string;
|
||||
documentation: string;
|
||||
sortText: string;
|
||||
@@ -666,6 +666,18 @@ export class CompletionItem {
|
||||
}
|
||||
}
|
||||
|
||||
export class CompletionList {
|
||||
|
||||
isIncomplete: boolean;
|
||||
|
||||
items: vscode.CompletionItem[];
|
||||
|
||||
constructor(items: vscode.CompletionItem[] = [], isIncomplete: boolean = false) {
|
||||
this.items = items;
|
||||
this.isIncomplete = isIncomplete;
|
||||
}
|
||||
}
|
||||
|
||||
export enum ViewColumn {
|
||||
One = 1,
|
||||
Two = 2,
|
||||
|
||||
Reference in New Issue
Block a user