提交 7a8040ad 编写于 作者: J Johannes Rieken

move snippet-suggest option to new internal model, #42750

上级 1ea92bed
...@@ -532,7 +532,7 @@ const editorConfiguration: IConfigurationNode = { ...@@ -532,7 +532,7 @@ const editorConfiguration: IConfigurationNode = {
nls.localize('snippetSuggestions.inline', "Show snippets suggestions with other suggestions."), nls.localize('snippetSuggestions.inline', "Show snippets suggestions with other suggestions."),
nls.localize('snippetSuggestions.none', "Do not show snippet 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.") 'description': nls.localize('snippetSuggestions', "Controls whether snippets are shown with other suggestions and how they are sorted.")
}, },
'editor.emptySelectionClipboard': { 'editor.emptySelectionClipboard': {
......
...@@ -843,6 +843,7 @@ export interface InternalEditorHoverOptions { ...@@ -843,6 +843,7 @@ export interface InternalEditorHoverOptions {
export interface InternalSuggestOptions { export interface InternalSuggestOptions {
readonly filterGraceful: boolean; readonly filterGraceful: boolean;
readonly snippets: 'top' | 'bottom' | 'inline' | 'none';
} }
export interface EditorWrappingInfo { export interface EditorWrappingInfo {
...@@ -912,7 +913,7 @@ export interface EditorContribOptions { ...@@ -912,7 +913,7 @@ export interface EditorContribOptions {
readonly suggestOnTriggerCharacters: boolean; readonly suggestOnTriggerCharacters: boolean;
readonly acceptSuggestionOnEnter: 'on' | 'smart' | 'off'; readonly acceptSuggestionOnEnter: 'on' | 'smart' | 'off';
readonly acceptSuggestionOnCommitCharacter: boolean; readonly acceptSuggestionOnCommitCharacter: boolean;
readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none'; // readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
readonly wordBasedSuggestions: boolean; readonly wordBasedSuggestions: boolean;
readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'; readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix';
readonly suggestFontSize: number; readonly suggestFontSize: number;
...@@ -1245,13 +1246,13 @@ export class InternalEditorOptions { ...@@ -1245,13 +1246,13 @@ export class InternalEditorOptions {
/** /**
* @internal * @internal
*/ */
private static _equalsSuggestOptions(a: ISuggestOptions, b: ISuggestOptions): any { private static _equalsSuggestOptions(a: InternalSuggestOptions, b: InternalSuggestOptions): any {
if (a === b) { if (a === b) {
return true; return true;
} else if (!a || !b) { } else if (!a || !b) {
return false; return false;
} else { } else {
return a.filterGraceful === b.filterGraceful; return a.filterGraceful === b.filterGraceful && a.snippets === b.snippets;
} }
} }
...@@ -1290,7 +1291,6 @@ export class InternalEditorOptions { ...@@ -1290,7 +1291,6 @@ export class InternalEditorOptions {
&& a.suggestOnTriggerCharacters === b.suggestOnTriggerCharacters && a.suggestOnTriggerCharacters === b.suggestOnTriggerCharacters
&& a.acceptSuggestionOnEnter === b.acceptSuggestionOnEnter && a.acceptSuggestionOnEnter === b.acceptSuggestionOnEnter
&& a.acceptSuggestionOnCommitCharacter === b.acceptSuggestionOnCommitCharacter && a.acceptSuggestionOnCommitCharacter === b.acceptSuggestionOnCommitCharacter
&& a.snippetSuggestions === b.snippetSuggestions
&& a.wordBasedSuggestions === b.wordBasedSuggestions && a.wordBasedSuggestions === b.wordBasedSuggestions
&& a.suggestSelection === b.suggestSelection && a.suggestSelection === b.suggestSelection
&& a.suggestFontSize === b.suggestFontSize && a.suggestFontSize === b.suggestFontSize
...@@ -1744,13 +1744,13 @@ export class EditorOptionsValidator { ...@@ -1744,13 +1744,13 @@ export class EditorOptionsValidator {
}; };
} }
private static _sanitizeSuggestOpts(opts: ISuggestOptions, defaults: InternalSuggestOptions): InternalSuggestOptions { private static _sanitizeSuggestOpts(opts: IEditorOptions, defaults: InternalSuggestOptions): InternalSuggestOptions {
if (!opts) { if (!opts.suggest) {
return defaults; return defaults;
} }
let { filterGraceful } = opts;
return { 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 { ...@@ -1885,12 +1885,11 @@ export class EditorOptionsValidator {
suggestOnTriggerCharacters: _boolean(opts.suggestOnTriggerCharacters, defaults.suggestOnTriggerCharacters), suggestOnTriggerCharacters: _boolean(opts.suggestOnTriggerCharacters, defaults.suggestOnTriggerCharacters),
acceptSuggestionOnEnter: _stringSet<'on' | 'smart' | 'off'>(opts.acceptSuggestionOnEnter, defaults.acceptSuggestionOnEnter, ['on', 'smart', 'off']), acceptSuggestionOnEnter: _stringSet<'on' | 'smart' | 'off'>(opts.acceptSuggestionOnEnter, defaults.acceptSuggestionOnEnter, ['on', 'smart', 'off']),
acceptSuggestionOnCommitCharacter: _boolean(opts.acceptSuggestionOnCommitCharacter, defaults.acceptSuggestionOnCommitCharacter), 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), wordBasedSuggestions: _boolean(opts.wordBasedSuggestions, defaults.wordBasedSuggestions),
suggestSelection: _stringSet<'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'>(opts.suggestSelection, defaults.suggestSelection, ['first', 'recentlyUsed', 'recentlyUsedByPrefix']), suggestSelection: _stringSet<'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'>(opts.suggestSelection, defaults.suggestSelection, ['first', 'recentlyUsed', 'recentlyUsedByPrefix']),
suggestFontSize: _clampedInt(opts.suggestFontSize, defaults.suggestFontSize, 0, 1000), suggestFontSize: _clampedInt(opts.suggestFontSize, defaults.suggestFontSize, 0, 1000),
suggestLineHeight: _clampedInt(opts.suggestLineHeight, defaults.suggestLineHeight, 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), selectionHighlight: _boolean(opts.selectionHighlight, defaults.selectionHighlight),
occurrencesHighlight: _boolean(opts.occurrencesHighlight, defaults.occurrencesHighlight), occurrencesHighlight: _boolean(opts.occurrencesHighlight, defaults.occurrencesHighlight),
codeLens: _boolean(opts.codeLens, defaults.codeLens), codeLens: _boolean(opts.codeLens, defaults.codeLens),
...@@ -1994,7 +1993,6 @@ export class InternalEditorOptionsFactory { ...@@ -1994,7 +1993,6 @@ export class InternalEditorOptionsFactory {
suggestOnTriggerCharacters: opts.contribInfo.suggestOnTriggerCharacters, suggestOnTriggerCharacters: opts.contribInfo.suggestOnTriggerCharacters,
acceptSuggestionOnEnter: opts.contribInfo.acceptSuggestionOnEnter, acceptSuggestionOnEnter: opts.contribInfo.acceptSuggestionOnEnter,
acceptSuggestionOnCommitCharacter: opts.contribInfo.acceptSuggestionOnCommitCharacter, acceptSuggestionOnCommitCharacter: opts.contribInfo.acceptSuggestionOnCommitCharacter,
snippetSuggestions: opts.contribInfo.snippetSuggestions,
wordBasedSuggestions: opts.contribInfo.wordBasedSuggestions, wordBasedSuggestions: opts.contribInfo.wordBasedSuggestions,
suggestSelection: opts.contribInfo.suggestSelection, suggestSelection: opts.contribInfo.suggestSelection,
suggestFontSize: opts.contribInfo.suggestFontSize, suggestFontSize: opts.contribInfo.suggestFontSize,
...@@ -2466,13 +2464,13 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { ...@@ -2466,13 +2464,13 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
suggestOnTriggerCharacters: true, suggestOnTriggerCharacters: true,
acceptSuggestionOnEnter: 'on', acceptSuggestionOnEnter: 'on',
acceptSuggestionOnCommitCharacter: true, acceptSuggestionOnCommitCharacter: true,
snippetSuggestions: 'inline',
wordBasedSuggestions: true, wordBasedSuggestions: true,
suggestSelection: 'recentlyUsed', suggestSelection: 'recentlyUsed',
suggestFontSize: 0, suggestFontSize: 0,
suggestLineHeight: 0, suggestLineHeight: 0,
suggest: { suggest: {
filterGraceful: true, filterGraceful: true,
snippets: 'inline'
}, },
selectionHighlight: true, selectionHighlight: true,
occurrencesHighlight: true, occurrencesHighlight: true,
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
import { fuzzyScore, fuzzyScoreGracefulAggressive, anyScore } from 'vs/base/common/filters'; import { fuzzyScore, fuzzyScoreGracefulAggressive, anyScore } from 'vs/base/common/filters';
import { isDisposable } from 'vs/base/common/lifecycle'; import { isDisposable } from 'vs/base/common/lifecycle';
import { ISuggestResult, ISuggestSupport } from 'vs/editor/common/modes'; import { ISuggestResult, ISuggestSupport } from 'vs/editor/common/modes';
import { ISuggestionItem, SnippetConfig } from './suggest'; import { ISuggestionItem } from './suggest';
import { ISuggestOptions } from 'vs/editor/common/config/editorOptions'; import { InternalSuggestOptions } from 'vs/editor/common/config/editorOptions';
export interface ICompletionItem extends ISuggestionItem { export interface ICompletionItem extends ISuggestionItem {
matches?: number[]; matches?: number[];
...@@ -49,7 +49,7 @@ export class CompletionModel { ...@@ -49,7 +49,7 @@ export class CompletionModel {
private readonly _items: ICompletionItem[]; private readonly _items: ICompletionItem[];
private readonly _column: number; private readonly _column: number;
private readonly _options: ISuggestOptions; private readonly _options: InternalSuggestOptions;
private readonly _snippetCompareFn = CompletionModel._compareCompletionItems; private readonly _snippetCompareFn = CompletionModel._compareCompletionItems;
private _lineContext: LineContext; private _lineContext: LineContext;
...@@ -58,16 +58,16 @@ export class CompletionModel { ...@@ -58,16 +58,16 @@ export class CompletionModel {
private _isIncomplete: Set<ISuggestSupport>; private _isIncomplete: Set<ISuggestSupport>;
private _stats: ICompletionStats; 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._items = items;
this._column = column; this._column = column;
this._options = options; this._options = options;
this._refilterKind = Refilter.All; this._refilterKind = Refilter.All;
this._lineContext = lineContext; this._lineContext = lineContext;
if (snippetConfig === 'top') { if (options.snippets === 'top') {
this._snippetCompareFn = CompletionModel._compareCompletionItemsSnippetsUp; this._snippetCompareFn = CompletionModel._compareCompletionItemsSnippetsUp;
} else if (snippetConfig === 'bottom') { } else if (options.snippets === 'bottom') {
this._snippetCompareFn = CompletionModel._compareCompletionItemsSnippetsDown; this._snippetCompareFn = CompletionModel._compareCompletionItemsSnippetsDown;
} }
} }
......
...@@ -357,7 +357,7 @@ export class SuggestModel implements IDisposable { ...@@ -357,7 +357,7 @@ export class SuggestModel implements IDisposable {
} }
this._requestPromise = provideSuggestionItems(model, this._editor.getPosition(), this._requestPromise = provideSuggestionItems(model, this._editor.getPosition(),
this._editor.getConfiguration().contribInfo.snippetSuggestions, this._editor.getConfiguration().contribInfo.suggest.snippets,
onlyFrom, onlyFrom,
suggestCtx suggestCtx
).then(items => { ).then(items => {
...@@ -372,7 +372,7 @@ export class SuggestModel implements IDisposable { ...@@ -372,7 +372,7 @@ export class SuggestModel implements IDisposable {
} }
if (!isFalsyOrEmpty(existingItems)) { 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); items = items.concat(existingItems).sort(cmpFn);
} }
...@@ -382,8 +382,7 @@ export class SuggestModel implements IDisposable { ...@@ -382,8 +382,7 @@ export class SuggestModel implements IDisposable {
leadingLineContent: ctx.leadingLineContent, leadingLineContent: ctx.leadingLineContent,
characterCountDelta: this._context ? ctx.column - this._context.column : 0 characterCountDelta: this._context ? ctx.column - this._context.column : 0
}, },
this._editor.getConfiguration().contribInfo.suggest, this._editor.getConfiguration().contribInfo.suggest
this._editor.getConfiguration().contribInfo.snippetSuggestions
); );
this._onNewContext(ctx); this._onNewContext(ctx);
......
...@@ -167,7 +167,7 @@ suite('CompletionModel', function () { ...@@ -167,7 +167,7 @@ suite('CompletionModel', function () {
], 1, { ], 1, {
leadingLineContent: 's', leadingLineContent: 's',
characterCountDelta: 0 characterCountDelta: 0
}, undefined, 'top'); }, { snippets: 'top', filterGraceful: true });
assert.equal(model.items.length, 2); assert.equal(model.items.length, 2);
const [a, b] = model.items; const [a, b] = model.items;
...@@ -186,7 +186,7 @@ suite('CompletionModel', function () { ...@@ -186,7 +186,7 @@ suite('CompletionModel', function () {
], 1, { ], 1, {
leadingLineContent: 's', leadingLineContent: 's',
characterCountDelta: 0 characterCountDelta: 0
}, undefined, 'bottom'); }, { snippets: 'bottom', filterGraceful: true });
assert.equal(model.items.length, 2); assert.equal(model.items.length, 2);
const [a, b] = model.items; const [a, b] = model.items;
...@@ -204,7 +204,7 @@ suite('CompletionModel', function () { ...@@ -204,7 +204,7 @@ suite('CompletionModel', function () {
], 1, { ], 1, {
leadingLineContent: 's', leadingLineContent: 's',
characterCountDelta: 0 characterCountDelta: 0
}, undefined, 'inline'); }, { snippets: 'inline', filterGraceful: true });
assert.equal(model.items.length, 2); assert.equal(model.items.length, 2);
const [a, b] = model.items; const [a, b] = model.items;
...@@ -267,7 +267,7 @@ suite('CompletionModel', function () { ...@@ -267,7 +267,7 @@ suite('CompletionModel', function () {
], 1, { ], 1, {
leadingLineContent: '', leadingLineContent: '',
characterCountDelta: 0 characterCountDelta: 0
}, undefined, 'inline'); });
assert.equal(model.items.length, 5); assert.equal(model.items.length, 5);
...@@ -294,7 +294,7 @@ suite('CompletionModel', function () { ...@@ -294,7 +294,7 @@ suite('CompletionModel', function () {
], 1, { ], 1, {
leadingLineContent: '', leadingLineContent: '',
characterCountDelta: 0 characterCountDelta: 0
}, undefined, 'inline'); });
// query gets longer, narrow down the narrow-down'ed-set from before // query gets longer, narrow down the narrow-down'ed-set from before
model.lineContext = { leadingLineContent: 'rlut', characterCountDelta: 4 }; model.lineContext = { leadingLineContent: 'rlut', characterCountDelta: 4 };
...@@ -316,7 +316,7 @@ suite('CompletionModel', function () { ...@@ -316,7 +316,7 @@ suite('CompletionModel', function () {
], 1, { ], 1, {
leadingLineContent: '', leadingLineContent: '',
characterCountDelta: 0 characterCountDelta: 0
}, undefined, 'inline'); });
model.lineContext = { leadingLineContent: 'form', characterCountDelta: 4 }; model.lineContext = { leadingLineContent: 'form', characterCountDelta: 4 };
assert.equal(model.items.length, 5); assert.equal(model.items.length, 5);
......
...@@ -3123,6 +3123,7 @@ declare namespace monaco.editor { ...@@ -3123,6 +3123,7 @@ declare namespace monaco.editor {
export interface InternalSuggestOptions { export interface InternalSuggestOptions {
readonly filterGraceful: boolean; readonly filterGraceful: boolean;
readonly snippets: 'top' | 'bottom' | 'inline' | 'none';
} }
export interface EditorWrappingInfo { export interface EditorWrappingInfo {
...@@ -3196,7 +3197,6 @@ declare namespace monaco.editor { ...@@ -3196,7 +3197,6 @@ declare namespace monaco.editor {
readonly suggestOnTriggerCharacters: boolean; readonly suggestOnTriggerCharacters: boolean;
readonly acceptSuggestionOnEnter: 'on' | 'smart' | 'off'; readonly acceptSuggestionOnEnter: 'on' | 'smart' | 'off';
readonly acceptSuggestionOnCommitCharacter: boolean; readonly acceptSuggestionOnCommitCharacter: boolean;
readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
readonly wordBasedSuggestions: boolean; readonly wordBasedSuggestions: boolean;
readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'; readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix';
readonly suggestFontSize: number; readonly suggestFontSize: number;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册