diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index 71ad6ba5f97..7b78569f9b6 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -258,32 +258,108 @@ export interface HoverProvider { /** * @internal */ -export type SuggestionType = 'method' - | 'function' - | 'constructor' - | 'field' - | 'variable' - | 'class' - | 'struct' - | 'interface' - | 'module' - | 'property' - | 'event' - | 'operator' - | 'unit' - | 'value' - | 'constant' - | 'enum' - | 'enum-member' - | 'keyword' - | 'snippet' - | 'text' - | 'color' - | 'file' - | 'reference' - | 'customcolor' - | 'folder' - | 'type-parameter'; +export const enum SuggestionKind { + Method, + Function, + Constructor, + Field, + Variable, + Class, + Struct, + Interface, + Module, + Property, + Event, + Operator, + Unit, + Value, + Constant, + Enum, + EnumMember, + Keyword, + Snippet, + Text, + Color, + File, + Reference, + Customcolor, + Folder, + TypeParameter, +} + +/** + * @internal + */ +export let suggestionKindToCssClass = (function () { + let data = Object.create(null); + data[SuggestionKind.Method] = 'method'; + data[SuggestionKind.Function] = 'function'; + data[SuggestionKind.Constructor] = 'constructor'; + data[SuggestionKind.Field] = 'field'; + data[SuggestionKind.Variable] = 'variable'; + data[SuggestionKind.Class] = 'class'; + data[SuggestionKind.Struct] = 'struct'; + data[SuggestionKind.Interface] = 'interface'; + data[SuggestionKind.Module] = 'module'; + data[SuggestionKind.Property] = 'property'; + data[SuggestionKind.Event] = 'event'; + data[SuggestionKind.Operator] = 'operator'; + data[SuggestionKind.Unit] = 'unit'; + data[SuggestionKind.Value] = 'value'; + data[SuggestionKind.Constant] = 'constant'; + data[SuggestionKind.Enum] = 'enum'; + data[SuggestionKind.EnumMember] = 'enum-member'; + data[SuggestionKind.Keyword] = 'keyword'; + data[SuggestionKind.Snippet] = 'snippet'; + data[SuggestionKind.Text] = 'text'; + data[SuggestionKind.Color] = 'color'; + data[SuggestionKind.File] = 'file'; + data[SuggestionKind.Reference] = 'reference'; + data[SuggestionKind.Customcolor] = 'customcolor'; + data[SuggestionKind.Folder] = 'folder'; + data[SuggestionKind.TypeParameter] = 'type-parameter'; + + return function (kind: SuggestionKind) { + return data[kind] || 'property'; + }; +})(); + +/** + * @internal + */ +export let suggestionKindFromLegacyString = (function () { + let data = Object.create(null); + data['method'] = SuggestionKind.Method; + data['function'] = SuggestionKind.Function; + data['constructor'] = SuggestionKind.Constructor; + data['field'] = SuggestionKind.Field; + data['variable'] = SuggestionKind.Variable; + data['class'] = SuggestionKind.Class; + data['struct'] = SuggestionKind.Struct; + data['interface'] = SuggestionKind.Interface; + data['module'] = SuggestionKind.Module; + data['property'] = SuggestionKind.Property; + data['event'] = SuggestionKind.Event; + data['operator'] = SuggestionKind.Operator; + data['unit'] = SuggestionKind.Unit; + data['value'] = SuggestionKind.Value; + data['constant'] = SuggestionKind.Constant; + data['enum'] = SuggestionKind.Enum; + data['enum-member'] = SuggestionKind.EnumMember; + data['keyword'] = SuggestionKind.Keyword; + data['snippet'] = SuggestionKind.Snippet; + data['text'] = SuggestionKind.Text; + data['color'] = SuggestionKind.Color; + data['file'] = SuggestionKind.File; + data['reference'] = SuggestionKind.Reference; + data['customcolor'] = SuggestionKind.Customcolor; + data['folder'] = SuggestionKind.Folder; + data['type-parameter'] = SuggestionKind.TypeParameter; + + return function (value: string) { + return data[value] || 'property'; + }; +})(); /** * @internal @@ -292,7 +368,7 @@ export interface ISuggestion { label: string; insertText: string; insertTextIsSnippet?: boolean; - type: SuggestionType; + kind: SuggestionKind; detail?: string; documentation?: string | IMarkdownString; filterText?: string; diff --git a/src/vs/editor/common/services/editorSimpleWorker.ts b/src/vs/editor/common/services/editorSimpleWorker.ts index 63b1b81f1ea..667861ff701 100644 --- a/src/vs/editor/common/services/editorSimpleWorker.ts +++ b/src/vs/editor/common/services/editorSimpleWorker.ts @@ -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, ISuggestResult, ISuggestion, TextEdit } from 'vs/editor/common/modes'; +import { IInplaceReplaceSupportResult, ILink, ISuggestResult, ISuggestion, TextEdit, SuggestionKind } 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({ - type: 'text', + kind: SuggestionKind.Text, label: word, insertText: word, noAutoAccept: true, diff --git a/src/vs/editor/contrib/snippet/snippetController2.ts b/src/vs/editor/contrib/snippet/snippetController2.ts index 03e9a581b1a..67a0000f73a 100644 --- a/src/vs/editor/contrib/snippet/snippetController2.ts +++ b/src/vs/editor/contrib/snippet/snippetController2.ts @@ -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 { ISuggestion } from 'vs/editor/common/modes'; +import { ISuggestion, SuggestionKind } 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 { - type: 'value', + kind: SuggestionKind.Value, label: option.value, insertText: option.value, // insertText: `\${1|${after.concat(before).join(',')}|}$0`, diff --git a/src/vs/editor/contrib/suggest/completionModel.ts b/src/vs/editor/contrib/suggest/completionModel.ts index 3ca9d14e882..46cb6c90d84 100644 --- a/src/vs/editor/contrib/suggest/completionModel.ts +++ b/src/vs/editor/contrib/suggest/completionModel.ts @@ -7,7 +7,7 @@ import { fuzzyScore, fuzzyScoreGracefulAggressive, anyScore } from 'vs/base/common/filters'; import { isDisposable } from 'vs/base/common/lifecycle'; -import { ISuggestResult, ISuggestSupport } from 'vs/editor/common/modes'; +import { ISuggestResult, ISuggestSupport, SuggestionKind } 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'; @@ -222,9 +222,9 @@ export class CompletionModel { // update stats this._stats.suggestionCount++; - switch (suggestion.type) { - case 'snippet': this._stats.snippetCount++; break; - case 'text': this._stats.textCount++; break; + switch (suggestion.kind) { + case SuggestionKind.Snippet: this._stats.snippetCount++; break; + case SuggestionKind.Text: this._stats.textCount++; break; } } @@ -251,10 +251,10 @@ export class CompletionModel { } private static _compareCompletionItemsSnippetsDown(a: ICompletionItem, b: ICompletionItem): number { - if (a.suggestion.type !== b.suggestion.type) { - if (a.suggestion.type === 'snippet') { + if (a.suggestion.kind !== b.suggestion.kind) { + if (a.suggestion.kind === SuggestionKind.Snippet) { return 1; - } else if (b.suggestion.type === 'snippet') { + } else if (b.suggestion.kind === SuggestionKind.Snippet) { return -1; } } @@ -262,10 +262,10 @@ export class CompletionModel { } private static _compareCompletionItemsSnippetsUp(a: ICompletionItem, b: ICompletionItem): number { - if (a.suggestion.type !== b.suggestion.type) { - if (a.suggestion.type === 'snippet') { + if (a.suggestion.kind !== b.suggestion.kind) { + if (a.suggestion.kind === SuggestionKind.Snippet) { return -1; - } else if (b.suggestion.type === 'snippet') { + } else if (b.suggestion.kind === SuggestionKind.Snippet) { return 1; } } diff --git a/src/vs/editor/contrib/suggest/suggest.ts b/src/vs/editor/contrib/suggest/suggest.ts index 595bbfc961f..8ffed9216b9 100644 --- a/src/vs/editor/contrib/suggest/suggest.ts +++ b/src/vs/editor/contrib/suggest/suggest.ts @@ -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 { ISuggestResult, ISuggestSupport, ISuggestion, SuggestRegistry, SuggestContext, SuggestTriggerKind } from 'vs/editor/common/modes'; +import { ISuggestResult, ISuggestSupport, ISuggestion, SuggestRegistry, SuggestContext, SuggestTriggerKind, SuggestionKind } 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'; @@ -152,7 +152,7 @@ function createSuggestionResolver(provider: ISuggestSupport, suggestion: ISugges function createSuggesionFilter(snippetConfig: SnippetConfig): (candidate: ISuggestion) => boolean { if (snippetConfig === 'none') { - return suggestion => suggestion.type !== 'snippet'; + return suggestion => suggestion.kind !== SuggestionKind.Snippet; } else { return () => true; } @@ -172,10 +172,10 @@ function defaultComparator(a: ISuggestionItem, b: ISuggestionItem): number { } // check with 'type' and lower snippets - if (ret === 0 && a.suggestion.type !== b.suggestion.type) { - if (a.suggestion.type === 'snippet') { + if (ret === 0 && a.suggestion.kind !== b.suggestion.kind) { + if (a.suggestion.kind === SuggestionKind.Snippet) { ret = 1; - } else if (b.suggestion.type === 'snippet') { + } else if (b.suggestion.kind === SuggestionKind.Snippet) { ret = -1; } } @@ -184,10 +184,10 @@ function defaultComparator(a: ISuggestionItem, b: ISuggestionItem): number { } function snippetUpComparator(a: ISuggestionItem, b: ISuggestionItem): number { - if (a.suggestion.type !== b.suggestion.type) { - if (a.suggestion.type === 'snippet') { + if (a.suggestion.kind !== b.suggestion.kind) { + if (a.suggestion.kind === SuggestionKind.Snippet) { return -1; - } else if (b.suggestion.type === 'snippet') { + } else if (b.suggestion.kind === SuggestionKind.Snippet) { return 1; } } @@ -195,10 +195,10 @@ function snippetUpComparator(a: ISuggestionItem, b: ISuggestionItem): number { } function snippetDownComparator(a: ISuggestionItem, b: ISuggestionItem): number { - if (a.suggestion.type !== b.suggestion.type) { - if (a.suggestion.type === 'snippet') { + if (a.suggestion.kind !== b.suggestion.kind) { + if (a.suggestion.kind === SuggestionKind.Snippet) { return 1; - } else if (b.suggestion.type === 'snippet') { + } else if (b.suggestion.kind === SuggestionKind.Snippet) { return -1; } } diff --git a/src/vs/editor/contrib/suggest/suggestController.ts b/src/vs/editor/contrib/suggest/suggestController.ts index 04504e8fc60..b8e875875f6 100644 --- a/src/vs/editor/contrib/suggest/suggestController.ts +++ b/src/vs/editor/contrib/suggest/suggestController.ts @@ -278,7 +278,7 @@ export class SuggestController implements IEditorContribution { } */ service.publicLog('acceptSuggestion', { - type: item.type, + type: item.kind, multiline: item.insertText.match(/\r|\n/) }); } diff --git a/src/vs/editor/contrib/suggest/suggestMemory.ts b/src/vs/editor/contrib/suggest/suggestMemory.ts index e278a619c96..be06c20f287 100644 --- a/src/vs/editor/contrib/suggest/suggestMemory.ts +++ b/src/vs/editor/contrib/suggest/suggestMemory.ts @@ -10,6 +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 { SuggestionKind, suggestionKindFromLegacyString } from 'vs/editor/common/modes'; export abstract class Memory { @@ -55,7 +56,7 @@ export class NoMemory extends Memory { } export interface MemItem { - type: string; + type: string | SuggestionKind; insertText: string; touch: number; } @@ -70,7 +71,7 @@ export class LRUMemory extends Memory { const key = `${model.getLanguageIdentifier().language}/${label}`; this._cache.set(key, { touch: this._seq++, - type: item.suggestion.type, + type: item.suggestion.kind, insertText: item.suggestion.insertText }); } @@ -94,7 +95,7 @@ export class LRUMemory extends Memory { const { suggestion } = items[i]; const key = `${model.getLanguageIdentifier().language}/${suggestion.label}`; const item = this._cache.get(key); - if (item && item.touch > seq && item.type === suggestion.type && item.insertText === suggestion.insertText) { + if (item && item.touch > seq && item.type === suggestion.kind && item.insertText === suggestion.insertText) { seq = item.touch; res = i; } @@ -119,6 +120,7 @@ export class LRUMemory extends Memory { let seq = 0; for (const [key, value] of data) { value.touch = seq; + value.type = typeof value.type === 'number' ? value.type : suggestionKindFromLegacyString(value.type); this._cache.set(key, value); } this._seq = this._cache.size; @@ -135,7 +137,7 @@ export class PrefixMemory extends Memory { const { word } = model.getWordUntilPosition(pos); const key = `${model.getLanguageIdentifier().language}/${word}`; this._trie.set(key, { - type: item.suggestion.type, + type: item.suggestion.kind, insertText: item.suggestion.insertText, touch: this._seq++ }); @@ -153,8 +155,8 @@ export class PrefixMemory extends Memory { } if (item) { for (let i = 0; i < items.length; i++) { - let { type, insertText } = items[i].suggestion; - if (type === item.type && insertText === item.insertText) { + let { kind, insertText } = items[i].suggestion; + if (kind === item.type && insertText === item.insertText) { return i; } } @@ -182,6 +184,7 @@ export class PrefixMemory extends Memory { if (data.length > 0) { this._seq = data[0][1].touch + 1; for (const [key, value] of data) { + value.type = typeof value.type === 'number' ? value.type : suggestionKindFromLegacyString(value.type); this._trie.set(key, value); } } diff --git a/src/vs/editor/contrib/suggest/suggestWidget.ts b/src/vs/editor/contrib/suggest/suggestWidget.ts index cdbc8ef1dc4..aa695cb66b5 100644 --- a/src/vs/editor/contrib/suggest/suggestWidget.ts +++ b/src/vs/editor/contrib/suggest/suggestWidget.ts @@ -34,6 +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 { SuggestionKind, suggestionKindToCssClass } from 'vs/editor/common/modes'; const expandSuggestionDocsByDefault = false; const maxSuggestionsToShow = 12; @@ -137,10 +138,10 @@ class Renderer implements IRenderer { const data = templateData; const suggestion = (element).suggestion; - data.icon.className = 'icon ' + suggestion.type; + data.icon.className = 'icon ' + suggestionKindToCssClass(suggestion.kind); data.colorspan.style.backgroundColor = ''; - if (suggestion.type === 'color') { + if (suggestion.kind === SuggestionKind.Color) { let color = matchesColor(suggestion.label) || typeof suggestion.documentation === 'string' && matchesColor(suggestion.documentation); if (color) { data.icon.className = 'icon customcolor'; @@ -501,7 +502,7 @@ export class SuggestWidget implements IContentWidget, IVirtualDelegate'keyword' + kind: modes.SuggestionKind.Keyword }; }) }; diff --git a/src/vs/workbench/parts/debug/electron-browser/debugSession.ts b/src/vs/workbench/parts/debug/electron-browser/debugSession.ts index e24b715089c..eb031d3da50 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugSession.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugSession.ts @@ -10,7 +10,7 @@ import * as platform from 'vs/base/common/platform'; import severity from 'vs/base/common/severity'; import { TPromise } from 'vs/base/common/winjs.base'; import { Event, Emitter } from 'vs/base/common/event'; -import { ISuggestion } from 'vs/editor/common/modes'; +import { ISuggestion, suggestionKindFromLegacyString } from 'vs/editor/common/modes'; import { Position } from 'vs/editor/common/core/position'; import * as aria from 'vs/base/browser/ui/aria/aria'; import { IDebugSession, IConfig, IThread, IRawModelUpdate, IDebugService, IRawStoppedDetails, State, LoadedSourceEvent, IFunctionBreakpoint, IExceptionBreakpoint, ActualBreakpoints, IBreakpoint, IExceptionInfo, AdapterEndEvent, IDebugger } from 'vs/workbench/parts/debug/common/debug'; @@ -461,7 +461,7 @@ export class DebugSession implements IDebugSession { result.push({ label: item.label, insertText: item.text || item.label, - type: item.type, + kind: suggestionKindFromLegacyString(item.type), filterText: item.start && item.length && text.substr(item.start, item.length).concat(item.label), overwriteBefore: item.length || overwriteBefore }); diff --git a/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts b/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts index f28b870a1df..4eae4f099e6 100644 --- a/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts +++ b/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts @@ -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 { ISuggestion, ISuggestResult, ISuggestSupport, LanguageId, SuggestContext, SuggestionType } from 'vs/editor/common/modes'; +import { ISuggestion, ISuggestResult, ISuggestSupport, LanguageId, SuggestContext, SuggestionKind } 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'; @@ -345,7 +345,7 @@ export class SnippetSuggestion implements ISuggestion { overwriteBefore: number; sortText: string; noAutoAccept: boolean; - type: SuggestionType; + kind: SuggestionKind; insertTextIsSnippet: true; constructor( @@ -358,7 +358,7 @@ export class SnippetSuggestion implements ISuggestion { this.overwriteBefore = overwriteBefore; this.sortText = `${snippet.snippetSource === SnippetSource.Extension ? 'z' : 'a'}-${snippet.prefix}`; this.noAutoAccept = true; - this.type = 'snippet'; + this.kind = SuggestionKind.Snippet; this.insertTextIsSnippet = true; }