diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index debe94e1572464c442adc0e18794b77bad4f45b1..1ab88ea05ce6ba7c1568da44480bfecdecc5615e 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -532,7 +532,7 @@ const editorConfiguration: IConfigurationNode = { nls.localize('snippetSuggestions.inline', "Show snippets suggestions with other suggestions."), nls.localize('snippetSuggestions.none', "Do not show snippet suggestions."), ], - 'default': EDITOR_DEFAULTS.contribInfo.snippetSuggestions, + 'default': EDITOR_DEFAULTS.contribInfo.suggest.snippets, 'description': nls.localize('snippetSuggestions', "Controls whether snippets are shown with other suggestions and how they are sorted.") }, 'editor.emptySelectionClipboard': { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 1d7e0e55680199cf1e9bce14de09ada059542451..2189eaf348ec0f538d76857f21c813ec38baa421 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -843,6 +843,7 @@ export interface InternalEditorHoverOptions { export interface InternalSuggestOptions { readonly filterGraceful: boolean; + readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; } export interface EditorWrappingInfo { @@ -912,7 +913,7 @@ export interface EditorContribOptions { readonly suggestOnTriggerCharacters: boolean; readonly acceptSuggestionOnEnter: 'on' | 'smart' | 'off'; readonly acceptSuggestionOnCommitCharacter: boolean; - readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none'; + // readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none'; readonly wordBasedSuggestions: boolean; readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'; readonly suggestFontSize: number; @@ -1245,13 +1246,13 @@ export class InternalEditorOptions { /** * @internal */ - private static _equalsSuggestOptions(a: ISuggestOptions, b: ISuggestOptions): any { + private static _equalsSuggestOptions(a: InternalSuggestOptions, b: InternalSuggestOptions): any { if (a === b) { return true; } else if (!a || !b) { return false; } else { - return a.filterGraceful === b.filterGraceful; + return a.filterGraceful === b.filterGraceful && a.snippets === b.snippets; } } @@ -1290,7 +1291,6 @@ export class InternalEditorOptions { && a.suggestOnTriggerCharacters === b.suggestOnTriggerCharacters && a.acceptSuggestionOnEnter === b.acceptSuggestionOnEnter && a.acceptSuggestionOnCommitCharacter === b.acceptSuggestionOnCommitCharacter - && a.snippetSuggestions === b.snippetSuggestions && a.wordBasedSuggestions === b.wordBasedSuggestions && a.suggestSelection === b.suggestSelection && a.suggestFontSize === b.suggestFontSize @@ -1744,13 +1744,13 @@ export class EditorOptionsValidator { }; } - private static _sanitizeSuggestOpts(opts: ISuggestOptions, defaults: InternalSuggestOptions): InternalSuggestOptions { - if (!opts) { + private static _sanitizeSuggestOpts(opts: IEditorOptions, defaults: InternalSuggestOptions): InternalSuggestOptions { + if (!opts.suggest) { return defaults; } - let { filterGraceful } = opts; return { - filterGraceful: _boolean(filterGraceful, defaults.filterGraceful) + filterGraceful: _boolean(opts.suggest.filterGraceful, defaults.filterGraceful), + snippets: _stringSet<'top' | 'bottom' | 'inline' | 'none'>(opts.snippetSuggestions, defaults.snippets, ['top', 'bottom', 'inline', 'none']), }; } @@ -1885,12 +1885,11 @@ export class EditorOptionsValidator { suggestOnTriggerCharacters: _boolean(opts.suggestOnTriggerCharacters, defaults.suggestOnTriggerCharacters), acceptSuggestionOnEnter: _stringSet<'on' | 'smart' | 'off'>(opts.acceptSuggestionOnEnter, defaults.acceptSuggestionOnEnter, ['on', 'smart', 'off']), acceptSuggestionOnCommitCharacter: _boolean(opts.acceptSuggestionOnCommitCharacter, defaults.acceptSuggestionOnCommitCharacter), - snippetSuggestions: _stringSet<'top' | 'bottom' | 'inline' | 'none'>(opts.snippetSuggestions, defaults.snippetSuggestions, ['top', 'bottom', 'inline', 'none']), wordBasedSuggestions: _boolean(opts.wordBasedSuggestions, defaults.wordBasedSuggestions), suggestSelection: _stringSet<'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'>(opts.suggestSelection, defaults.suggestSelection, ['first', 'recentlyUsed', 'recentlyUsedByPrefix']), suggestFontSize: _clampedInt(opts.suggestFontSize, defaults.suggestFontSize, 0, 1000), suggestLineHeight: _clampedInt(opts.suggestLineHeight, defaults.suggestLineHeight, 0, 1000), - suggest: this._sanitizeSuggestOpts(opts.suggest, defaults.suggest), + suggest: this._sanitizeSuggestOpts(opts, defaults.suggest), selectionHighlight: _boolean(opts.selectionHighlight, defaults.selectionHighlight), occurrencesHighlight: _boolean(opts.occurrencesHighlight, defaults.occurrencesHighlight), codeLens: _boolean(opts.codeLens, defaults.codeLens), @@ -1994,7 +1993,6 @@ export class InternalEditorOptionsFactory { suggestOnTriggerCharacters: opts.contribInfo.suggestOnTriggerCharacters, acceptSuggestionOnEnter: opts.contribInfo.acceptSuggestionOnEnter, acceptSuggestionOnCommitCharacter: opts.contribInfo.acceptSuggestionOnCommitCharacter, - snippetSuggestions: opts.contribInfo.snippetSuggestions, wordBasedSuggestions: opts.contribInfo.wordBasedSuggestions, suggestSelection: opts.contribInfo.suggestSelection, suggestFontSize: opts.contribInfo.suggestFontSize, @@ -2466,13 +2464,13 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { suggestOnTriggerCharacters: true, acceptSuggestionOnEnter: 'on', acceptSuggestionOnCommitCharacter: true, - snippetSuggestions: 'inline', wordBasedSuggestions: true, suggestSelection: 'recentlyUsed', suggestFontSize: 0, suggestLineHeight: 0, suggest: { filterGraceful: true, + snippets: 'inline' }, selectionHighlight: true, occurrencesHighlight: true, diff --git a/src/vs/editor/contrib/suggest/completionModel.ts b/src/vs/editor/contrib/suggest/completionModel.ts index 001d7db3a39c79c4b1b9ab97f053ab9c261abe65..d67493343bf58de085d640457a03345eba42f318 100644 --- a/src/vs/editor/contrib/suggest/completionModel.ts +++ b/src/vs/editor/contrib/suggest/completionModel.ts @@ -8,8 +8,8 @@ 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 { ISuggestionItem, SnippetConfig } from './suggest'; -import { ISuggestOptions } from 'vs/editor/common/config/editorOptions'; +import { ISuggestionItem } from './suggest'; +import { InternalSuggestOptions } from 'vs/editor/common/config/editorOptions'; export interface ICompletionItem extends ISuggestionItem { matches?: number[]; @@ -49,7 +49,7 @@ export class CompletionModel { private readonly _items: ICompletionItem[]; private readonly _column: number; - private readonly _options: ISuggestOptions; + private readonly _options: InternalSuggestOptions; private readonly _snippetCompareFn = CompletionModel._compareCompletionItems; private _lineContext: LineContext; @@ -58,16 +58,16 @@ export class CompletionModel { private _isIncomplete: Set; private _stats: ICompletionStats; - constructor(items: ISuggestionItem[], column: number, lineContext: LineContext, options: ISuggestOptions = { filterGraceful: true }, snippetConfig?: SnippetConfig) { + constructor(items: ISuggestionItem[], column: number, lineContext: LineContext, options: InternalSuggestOptions = { filterGraceful: true, snippets: 'inline' }) { this._items = items; this._column = column; this._options = options; this._refilterKind = Refilter.All; this._lineContext = lineContext; - if (snippetConfig === 'top') { + if (options.snippets === 'top') { this._snippetCompareFn = CompletionModel._compareCompletionItemsSnippetsUp; - } else if (snippetConfig === 'bottom') { + } else if (options.snippets === 'bottom') { this._snippetCompareFn = CompletionModel._compareCompletionItemsSnippetsDown; } } diff --git a/src/vs/editor/contrib/suggest/suggestModel.ts b/src/vs/editor/contrib/suggest/suggestModel.ts index add378be47cc6bb68882016a35b0c3f56d0f56ea..d95f90c5e8aaeefe0be440a7254d848098c5a46d 100644 --- a/src/vs/editor/contrib/suggest/suggestModel.ts +++ b/src/vs/editor/contrib/suggest/suggestModel.ts @@ -357,7 +357,7 @@ export class SuggestModel implements IDisposable { } this._requestPromise = provideSuggestionItems(model, this._editor.getPosition(), - this._editor.getConfiguration().contribInfo.snippetSuggestions, + this._editor.getConfiguration().contribInfo.suggest.snippets, onlyFrom, suggestCtx ).then(items => { @@ -372,7 +372,7 @@ export class SuggestModel implements IDisposable { } if (!isFalsyOrEmpty(existingItems)) { - const cmpFn = getSuggestionComparator(this._editor.getConfiguration().contribInfo.snippetSuggestions); + const cmpFn = getSuggestionComparator(this._editor.getConfiguration().contribInfo.suggest.snippets); items = items.concat(existingItems).sort(cmpFn); } @@ -382,8 +382,7 @@ export class SuggestModel implements IDisposable { leadingLineContent: ctx.leadingLineContent, characterCountDelta: this._context ? ctx.column - this._context.column : 0 }, - this._editor.getConfiguration().contribInfo.suggest, - this._editor.getConfiguration().contribInfo.snippetSuggestions + this._editor.getConfiguration().contribInfo.suggest ); this._onNewContext(ctx); diff --git a/src/vs/editor/contrib/suggest/test/completionModel.test.ts b/src/vs/editor/contrib/suggest/test/completionModel.test.ts index 0af0f138093bf4248de071cbc85121a05c429f03..2786aef089af97a456c12893857aba3fa7807da0 100644 --- a/src/vs/editor/contrib/suggest/test/completionModel.test.ts +++ b/src/vs/editor/contrib/suggest/test/completionModel.test.ts @@ -167,7 +167,7 @@ suite('CompletionModel', function () { ], 1, { leadingLineContent: 's', characterCountDelta: 0 - }, undefined, 'top'); + }, { snippets: 'top', filterGraceful: true }); assert.equal(model.items.length, 2); const [a, b] = model.items; @@ -186,7 +186,7 @@ suite('CompletionModel', function () { ], 1, { leadingLineContent: 's', characterCountDelta: 0 - }, undefined, 'bottom'); + }, { snippets: 'bottom', filterGraceful: true }); assert.equal(model.items.length, 2); const [a, b] = model.items; @@ -204,7 +204,7 @@ suite('CompletionModel', function () { ], 1, { leadingLineContent: 's', characterCountDelta: 0 - }, undefined, 'inline'); + }, { snippets: 'inline', filterGraceful: true }); assert.equal(model.items.length, 2); const [a, b] = model.items; @@ -267,7 +267,7 @@ suite('CompletionModel', function () { ], 1, { leadingLineContent: '', characterCountDelta: 0 - }, undefined, 'inline'); + }); assert.equal(model.items.length, 5); @@ -294,7 +294,7 @@ suite('CompletionModel', function () { ], 1, { leadingLineContent: '', characterCountDelta: 0 - }, undefined, 'inline'); + }); // query gets longer, narrow down the narrow-down'ed-set from before model.lineContext = { leadingLineContent: 'rlut', characterCountDelta: 4 }; @@ -316,7 +316,7 @@ suite('CompletionModel', function () { ], 1, { leadingLineContent: '', characterCountDelta: 0 - }, undefined, 'inline'); + }); model.lineContext = { leadingLineContent: 'form', characterCountDelta: 4 }; assert.equal(model.items.length, 5); diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 5a45978929ff37eecba7d18da2f060e9823aec8f..ff51d53c184faceae0b19242e91dbb44e415eee9 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3123,6 +3123,7 @@ declare namespace monaco.editor { export interface InternalSuggestOptions { readonly filterGraceful: boolean; + readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; } export interface EditorWrappingInfo { @@ -3196,7 +3197,6 @@ declare namespace monaco.editor { readonly suggestOnTriggerCharacters: boolean; readonly acceptSuggestionOnEnter: 'on' | 'smart' | 'off'; readonly acceptSuggestionOnCommitCharacter: boolean; - readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none'; readonly wordBasedSuggestions: boolean; readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'; readonly suggestFontSize: number;