提交 a1570023 编写于 作者: J Johannes Rieken

debt - remove suggest adapter and use CompletionItemProvider from modes.ts....

debt - remove suggest adapter and use CompletionItemProvider from modes.ts. Also fixes https://github.com/Microsoft/monaco-editor/issues/985
上级 0e8fe348
......@@ -255,10 +255,7 @@ export interface HoverProvider {
provideHover(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Hover>;
}
/**
* @internal
*/
export const enum CompletionKind {
export enum CompletionItemKind {
Method,
Function,
Constructor,
......@@ -292,34 +289,34 @@ export const enum CompletionKind {
*/
export let completionKindToCssClass = (function () {
let data = Object.create(null);
data[CompletionKind.Method] = 'method';
data[CompletionKind.Function] = 'function';
data[CompletionKind.Constructor] = 'constructor';
data[CompletionKind.Field] = 'field';
data[CompletionKind.Variable] = 'variable';
data[CompletionKind.Class] = 'class';
data[CompletionKind.Struct] = 'struct';
data[CompletionKind.Interface] = 'interface';
data[CompletionKind.Module] = 'module';
data[CompletionKind.Property] = 'property';
data[CompletionKind.Event] = 'event';
data[CompletionKind.Operator] = 'operator';
data[CompletionKind.Unit] = 'unit';
data[CompletionKind.Value] = 'value';
data[CompletionKind.Constant] = 'constant';
data[CompletionKind.Enum] = 'enum';
data[CompletionKind.EnumMember] = 'enum-member';
data[CompletionKind.Keyword] = 'keyword';
data[CompletionKind.Snippet] = 'snippet';
data[CompletionKind.Text] = 'text';
data[CompletionKind.Color] = 'color';
data[CompletionKind.File] = 'file';
data[CompletionKind.Reference] = 'reference';
data[CompletionKind.Customcolor] = 'customcolor';
data[CompletionKind.Folder] = 'folder';
data[CompletionKind.TypeParameter] = 'type-parameter';
return function (kind: CompletionKind) {
data[CompletionItemKind.Method] = 'method';
data[CompletionItemKind.Function] = 'function';
data[CompletionItemKind.Constructor] = 'constructor';
data[CompletionItemKind.Field] = 'field';
data[CompletionItemKind.Variable] = 'variable';
data[CompletionItemKind.Class] = 'class';
data[CompletionItemKind.Struct] = 'struct';
data[CompletionItemKind.Interface] = 'interface';
data[CompletionItemKind.Module] = 'module';
data[CompletionItemKind.Property] = 'property';
data[CompletionItemKind.Event] = 'event';
data[CompletionItemKind.Operator] = 'operator';
data[CompletionItemKind.Unit] = 'unit';
data[CompletionItemKind.Value] = 'value';
data[CompletionItemKind.Constant] = 'constant';
data[CompletionItemKind.Enum] = 'enum';
data[CompletionItemKind.EnumMember] = 'enum-member';
data[CompletionItemKind.Keyword] = 'keyword';
data[CompletionItemKind.Snippet] = 'snippet';
data[CompletionItemKind.Text] = 'text';
data[CompletionItemKind.Color] = 'color';
data[CompletionItemKind.File] = 'file';
data[CompletionItemKind.Reference] = 'reference';
data[CompletionItemKind.Customcolor] = 'customcolor';
data[CompletionItemKind.Folder] = 'folder';
data[CompletionItemKind.TypeParameter] = 'type-parameter';
return function (kind: CompletionItemKind) {
return data[kind] || 'property';
};
})();
......@@ -329,32 +326,32 @@ export let completionKindToCssClass = (function () {
*/
export let completionKindFromLegacyString = (function () {
let data = Object.create(null);
data['method'] = CompletionKind.Method;
data['function'] = CompletionKind.Function;
data['constructor'] = CompletionKind.Constructor;
data['field'] = CompletionKind.Field;
data['variable'] = CompletionKind.Variable;
data['class'] = CompletionKind.Class;
data['struct'] = CompletionKind.Struct;
data['interface'] = CompletionKind.Interface;
data['module'] = CompletionKind.Module;
data['property'] = CompletionKind.Property;
data['event'] = CompletionKind.Event;
data['operator'] = CompletionKind.Operator;
data['unit'] = CompletionKind.Unit;
data['value'] = CompletionKind.Value;
data['constant'] = CompletionKind.Constant;
data['enum'] = CompletionKind.Enum;
data['enum-member'] = CompletionKind.EnumMember;
data['keyword'] = CompletionKind.Keyword;
data['snippet'] = CompletionKind.Snippet;
data['text'] = CompletionKind.Text;
data['color'] = CompletionKind.Color;
data['file'] = CompletionKind.File;
data['reference'] = CompletionKind.Reference;
data['customcolor'] = CompletionKind.Customcolor;
data['folder'] = CompletionKind.Folder;
data['type-parameter'] = CompletionKind.TypeParameter;
data['method'] = CompletionItemKind.Method;
data['function'] = CompletionItemKind.Function;
data['constructor'] = CompletionItemKind.Constructor;
data['field'] = CompletionItemKind.Field;
data['variable'] = CompletionItemKind.Variable;
data['class'] = CompletionItemKind.Class;
data['struct'] = CompletionItemKind.Struct;
data['interface'] = CompletionItemKind.Interface;
data['module'] = CompletionItemKind.Module;
data['property'] = CompletionItemKind.Property;
data['event'] = CompletionItemKind.Event;
data['operator'] = CompletionItemKind.Operator;
data['unit'] = CompletionItemKind.Unit;
data['value'] = CompletionItemKind.Value;
data['constant'] = CompletionItemKind.Constant;
data['enum'] = CompletionItemKind.Enum;
data['enum-member'] = CompletionItemKind.EnumMember;
data['keyword'] = CompletionItemKind.Keyword;
data['snippet'] = CompletionItemKind.Snippet;
data['text'] = CompletionItemKind.Text;
data['color'] = CompletionItemKind.Color;
data['file'] = CompletionItemKind.File;
data['reference'] = CompletionItemKind.Reference;
data['customcolor'] = CompletionItemKind.Customcolor;
data['folder'] = CompletionItemKind.Folder;
data['type-parameter'] = CompletionItemKind.TypeParameter;
return function (value: string) {
return data[value] || 'property';
......@@ -362,29 +359,83 @@ export let completionKindFromLegacyString = (function () {
})();
/**
* @internal
* A completion item represents a text snippet that is
* proposed to complete text that is being typed.
*/
export interface CompletionItem {
/**
* The label of this completion item. By default
* this is also the text that is inserted when selecting
* this completion.
*/
label: string;
kind: CompletionKind;
/**
* The kind of this completion item. Based on the kind
* an icon is chosen by the editor.
*/
kind: CompletionItemKind;
/**
* A human-readable string with additional information
* about this item, like type or symbol information.
*/
detail?: string;
/**
* A human-readable string that represents a doc-comment.
*/
documentation?: string | IMarkdownString;
/**
* A string that should be used when comparing this item
* with other items. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
sortText?: string;
/**
* A string that should be used when filtering a set of
* completion items. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
filterText?: string;
preselect?: boolean;
/**
* A string or snippet that should be inserted in a document when selecting
* this completion. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
insertText: string;
/**
* The insert test is a snippet
*/
insertTextIsSnippet?: boolean;
noWhitespaceAdjust?: boolean;
/**
* A range of text that should be replaced by this completion item.
*
* Defaults to a range from the start of the [current word](#TextDocument.getWordRangeAtPosition) to the
* current position.
*
* *Note:* The range must be a [single line](#Range.isSingleLine) and it must
* [contain](#Range.contains) the position at which completion has been [requested](#CompletionItemProvider.provideCompletionItems).
*/
range?: IRange;
noAutoAccept?: boolean;
/**
* An optional set of characters that when pressed while this completion is active will accept it first and
* then type that character. *Note* that all commit characters should have `length=1` and that superfluous
* characters will be ignored.
*/
commitCharacters?: string[];
/**
* An optional array of additional text edits that are applied when
* selecting this completion. Edits must not overlap with the main edit
* nor with themselves.
*/
additionalTextEdits?: model.ISingleEditOperation[];
/**
* A command that should be run upon acceptance of this item.
*/
command?: Command;
noWhitespaceAdjust?: boolean;
noAutoAccept?: boolean;
}
/**
* @internal
*/
export interface CompletionList {
suggestions: CompletionItem[];
incomplete?: boolean;
......@@ -399,24 +450,47 @@ export enum CompletionTriggerKind {
TriggerCharacter = 1,
TriggerForIncompleteCompletions = 2
}
/**
* @internal
* Contains additional information about the context in which
* [completion provider](#CompletionItemProvider.provideCompletionItems) is triggered.
*/
export interface CompletionContext {
/**
* How the completion was triggered.
*/
triggerKind: CompletionTriggerKind;
/**
* Character that triggered the completion item provider.
*
* `undefined` if provider was not triggered by a character.
*/
triggerCharacter?: string;
}
/**
* @internal
* The completion item provider interface defines the contract between extensions and
* the [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
*
* When computing *complete* completion items is expensive, providers can optionally implement
* the `resolveCompletionItem`-function. In that case it is enough to return completion
* items with a [label](#CompletionItem.label) from the
* [provideCompletionItems](#CompletionItemProvider.provideCompletionItems)-function. Subsequently,
* when a completion item is shown in the UI and gains focus this provider is asked to resolve
* the item, like adding [doc-comment](#CompletionItem.documentation) or [details](#CompletionItem.detail).
*/
export interface CompletionItemProvider {
triggerCharacters?: string[];
/**
* Provide completion items for the given position and document.
*/
provideCompletionItems(model: model.ITextModel, position: Position, context: CompletionContext, token: CancellationToken): ProviderResult<CompletionList>;
/**
* Given a completion item fill in more data, like [doc-comment](#CompletionItem.documentation)
* or [details](#CompletionItem.detail).
*
* The editor will only resolve a completion item once.
*/
resolveCompletionItem?(model: model.ITextModel, position: Position, item: CompletionItem, token: CancellationToken): ProviderResult<CompletionItem>;
}
......
......@@ -15,7 +15,7 @@ import { stringDiff } from 'vs/base/common/diff/diff';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { Position, IPosition } from 'vs/editor/common/core/position';
import { MirrorTextModel as BaseMirrorModel, IModelChangedEvent } from 'vs/editor/common/model/mirrorTextModel';
import { IInplaceReplaceSupportResult, ILink, CompletionList, CompletionItem, TextEdit, CompletionKind } from 'vs/editor/common/modes';
import { IInplaceReplaceSupportResult, ILink, CompletionList, CompletionItem, TextEdit, CompletionItemKind } from 'vs/editor/common/modes';
import { computeLinks, ILinkComputerTarget } from 'vs/editor/common/modes/linkComputer';
import { BasicInplaceReplace } from 'vs/editor/common/modes/supports/inplaceReplaceSupport';
import { getWordAtText, ensureValidWordDefinition } from 'vs/editor/common/model/wordHelper';
......@@ -482,7 +482,7 @@ export abstract class BaseEditorSimpleWorker {
}
suggestions.push({
kind: CompletionKind.Text,
kind: CompletionItemKind.Text,
label: word,
insertText: word,
noAutoAccept: true,
......
......@@ -14,7 +14,7 @@ import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { CompletionItem, CompletionKind } from 'vs/editor/common/modes';
import { CompletionItem, CompletionItemKind } from 'vs/editor/common/modes';
import { Choice } from 'vs/editor/contrib/snippet/snippetParser';
import { showSimpleSuggestions } from 'vs/editor/contrib/suggest/suggest';
import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
......@@ -169,7 +169,7 @@ export class SnippetController2 implements IEditorContribution {
// let after = choice.options.slice(i);
return <CompletionItem>{
kind: CompletionKind.Value,
kind: CompletionItemKind.Value,
label: option.value,
insertText: option.value,
// insertText: `\${1|${after.concat(before).join(',')}|}$0`,
......
......@@ -7,7 +7,7 @@
import { fuzzyScore, fuzzyScoreGracefulAggressive, anyScore } from 'vs/base/common/filters';
import { isDisposable } from 'vs/base/common/lifecycle';
import { CompletionList, CompletionItemProvider, CompletionKind } from 'vs/editor/common/modes';
import { CompletionList, CompletionItemProvider, CompletionItemKind } from 'vs/editor/common/modes';
import { ISuggestionItem } from './suggest';
import { InternalSuggestOptions, EDITOR_DEFAULTS } from 'vs/editor/common/config/editorOptions';
import { WordDistance } from 'vs/editor/contrib/suggest/wordDistance';
......@@ -224,8 +224,8 @@ export class CompletionModel {
// update stats
this._stats.suggestionCount++;
switch (suggestion.kind) {
case CompletionKind.Snippet: this._stats.snippetCount++; break;
case CompletionKind.Text: this._stats.textCount++; break;
case CompletionItemKind.Snippet: this._stats.snippetCount++; break;
case CompletionItemKind.Text: this._stats.textCount++; break;
}
}
......@@ -253,9 +253,9 @@ export class CompletionModel {
private static _compareCompletionItemsSnippetsDown(a: ICompletionItem, b: ICompletionItem): number {
if (a.suggestion.kind !== b.suggestion.kind) {
if (a.suggestion.kind === CompletionKind.Snippet) {
if (a.suggestion.kind === CompletionItemKind.Snippet) {
return 1;
} else if (b.suggestion.kind === CompletionKind.Snippet) {
} else if (b.suggestion.kind === CompletionItemKind.Snippet) {
return -1;
}
}
......@@ -264,9 +264,9 @@ export class CompletionModel {
private static _compareCompletionItemsSnippetsUp(a: ICompletionItem, b: ICompletionItem): number {
if (a.suggestion.kind !== b.suggestion.kind) {
if (a.suggestion.kind === CompletionKind.Snippet) {
if (a.suggestion.kind === CompletionItemKind.Snippet) {
return -1;
} else if (b.suggestion.kind === CompletionKind.Snippet) {
} else if (b.suggestion.kind === CompletionItemKind.Snippet) {
return 1;
}
}
......
......@@ -11,7 +11,7 @@ import { onUnexpectedExternalError, canceled } from 'vs/base/common/errors';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { ITextModel } from 'vs/editor/common/model';
import { registerDefaultLanguageCommand } from 'vs/editor/browser/editorExtensions';
import { CompletionList, CompletionItemProvider, CompletionItem, CompletionProviderRegistry, CompletionContext, CompletionTriggerKind, CompletionKind } from 'vs/editor/common/modes';
import { CompletionList, CompletionItemProvider, CompletionItem, CompletionProviderRegistry, CompletionContext, CompletionTriggerKind, CompletionItemKind } from 'vs/editor/common/modes';
import { Position, IPosition } from 'vs/editor/common/core/position';
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
......@@ -149,7 +149,7 @@ function createSuggestionResolver(provider: CompletionItemProvider, suggestion:
function createSuggesionFilter(snippetConfig: SnippetConfig): (candidate: CompletionItem) => boolean {
if (snippetConfig === 'none') {
return suggestion => suggestion.kind !== CompletionKind.Snippet;
return suggestion => suggestion.kind !== CompletionItemKind.Snippet;
} else {
return () => true;
}
......@@ -170,9 +170,9 @@ function defaultComparator(a: ISuggestionItem, b: ISuggestionItem): number {
// check with 'type' and lower snippets
if (ret === 0 && a.suggestion.kind !== b.suggestion.kind) {
if (a.suggestion.kind === CompletionKind.Snippet) {
if (a.suggestion.kind === CompletionItemKind.Snippet) {
ret = 1;
} else if (b.suggestion.kind === CompletionKind.Snippet) {
} else if (b.suggestion.kind === CompletionItemKind.Snippet) {
ret = -1;
}
}
......@@ -182,9 +182,9 @@ function defaultComparator(a: ISuggestionItem, b: ISuggestionItem): number {
function snippetUpComparator(a: ISuggestionItem, b: ISuggestionItem): number {
if (a.suggestion.kind !== b.suggestion.kind) {
if (a.suggestion.kind === CompletionKind.Snippet) {
if (a.suggestion.kind === CompletionItemKind.Snippet) {
return -1;
} else if (b.suggestion.kind === CompletionKind.Snippet) {
} else if (b.suggestion.kind === CompletionItemKind.Snippet) {
return 1;
}
}
......@@ -193,9 +193,9 @@ function snippetUpComparator(a: ISuggestionItem, b: ISuggestionItem): number {
function snippetDownComparator(a: ISuggestionItem, b: ISuggestionItem): number {
if (a.suggestion.kind !== b.suggestion.kind) {
if (a.suggestion.kind === CompletionKind.Snippet) {
if (a.suggestion.kind === CompletionItemKind.Snippet) {
return 1;
} else if (b.suggestion.kind === CompletionKind.Snippet) {
} else if (b.suggestion.kind === CompletionItemKind.Snippet) {
return -1;
}
}
......
......@@ -10,7 +10,7 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import { ITextModel } from 'vs/editor/common/model';
import { IPosition } from 'vs/editor/common/core/position';
import { RunOnceScheduler } from 'vs/base/common/async';
import { CompletionKind, completionKindFromLegacyString } from 'vs/editor/common/modes';
import { CompletionItemKind, completionKindFromLegacyString } from 'vs/editor/common/modes';
export abstract class Memory {
......@@ -56,7 +56,7 @@ export class NoMemory extends Memory {
}
export interface MemItem {
type: string | CompletionKind;
type: string | CompletionItemKind;
insertText: string;
touch: number;
}
......
......@@ -34,7 +34,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { TimeoutTimer, CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { CompletionKind, completionKindToCssClass } from 'vs/editor/common/modes';
import { CompletionItemKind, completionKindToCssClass } from 'vs/editor/common/modes';
const expandSuggestionDocsByDefault = false;
const maxSuggestionsToShow = 12;
......@@ -141,7 +141,7 @@ class Renderer implements IRenderer<ICompletionItem, ISuggestionTemplateData> {
data.icon.className = 'icon ' + completionKindToCssClass(suggestion.kind);
data.colorspan.style.backgroundColor = '';
if (suggestion.kind === CompletionKind.Color) {
if (suggestion.kind === CompletionItemKind.Color) {
let color = matchesColor(suggestion.label) || typeof suggestion.documentation === 'string' && matchesColor(suggestion.documentation);
if (color) {
data.icon.className = 'icon customcolor';
......@@ -502,7 +502,7 @@ export class SuggestWidget implements IContentWidget, IVirtualDelegate<ICompleti
}
private _getSuggestionAriaAlertLabel(item: ICompletionItem): string {
const isSnippet = item.suggestion.kind === CompletionKind.Snippet;
const isSnippet = item.suggestion.kind === CompletionItemKind.Snippet;
if (!canExpandCompletionItem(item)) {
return isSnippet ? nls.localize('ariaCurrentSnippetSuggestion', "{0}, snippet suggestion", item.suggestion.label)
......
......@@ -6,12 +6,12 @@
import * as assert from 'assert';
import { IPosition } from 'vs/editor/common/core/position';
import { CompletionList, CompletionItemProvider, CompletionItem, CompletionKind } from 'vs/editor/common/modes';
import { CompletionList, CompletionItemProvider, CompletionItem, CompletionItemKind } from 'vs/editor/common/modes';
import { CompletionModel } from 'vs/editor/contrib/suggest/completionModel';
import { ISuggestionItem, getSuggestionComparator } from 'vs/editor/contrib/suggest/suggest';
import { WordDistance } from 'vs/editor/contrib/suggest/wordDistance';
export function createSuggestItem(label: string, overwriteBefore: number, kind = CompletionKind.Property, incomplete: boolean = false, position: IPosition = { lineNumber: 1, column: 1 }): ISuggestionItem {
export function createSuggestItem(label: string, overwriteBefore: number, kind = CompletionItemKind.Property, incomplete: boolean = false, position: IPosition = { lineNumber: 1, column: 1 }): ISuggestionItem {
return new class implements ISuggestionItem {
......@@ -161,9 +161,9 @@ suite('CompletionModel', function () {
test('keep snippet sorting with prefix: top, #25495', function () {
model = new CompletionModel([
createSuggestItem('Snippet1', 1, CompletionKind.Snippet),
createSuggestItem('tnippet2', 1, CompletionKind.Snippet),
createSuggestItem('semver', 1, CompletionKind.Property),
createSuggestItem('Snippet1', 1, CompletionItemKind.Snippet),
createSuggestItem('tnippet2', 1, CompletionItemKind.Snippet),
createSuggestItem('semver', 1, CompletionItemKind.Property),
], 1, {
leadingLineContent: 's',
characterCountDelta: 0
......@@ -180,9 +180,9 @@ suite('CompletionModel', function () {
test('keep snippet sorting with prefix: bottom, #25495', function () {
model = new CompletionModel([
createSuggestItem('snippet1', 1, CompletionKind.Snippet),
createSuggestItem('tnippet2', 1, CompletionKind.Snippet),
createSuggestItem('Semver', 1, CompletionKind.Property),
createSuggestItem('snippet1', 1, CompletionItemKind.Snippet),
createSuggestItem('tnippet2', 1, CompletionItemKind.Snippet),
createSuggestItem('Semver', 1, CompletionItemKind.Property),
], 1, {
leadingLineContent: 's',
characterCountDelta: 0
......@@ -198,8 +198,8 @@ suite('CompletionModel', function () {
test('keep snippet sorting with prefix: inline, #25495', function () {
model = new CompletionModel([
createSuggestItem('snippet1', 1, CompletionKind.Snippet),
createSuggestItem('tnippet2', 1, CompletionKind.Snippet),
createSuggestItem('snippet1', 1, CompletionItemKind.Snippet),
createSuggestItem('tnippet2', 1, CompletionItemKind.Snippet),
createSuggestItem('Semver', 1),
], 1, {
leadingLineContent: 's',
......@@ -235,11 +235,11 @@ suite('CompletionModel', function () {
test('Vscode 1.12 no longer obeys \'sortText\' in completion items (from language server), #26096', function () {
const item1 = createSuggestItem('<- groups', 2, CompletionKind.Property, false, { lineNumber: 1, column: 3 });
const item1 = createSuggestItem('<- groups', 2, CompletionItemKind.Property, false, { lineNumber: 1, column: 3 });
item1.suggestion.filterText = ' groups';
item1.suggestion.sortText = '00002';
const item2 = createSuggestItem('source', 0, CompletionKind.Property, false, { lineNumber: 1, column: 3 });
const item2 = createSuggestItem('source', 0, CompletionItemKind.Property, false, { lineNumber: 1, column: 3 });
item2.suggestion.filterText = 'source';
item2.suggestion.sortText = '00001';
......
......@@ -7,7 +7,7 @@
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { IDisposable } from 'vs/base/common/lifecycle';
import { CompletionProviderRegistry, CompletionKind } from 'vs/editor/common/modes';
import { CompletionProviderRegistry, CompletionItemKind } from 'vs/editor/common/modes';
import { provideSuggestionItems } from 'vs/editor/contrib/suggest/suggest';
import { Position } from 'vs/editor/common/core/position';
import { TextModel } from 'vs/editor/common/model/textModel';
......@@ -27,15 +27,15 @@ suite('Suggest', function () {
incomplete: false,
suggestions: [{
label: 'aaa',
kind: CompletionKind.Snippet,
kind: CompletionItemKind.Snippet,
insertText: 'aaa'
}, {
label: 'zzz',
kind: CompletionKind.Snippet,
kind: CompletionItemKind.Snippet,
insertText: 'zzz'
}, {
label: 'fff',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'fff'
}]
};
......
......@@ -15,7 +15,7 @@ import { Selection } from 'vs/editor/common/core/selection';
import { TokenizationResult2 } from 'vs/editor/common/core/token';
import { Handler } from 'vs/editor/common/editorCommon';
import { TextModel } from 'vs/editor/common/model/textModel';
import { IState, CompletionList, CompletionItemProvider, LanguageIdentifier, MetadataConsts, CompletionProviderRegistry, CompletionTriggerKind, TokenizationRegistry, CompletionKind } from 'vs/editor/common/modes';
import { IState, CompletionList, CompletionItemProvider, LanguageIdentifier, MetadataConsts, CompletionProviderRegistry, CompletionTriggerKind, TokenizationRegistry, CompletionItemKind } from 'vs/editor/common/modes';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { NULL_STATE } from 'vs/editor/common/modes/nullMode';
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
......@@ -157,7 +157,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
incomplete: false,
suggestions: [{
label: doc.getWordUntilPosition(pos).word,
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'foofoo'
}]
};
......@@ -305,7 +305,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
incomplete: false,
suggestions: [{
label: 'My Table',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'My Table'
}]
};
......@@ -354,7 +354,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
incomplete: false,
suggestions: [{
label: 'foo.bar',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'foo.bar',
range: Range.fromPositions(pos.with(undefined, 1), pos)
}]
......@@ -369,7 +369,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
incomplete: false,
suggestions: [{
label: 'boom',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'boom',
range: Range.fromPositions(
pos.delta(0, doc.getLineContent(pos.lineNumber)[pos.column - 2] === '.' ? 0 : -1),
......@@ -466,7 +466,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
incomplete: true,
suggestions: [{
label: 'foo',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'foo',
range: Range.fromPositions(pos.with(undefined, 1), pos)
}]
......@@ -503,7 +503,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
incomplete: true,
suggestions: [{
label: 'foo;',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'foo',
range: Range.fromPositions(pos.with(undefined, 1), pos)
}]
......@@ -550,7 +550,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
suggestions: [
{
label: 'foo.bar',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'foo.bar',
range: Range.fromPositions(pos.with(undefined, 1), pos)
}
......@@ -579,12 +579,12 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
incomplete: true,
suggestions: [{
label: 'abc',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'abc',
range: Range.fromPositions(pos.with(undefined, 1), pos)
}, {
label: 'äbc',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'äbc',
range: Range.fromPositions(pos.with(undefined, 1), pos)
}]
......@@ -651,7 +651,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
incomplete: true,
suggestions: [{
label: 'bar',
kind: CompletionKind.Property,
kind: CompletionItemKind.Property,
insertText: 'bar',
range: Range.fromPositions(pos.delta(0, -2), pos),
additionalTextEdits: [{
......@@ -723,7 +723,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
provideCompletionItems(doc, pos) {
return {
incomplete: true,
suggestions: [{ kind: CompletionKind.Folder, label: 'CompleteNot', insertText: 'Incomplete', sortText: 'a', overwriteBefore: pos.column - 1 }],
suggestions: [{ kind: CompletionItemKind.Folder, label: 'CompleteNot', insertText: 'Incomplete', sortText: 'a', overwriteBefore: pos.column - 1 }],
dispose() { disposeA += 1; }
};
}
......@@ -732,7 +732,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
provideCompletionItems(doc, pos) {
return {
incomplete: false,
suggestions: [{ kind: CompletionKind.Folder, label: 'Complete', insertText: 'Complete', sortText: 'z', overwriteBefore: pos.column - 1 }],
suggestions: [{ kind: CompletionItemKind.Folder, label: 'Complete', insertText: 'Complete', sortText: 'z', overwriteBefore: pos.column - 1 }],
dispose() { disposeB += 1; }
};
},
......
......@@ -11,7 +11,7 @@ import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerServ
import { IPosition } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import * as tokenTree from 'vs/editor/contrib/smartSelect/tokenTree';
import { CompletionItem, CompletionKind } from 'vs/editor/common/modes';
import { CompletionItem, CompletionItemKind } from 'vs/editor/common/modes';
export abstract class WordDistance {
......@@ -58,7 +58,7 @@ export abstract class WordDistance {
if (!wordRanges || !position.equals(editor.getPosition())) {
return 0;
}
if (suggestion.kind === CompletionKind.Keyword) {
if (suggestion.kind === CompletionItemKind.Keyword) {
return 2 << 20;
}
let word = suggestion.label;
......
......@@ -5,7 +5,6 @@
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { IDisposable } from 'vs/base/common/lifecycle';
import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry';
import { IMonarchLanguage } from 'vs/editor/standalone/common/monarch/monarchTypes';
......@@ -23,7 +22,6 @@ import { IMarkerData } from 'vs/platform/markers/common/markers';
import { Token, TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token';
import { IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneThemeService';
import * as model from 'vs/editor/common/model';
import { IMarkdownString } from 'vs/base/common/htmlContent';
/**
* Register information about a new language.
......@@ -454,17 +452,8 @@ export function registerLinkProvider(languageId: string, provider: modes.LinkPro
/**
* Register a completion item provider (use by e.g. suggestions).
*/
export function registerCompletionItemProvider(languageId: string, provider: CompletionItemProvider): IDisposable {
let adapter = new SuggestAdapter(provider);
return modes.CompletionProviderRegistry.register(languageId, {
triggerCharacters: provider.triggerCharacters,
provideCompletionItems: (model: model.ITextModel, position: Position, context: modes.CompletionContext, token: CancellationToken): Thenable<modes.CompletionList> => {
return adapter.provideCompletionItems(model, position, context, token);
},
resolveCompletionItem: (model: model.ITextModel, position: Position, suggestion: modes.CompletionItem, token: CancellationToken): Thenable<modes.CompletionItem> => {
return adapter.resolveCompletionItem(model, position, suggestion, token);
}
});
export function registerCompletionItemProvider(languageId: string, provider: modes.CompletionItemProvider): IDisposable {
return modes.CompletionProviderRegistry.register(languageId, provider);
}
/**
......@@ -511,333 +500,6 @@ export interface CodeActionProvider {
provideCodeActions(model: model.ITextModel, range: Range, context: CodeActionContext, token: CancellationToken): (modes.Command | modes.CodeAction)[] | Thenable<(modes.Command | modes.CodeAction)[]>;
}
/**
* Completion item kinds.
*/
export enum CompletionItemKind {
Text,
Method,
Function,
Constructor,
Field,
Variable,
Class,
Interface,
Module,
Property,
Unit,
Value,
Enum,
Keyword,
Snippet,
Color,
File,
Reference,
Folder
}
/**
* A snippet string is a template which allows to insert text
* and to control the editor cursor when insertion happens.
*
* A snippet can define tab stops and placeholders with `$1`, `$2`
* and `${3:foo}`. `$0` defines the final tab stop, it defaults to
* the end of the snippet. Variables are defined with `$name` and
* `${name:default value}`. The full snippet syntax is documented
* [here](http://code.visualstudio.com/docs/editor/userdefinedsnippets#_creating-your-own-snippets).
*/
export interface SnippetString {
/**
* The snippet string.
*/
value: string;
}
/**
* A completion item represents a text snippet that is
* proposed to complete text that is being typed.
*/
export interface CompletionItem {
/**
* The label of this completion item. By default
* this is also the text that is inserted when selecting
* this completion.
*/
label: string;
/**
* The kind of this completion item. Based on the kind
* an icon is chosen by the editor.
*/
kind: CompletionItemKind;
/**
* A human-readable string with additional information
* about this item, like type or symbol information.
*/
detail?: string;
/**
* A human-readable string that represents a doc-comment.
*/
documentation?: string | IMarkdownString;
/**
* A command that should be run upon acceptance of this item.
*/
command?: modes.Command;
/**
* A string that should be used when comparing this item
* with other items. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
sortText?: string;
/**
* A string that should be used when filtering a set of
* completion items. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
filterText?: string;
/**
* A string or snippet that should be inserted in a document when selecting
* this completion. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
insertText?: string | SnippetString;
/**
* A range of text that should be replaced by this completion item.
*
* Defaults to a range from the start of the [current word](#TextDocument.getWordRangeAtPosition) to the
* current position.
*
* *Note:* The range must be a [single line](#Range.isSingleLine) and it must
* [contain](#Range.contains) the position at which completion has been [requested](#CompletionItemProvider.provideCompletionItems).
*/
range?: Range;
/**
* An optional set of characters that when pressed while this completion is active will accept it first and
* then type that character. *Note* that all commit characters should have `length=1` and that superfluous
* characters will be ignored.
*/
commitCharacters?: string[];
/**
* @deprecated **Deprecated** in favor of `CompletionItem.insertText` and `CompletionItem.range`.
*
* ~~An [edit](#TextEdit) which is applied to a document when selecting
* this completion. When an edit is provided the value of
* [insertText](#CompletionItem.insertText) is ignored.~~
*
* ~~The [range](#Range) of the edit must be single-line and on the same
* line completions were [requested](#CompletionItemProvider.provideCompletionItems) at.~~
*/
textEdit?: model.ISingleEditOperation;
/**
* An optional array of additional text edits that are applied when
* selecting this completion. Edits must not overlap with the main edit
* nor with themselves.
*/
additionalTextEdits?: model.ISingleEditOperation[];
}
/**
* Represents a collection of [completion items](#CompletionItem) to be presented
* in the editor.
*/
export interface CompletionList {
/**
* This list it not complete. Further typing should result in recomputing
* this list.
*/
isIncomplete?: boolean;
/**
* The completion items.
*/
items: CompletionItem[];
}
/**
* Contains additional information about the context in which
* [completion provider](#CompletionItemProvider.provideCompletionItems) is triggered.
*/
export interface CompletionContext {
/**
* How the completion was triggered.
*/
triggerKind: modes.CompletionTriggerKind;
/**
* Character that triggered the completion item provider.
*
* `undefined` if provider was not triggered by a character.
*/
triggerCharacter?: string;
}
/**
* The completion item provider interface defines the contract between extensions and
* the [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
*
* When computing *complete* completion items is expensive, providers can optionally implement
* the `resolveCompletionItem`-function. In that case it is enough to return completion
* items with a [label](#CompletionItem.label) from the
* [provideCompletionItems](#CompletionItemProvider.provideCompletionItems)-function. Subsequently,
* when a completion item is shown in the UI and gains focus this provider is asked to resolve
* the item, like adding [doc-comment](#CompletionItem.documentation) or [details](#CompletionItem.detail).
*/
export interface CompletionItemProvider {
triggerCharacters?: string[];
/**
* Provide completion items for the given position and document.
*/
provideCompletionItems(document: model.ITextModel, position: Position, token: CancellationToken, context: CompletionContext): CompletionItem[] | Thenable<CompletionItem[]> | CompletionList | Thenable<CompletionList>;
/**
* Given a completion item fill in more data, like [doc-comment](#CompletionItem.documentation)
* or [details](#CompletionItem.detail).
*
* The editor will only resolve a completion item once.
*/
resolveCompletionItem?(item: CompletionItem, token: CancellationToken): CompletionItem | Thenable<CompletionItem>;
}
interface ISuggestion2 extends modes.CompletionItem {
_actual: CompletionItem;
}
function convertKind(kind: CompletionItemKind): modes.CompletionKind {
switch (kind) {
case CompletionItemKind.Method: return modes.CompletionKind.Method;
case CompletionItemKind.Function: return modes.CompletionKind.Function;
case CompletionItemKind.Constructor: return modes.CompletionKind.Constructor;
case CompletionItemKind.Field: return modes.CompletionKind.Field;
case CompletionItemKind.Variable: return modes.CompletionKind.Variable;
case CompletionItemKind.Class: return modes.CompletionKind.Class;
case CompletionItemKind.Interface: return modes.CompletionKind.Interface;
case CompletionItemKind.Module: return modes.CompletionKind.Module;
case CompletionItemKind.Property: return modes.CompletionKind.Property;
case CompletionItemKind.Unit: return modes.CompletionKind.Unit;
case CompletionItemKind.Value: return modes.CompletionKind.Value;
case CompletionItemKind.Enum: return modes.CompletionKind.Enum;
case CompletionItemKind.Keyword: return modes.CompletionKind.Keyword;
case CompletionItemKind.Snippet: return modes.CompletionKind.Snippet;
case CompletionItemKind.Text: return modes.CompletionKind.Text;
case CompletionItemKind.Color: return modes.CompletionKind.Color;
case CompletionItemKind.File: return modes.CompletionKind.File;
case CompletionItemKind.Reference: return modes.CompletionKind.Reference;
case CompletionItemKind.Folder: return modes.CompletionKind.Folder;
}
return modes.CompletionKind.Property;
}
class SuggestAdapter {
private _provider: CompletionItemProvider;
constructor(provider: CompletionItemProvider) {
this._provider = provider;
}
private static from(item: CompletionItem, position: Position, wordStartPos: Position): ISuggestion2 {
let suggestion: ISuggestion2 = {
_actual: item,
label: item.label,
insertText: item.label,
kind: convertKind(item.kind),
detail: item.detail,
documentation: item.documentation,
command: item.command,
sortText: item.sortText,
filterText: item.filterText,
insertTextIsSnippet: false,
additionalTextEdits: item.additionalTextEdits,
commitCharacters: item.commitCharacters
};
let editRange = item.textEdit ? item.textEdit.range : item.range;
if (editRange) {
let isSingleLine = (editRange.startLineNumber === editRange.endLineNumber);
// invalid text edit
if (!isSingleLine || editRange.startLineNumber !== position.lineNumber) {
console.warn('INVALID range, must be single line and on the same line');
return null;
}
// insert the text of the edit and create a dedicated
// suggestion-container with overwrite[Before|After]
suggestion.range = editRange;
} else {
suggestion.range = { startLineNumber: position.lineNumber, startColumn: wordStartPos.column, endLineNumber: position.lineNumber, endColumn: position.column };
}
if (item.textEdit) {
suggestion.insertText = item.textEdit.text;
} else if (typeof item.insertText === 'object' && typeof item.insertText.value === 'string') {
suggestion.insertText = item.insertText.value;
suggestion.insertTextIsSnippet = true;
} else if (typeof item.insertText === 'string') {
suggestion.insertText = item.insertText;
}
return suggestion;
}
provideCompletionItems(model: model.ITextModel, position: Position, context: modes.CompletionContext, token: CancellationToken): Thenable<modes.CompletionList> {
const result = this._provider.provideCompletionItems(model, position, token, context);
return Promise.resolve<CompletionItem[] | CompletionList>(result).then(value => {
const result: modes.CompletionList = {
suggestions: []
};
// default text edit start
let wordStartPos = position;
const word = model.getWordUntilPosition(position);
if (word) {
wordStartPos = new Position(wordStartPos.lineNumber, word.startColumn);
}
let list: CompletionList;
if (Array.isArray(value)) {
list = {
items: value,
isIncomplete: false
};
} else if (typeof value === 'object' && Array.isArray(value.items)) {
list = value;
result.incomplete = list.isIncomplete;
} else if (!value) {
// undefined and null are valid results
return undefined;
} else {
// warn about everything else
console.warn('INVALID result from completion provider. expected CompletionItem-array or CompletionList but got:', value);
}
for (let i = 0; i < list.items.length; i++) {
const item = list.items[i];
const suggestion = SuggestAdapter.from(item, position, wordStartPos);
if (suggestion) {
result.suggestions.push(suggestion);
}
}
return result;
});
}
resolveCompletionItem(model: model.ITextModel, position: Position, suggestion: modes.CompletionItem, token: CancellationToken): Thenable<modes.CompletionItem> {
if (typeof this._provider.resolveCompletionItem !== 'function') {
return TPromise.as(suggestion);
}
let item = (<ISuggestion2>suggestion)._actual;
if (!item) {
return TPromise.as(suggestion);
}
return Promise.resolve(this._provider.resolveCompletionItem(item, token)).then(resolvedItem => {
let wordStartPos = position;
const word = model.getWordUntilPosition(position);
if (word) {
wordStartPos = new Position(wordStartPos.lineNumber, word.startColumn);
}
return SuggestAdapter.from(resolvedItem, position, wordStartPos);
});
}
}
/**
* @internal
*/
......@@ -873,7 +535,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
// enums
DocumentHighlightKind: modes.DocumentHighlightKind,
CompletionItemKind: CompletionItemKind,
CompletionItemKind: modes.CompletionItemKind,
SymbolKind: modes.SymbolKind,
IndentAction: IndentAction,
CompletionTriggerKind: modes.CompletionTriggerKind,
......
......@@ -4377,189 +4377,6 @@ declare namespace monaco.languages {
provideCodeActions(model: editor.ITextModel, range: Range, context: CodeActionContext, token: CancellationToken): (Command | CodeAction)[] | Thenable<(Command | CodeAction)[]>;
}
/**
* Completion item kinds.
*/
export enum CompletionItemKind {
Text = 0,
Method = 1,
Function = 2,
Constructor = 3,
Field = 4,
Variable = 5,
Class = 6,
Interface = 7,
Module = 8,
Property = 9,
Unit = 10,
Value = 11,
Enum = 12,
Keyword = 13,
Snippet = 14,
Color = 15,
File = 16,
Reference = 17,
Folder = 18
}
/**
* A snippet string is a template which allows to insert text
* and to control the editor cursor when insertion happens.
*
* A snippet can define tab stops and placeholders with `$1`, `$2`
* and `${3:foo}`. `$0` defines the final tab stop, it defaults to
* the end of the snippet. Variables are defined with `$name` and
* `${name:default value}`. The full snippet syntax is documented
* [here](http://code.visualstudio.com/docs/editor/userdefinedsnippets#_creating-your-own-snippets).
*/
export interface SnippetString {
/**
* The snippet string.
*/
value: string;
}
/**
* A completion item represents a text snippet that is
* proposed to complete text that is being typed.
*/
export interface CompletionItem {
/**
* The label of this completion item. By default
* this is also the text that is inserted when selecting
* this completion.
*/
label: string;
/**
* The kind of this completion item. Based on the kind
* an icon is chosen by the editor.
*/
kind: CompletionItemKind;
/**
* A human-readable string with additional information
* about this item, like type or symbol information.
*/
detail?: string;
/**
* A human-readable string that represents a doc-comment.
*/
documentation?: string | IMarkdownString;
/**
* A command that should be run upon acceptance of this item.
*/
command?: Command;
/**
* A string that should be used when comparing this item
* with other items. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
sortText?: string;
/**
* A string that should be used when filtering a set of
* completion items. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
filterText?: string;
/**
* A string or snippet that should be inserted in a document when selecting
* this completion. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
insertText?: string | SnippetString;
/**
* A range of text that should be replaced by this completion item.
*
* Defaults to a range from the start of the [current word](#TextDocument.getWordRangeAtPosition) to the
* current position.
*
* *Note:* The range must be a [single line](#Range.isSingleLine) and it must
* [contain](#Range.contains) the position at which completion has been [requested](#CompletionItemProvider.provideCompletionItems).
*/
range?: Range;
/**
* An optional set of characters that when pressed while this completion is active will accept it first and
* then type that character. *Note* that all commit characters should have `length=1` and that superfluous
* characters will be ignored.
*/
commitCharacters?: string[];
/**
* @deprecated **Deprecated** in favor of `CompletionItem.insertText` and `CompletionItem.range`.
*
* ~~An [edit](#TextEdit) which is applied to a document when selecting
* this completion. When an edit is provided the value of
* [insertText](#CompletionItem.insertText) is ignored.~~
*
* ~~The [range](#Range) of the edit must be single-line and on the same
* line completions were [requested](#CompletionItemProvider.provideCompletionItems) at.~~
*/
textEdit?: editor.ISingleEditOperation;
/**
* An optional array of additional text edits that are applied when
* selecting this completion. Edits must not overlap with the main edit
* nor with themselves.
*/
additionalTextEdits?: editor.ISingleEditOperation[];
}
/**
* Represents a collection of [completion items](#CompletionItem) to be presented
* in the editor.
*/
export interface CompletionList {
/**
* This list it not complete. Further typing should result in recomputing
* this list.
*/
isIncomplete?: boolean;
/**
* The completion items.
*/
items: CompletionItem[];
}
/**
* Contains additional information about the context in which
* [completion provider](#CompletionItemProvider.provideCompletionItems) is triggered.
*/
export interface CompletionContext {
/**
* How the completion was triggered.
*/
triggerKind: CompletionTriggerKind;
/**
* Character that triggered the completion item provider.
*
* `undefined` if provider was not triggered by a character.
*/
triggerCharacter?: string;
}
/**
* The completion item provider interface defines the contract between extensions and
* the [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
*
* When computing *complete* completion items is expensive, providers can optionally implement
* the `resolveCompletionItem`-function. In that case it is enough to return completion
* items with a [label](#CompletionItem.label) from the
* [provideCompletionItems](#CompletionItemProvider.provideCompletionItems)-function. Subsequently,
* when a completion item is shown in the UI and gains focus this provider is asked to resolve
* the item, like adding [doc-comment](#CompletionItem.documentation) or [details](#CompletionItem.detail).
*/
export interface CompletionItemProvider {
triggerCharacters?: string[];
/**
* Provide completion items for the given position and document.
*/
provideCompletionItems(document: editor.ITextModel, position: Position, token: CancellationToken, context: CompletionContext): CompletionItem[] | Thenable<CompletionItem[]> | CompletionList | Thenable<CompletionList>;
/**
* Given a completion item fill in more data, like [doc-comment](#CompletionItem.documentation)
* or [details](#CompletionItem.detail).
*
* The editor will only resolve a completion item once.
*/
resolveCompletionItem?(item: CompletionItem, token: CancellationToken): CompletionItem | Thenable<CompletionItem>;
}
/**
* Describes how comments for a language work.
*/
......@@ -4832,6 +4649,119 @@ declare namespace monaco.languages {
provideHover(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Hover>;
}
export enum CompletionItemKind {
Method = 0,
Function = 1,
Constructor = 2,
Field = 3,
Variable = 4,
Class = 5,
Struct = 6,
Interface = 7,
Module = 8,
Property = 9,
Event = 10,
Operator = 11,
Unit = 12,
Value = 13,
Constant = 14,
Enum = 15,
EnumMember = 16,
Keyword = 17,
Snippet = 18,
Text = 19,
Color = 20,
File = 21,
Reference = 22,
Customcolor = 23,
Folder = 24,
TypeParameter = 25
}
/**
* A completion item represents a text snippet that is
* proposed to complete text that is being typed.
*/
export interface CompletionItem {
/**
* The label of this completion item. By default
* this is also the text that is inserted when selecting
* this completion.
*/
label: string;
/**
* The kind of this completion item. Based on the kind
* an icon is chosen by the editor.
*/
kind: CompletionItemKind;
/**
* A human-readable string with additional information
* about this item, like type or symbol information.
*/
detail?: string;
/**
* A human-readable string that represents a doc-comment.
*/
documentation?: string | IMarkdownString;
/**
* A string that should be used when comparing this item
* with other items. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
sortText?: string;
/**
* A string that should be used when filtering a set of
* completion items. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
filterText?: string;
preselect?: boolean;
/**
* A string or snippet that should be inserted in a document when selecting
* this completion. When `falsy` the [label](#CompletionItem.label)
* is used.
*/
insertText: string;
/**
* The insert test is a snippet
*/
insertTextIsSnippet?: boolean;
/**
* A range of text that should be replaced by this completion item.
*
* Defaults to a range from the start of the [current word](#TextDocument.getWordRangeAtPosition) to the
* current position.
*
* *Note:* The range must be a [single line](#Range.isSingleLine) and it must
* [contain](#Range.contains) the position at which completion has been [requested](#CompletionItemProvider.provideCompletionItems).
*/
range?: IRange;
/**
* An optional set of characters that when pressed while this completion is active will accept it first and
* then type that character. *Note* that all commit characters should have `length=1` and that superfluous
* characters will be ignored.
*/
commitCharacters?: string[];
/**
* An optional array of additional text edits that are applied when
* selecting this completion. Edits must not overlap with the main edit
* nor with themselves.
*/
additionalTextEdits?: editor.ISingleEditOperation[];
/**
* A command that should be run upon acceptance of this item.
*/
command?: Command;
noWhitespaceAdjust?: boolean;
noAutoAccept?: boolean;
}
export interface CompletionList {
suggestions: CompletionItem[];
incomplete?: boolean;
dispose?(): void;
}
/**
* How a suggest provider was triggered.
*/
......@@ -4841,6 +4771,49 @@ declare namespace monaco.languages {
TriggerForIncompleteCompletions = 2
}
/**
* Contains additional information about the context in which
* [completion provider](#CompletionItemProvider.provideCompletionItems) is triggered.
*/
export interface CompletionContext {
/**
* How the completion was triggered.
*/
triggerKind: CompletionTriggerKind;
/**
* Character that triggered the completion item provider.
*
* `undefined` if provider was not triggered by a character.
*/
triggerCharacter?: string;
}
/**
* The completion item provider interface defines the contract between extensions and
* the [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
*
* When computing *complete* completion items is expensive, providers can optionally implement
* the `resolveCompletionItem`-function. In that case it is enough to return completion
* items with a [label](#CompletionItem.label) from the
* [provideCompletionItems](#CompletionItemProvider.provideCompletionItems)-function. Subsequently,
* when a completion item is shown in the UI and gains focus this provider is asked to resolve
* the item, like adding [doc-comment](#CompletionItem.documentation) or [details](#CompletionItem.detail).
*/
export interface CompletionItemProvider {
triggerCharacters?: string[];
/**
* Provide completion items for the given position and document.
*/
provideCompletionItems(model: editor.ITextModel, position: Position, context: CompletionContext, token: CancellationToken): ProviderResult<CompletionList>;
/**
* Given a completion item fill in more data, like [doc-comment](#CompletionItem.documentation)
* or [details](#CompletionItem.detail).
*
* The editor will only resolve a completion item once.
*/
resolveCompletionItem?(model: editor.ITextModel, position: Position, item: CompletionItem, token: CancellationToken): ProviderResult<CompletionItem>;
}
export interface CodeAction {
title: string;
command?: Command;
......
......@@ -479,64 +479,64 @@ export namespace CompletionContext {
export const CompletionItemKind = {
from(kind: types.CompletionItemKind): modes.CompletionKind {
from(kind: types.CompletionItemKind): modes.CompletionItemKind {
switch (kind) {
case types.CompletionItemKind.Method: return modes.CompletionKind.Method;
case types.CompletionItemKind.Function: return modes.CompletionKind.Function;
case types.CompletionItemKind.Constructor: return modes.CompletionKind.Constructor;
case types.CompletionItemKind.Field: return modes.CompletionKind.Field;
case types.CompletionItemKind.Variable: return modes.CompletionKind.Variable;
case types.CompletionItemKind.Class: return modes.CompletionKind.Class;
case types.CompletionItemKind.Interface: return modes.CompletionKind.Interface;
case types.CompletionItemKind.Struct: return modes.CompletionKind.Struct;
case types.CompletionItemKind.Module: return modes.CompletionKind.Module;
case types.CompletionItemKind.Property: return modes.CompletionKind.Property;
case types.CompletionItemKind.Unit: return modes.CompletionKind.Unit;
case types.CompletionItemKind.Value: return modes.CompletionKind.Value;
case types.CompletionItemKind.Constant: return modes.CompletionKind.Constant;
case types.CompletionItemKind.Enum: return modes.CompletionKind.Enum;
case types.CompletionItemKind.EnumMember: return modes.CompletionKind.EnumMember;
case types.CompletionItemKind.Keyword: return modes.CompletionKind.Keyword;
case types.CompletionItemKind.Snippet: return modes.CompletionKind.Snippet;
case types.CompletionItemKind.Text: return modes.CompletionKind.Text;
case types.CompletionItemKind.Color: return modes.CompletionKind.Color;
case types.CompletionItemKind.File: return modes.CompletionKind.File;
case types.CompletionItemKind.Reference: return modes.CompletionKind.Reference;
case types.CompletionItemKind.Folder: return modes.CompletionKind.Folder;
case types.CompletionItemKind.Event: return modes.CompletionKind.Event;
case types.CompletionItemKind.Operator: return modes.CompletionKind.Operator;
case types.CompletionItemKind.TypeParameter: return modes.CompletionKind.TypeParameter;
}
return modes.CompletionKind.Property;
case types.CompletionItemKind.Method: return modes.CompletionItemKind.Method;
case types.CompletionItemKind.Function: return modes.CompletionItemKind.Function;
case types.CompletionItemKind.Constructor: return modes.CompletionItemKind.Constructor;
case types.CompletionItemKind.Field: return modes.CompletionItemKind.Field;
case types.CompletionItemKind.Variable: return modes.CompletionItemKind.Variable;
case types.CompletionItemKind.Class: return modes.CompletionItemKind.Class;
case types.CompletionItemKind.Interface: return modes.CompletionItemKind.Interface;
case types.CompletionItemKind.Struct: return modes.CompletionItemKind.Struct;
case types.CompletionItemKind.Module: return modes.CompletionItemKind.Module;
case types.CompletionItemKind.Property: return modes.CompletionItemKind.Property;
case types.CompletionItemKind.Unit: return modes.CompletionItemKind.Unit;
case types.CompletionItemKind.Value: return modes.CompletionItemKind.Value;
case types.CompletionItemKind.Constant: return modes.CompletionItemKind.Constant;
case types.CompletionItemKind.Enum: return modes.CompletionItemKind.Enum;
case types.CompletionItemKind.EnumMember: return modes.CompletionItemKind.EnumMember;
case types.CompletionItemKind.Keyword: return modes.CompletionItemKind.Keyword;
case types.CompletionItemKind.Snippet: return modes.CompletionItemKind.Snippet;
case types.CompletionItemKind.Text: return modes.CompletionItemKind.Text;
case types.CompletionItemKind.Color: return modes.CompletionItemKind.Color;
case types.CompletionItemKind.File: return modes.CompletionItemKind.File;
case types.CompletionItemKind.Reference: return modes.CompletionItemKind.Reference;
case types.CompletionItemKind.Folder: return modes.CompletionItemKind.Folder;
case types.CompletionItemKind.Event: return modes.CompletionItemKind.Event;
case types.CompletionItemKind.Operator: return modes.CompletionItemKind.Operator;
case types.CompletionItemKind.TypeParameter: return modes.CompletionItemKind.TypeParameter;
}
return modes.CompletionItemKind.Property;
},
to(kind: modes.CompletionKind): types.CompletionItemKind {
to(kind: modes.CompletionItemKind): types.CompletionItemKind {
switch (kind) {
case modes.CompletionKind.Method: return types.CompletionItemKind.Method;
case modes.CompletionKind.Function: return types.CompletionItemKind.Function;
case modes.CompletionKind.Constructor: return types.CompletionItemKind.Constructor;
case modes.CompletionKind.Field: return types.CompletionItemKind.Field;
case modes.CompletionKind.Variable: return types.CompletionItemKind.Variable;
case modes.CompletionKind.Class: return types.CompletionItemKind.Class;
case modes.CompletionKind.Interface: return types.CompletionItemKind.Interface;
case modes.CompletionKind.Struct: return types.CompletionItemKind.Struct;
case modes.CompletionKind.Module: return types.CompletionItemKind.Module;
case modes.CompletionKind.Property: return types.CompletionItemKind.Property;
case modes.CompletionKind.Unit: return types.CompletionItemKind.Unit;
case modes.CompletionKind.Value: return types.CompletionItemKind.Value;
case modes.CompletionKind.Constant: return types.CompletionItemKind.Constant;
case modes.CompletionKind.Enum: return types.CompletionItemKind.Enum;
case modes.CompletionKind.EnumMember: return types.CompletionItemKind.EnumMember;
case modes.CompletionKind.Keyword: return types.CompletionItemKind.Keyword;
case modes.CompletionKind.Snippet: return types.CompletionItemKind.Snippet;
case modes.CompletionKind.Text: return types.CompletionItemKind.Text;
case modes.CompletionKind.Color: return types.CompletionItemKind.Color;
case modes.CompletionKind.File: return types.CompletionItemKind.File;
case modes.CompletionKind.Reference: return types.CompletionItemKind.Reference;
case modes.CompletionKind.Folder: return types.CompletionItemKind.Folder;
case modes.CompletionKind.Event: return types.CompletionItemKind.Event;
case modes.CompletionKind.Operator: return types.CompletionItemKind.Operator;
case modes.CompletionKind.TypeParameter: return types.CompletionItemKind.TypeParameter;
case modes.CompletionItemKind.Method: return types.CompletionItemKind.Method;
case modes.CompletionItemKind.Function: return types.CompletionItemKind.Function;
case modes.CompletionItemKind.Constructor: return types.CompletionItemKind.Constructor;
case modes.CompletionItemKind.Field: return types.CompletionItemKind.Field;
case modes.CompletionItemKind.Variable: return types.CompletionItemKind.Variable;
case modes.CompletionItemKind.Class: return types.CompletionItemKind.Class;
case modes.CompletionItemKind.Interface: return types.CompletionItemKind.Interface;
case modes.CompletionItemKind.Struct: return types.CompletionItemKind.Struct;
case modes.CompletionItemKind.Module: return types.CompletionItemKind.Module;
case modes.CompletionItemKind.Property: return types.CompletionItemKind.Property;
case modes.CompletionItemKind.Unit: return types.CompletionItemKind.Unit;
case modes.CompletionItemKind.Value: return types.CompletionItemKind.Value;
case modes.CompletionItemKind.Constant: return types.CompletionItemKind.Constant;
case modes.CompletionItemKind.Enum: return types.CompletionItemKind.Enum;
case modes.CompletionItemKind.EnumMember: return types.CompletionItemKind.EnumMember;
case modes.CompletionItemKind.Keyword: return types.CompletionItemKind.Keyword;
case modes.CompletionItemKind.Snippet: return types.CompletionItemKind.Snippet;
case modes.CompletionItemKind.Text: return types.CompletionItemKind.Text;
case modes.CompletionItemKind.Color: return types.CompletionItemKind.Color;
case modes.CompletionItemKind.File: return types.CompletionItemKind.File;
case modes.CompletionItemKind.Reference: return types.CompletionItemKind.Reference;
case modes.CompletionItemKind.Folder: return types.CompletionItemKind.Folder;
case modes.CompletionItemKind.Event: return types.CompletionItemKind.Event;
case modes.CompletionItemKind.Operator: return types.CompletionItemKind.Operator;
case modes.CompletionItemKind.TypeParameter: return types.CompletionItemKind.TypeParameter;
}
return types.CompletionItemKind.Property;
}
......
......@@ -186,7 +186,7 @@ export class SuggestEnabledInput extends Widget implements IThemable {
insertText: result,
overwriteBefore: alreadyTypedCount,
sortText: validatedSuggestProvider.sortKey(result),
kind: modes.CompletionKind.Keyword
kind: modes.CompletionItemKind.Keyword
};
})
};
......
......@@ -14,7 +14,7 @@ import { compare, endsWith, isFalsyOrWhitespace } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { Position } from 'vs/editor/common/core/position';
import { ITextModel } from 'vs/editor/common/model';
import { CompletionItem, CompletionList, CompletionItemProvider, LanguageId, CompletionContext, CompletionKind } from 'vs/editor/common/modes';
import { CompletionItem, CompletionList, CompletionItemProvider, LanguageId, CompletionContext, CompletionItemKind } from 'vs/editor/common/modes';
import { IModeService } from 'vs/editor/common/services/modeService';
import { SnippetParser } from 'vs/editor/contrib/snippet/snippetParser';
import { setSnippetSuggestSupport } from 'vs/editor/contrib/suggest/suggest';
......@@ -349,7 +349,7 @@ export class SnippetSuggestion implements CompletionItem {
range: IRange;
sortText: string;
noAutoAccept: boolean;
kind: CompletionKind;
kind: CompletionItemKind;
insertTextIsSnippet: true;
constructor(
......@@ -362,7 +362,7 @@ export class SnippetSuggestion implements CompletionItem {
this.range = range;
this.sortText = `${snippet.snippetSource === SnippetSource.Extension ? 'z' : 'a'}-${snippet.prefix}`;
this.noAutoAccept = true;
this.kind = CompletionKind.Snippet;
this.kind = CompletionItemKind.Snippet;
this.insertTextIsSnippet = true;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册