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

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

上级 1ea92bed
......@@ -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': {
......
......@@ -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,
......
......@@ -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<ISuggestSupport>;
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;
}
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册