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

add locality bonus setting

上级 ff97e6a9
...@@ -636,6 +636,11 @@ const editorConfiguration: IConfigurationNode = { ...@@ -636,6 +636,11 @@ const editorConfiguration: IConfigurationNode = {
default: true, default: true,
description: nls.localize('suggest.filterGraceful', "Controls whether filtering and sorting suggestions accounts for small typos.") description: nls.localize('suggest.filterGraceful', "Controls whether filtering and sorting suggestions accounts for small typos.")
}, },
'editor.suggest.localityBonus': {
type: 'boolean',
default: false,
description: nls.localize('suggest.localityBonus', "Controls whether sorting favours words that appear close to the cursor.")
},
'editor.suggest.snippetsPreventQuickSuggestions': { 'editor.suggest.snippetsPreventQuickSuggestions': {
type: 'boolean', type: 'boolean',
default: true, default: true,
......
...@@ -193,6 +193,10 @@ export interface ISuggestOptions { ...@@ -193,6 +193,10 @@ export interface ISuggestOptions {
* Prevent quick suggestions when a snippet is active. Defaults to true. * Prevent quick suggestions when a snippet is active. Defaults to true.
*/ */
snippetsPreventQuickSuggestions?: boolean; snippetsPreventQuickSuggestions?: boolean;
/**
* Favours words that appear close to the cursor.
*/
localityBonus?: boolean;
} }
/** /**
...@@ -893,6 +897,7 @@ export interface InternalSuggestOptions { ...@@ -893,6 +897,7 @@ export interface InternalSuggestOptions {
readonly filterGraceful: boolean; readonly filterGraceful: boolean;
readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; readonly snippets: 'top' | 'bottom' | 'inline' | 'none';
readonly snippetsPreventQuickSuggestions: boolean; readonly snippetsPreventQuickSuggestions: boolean;
readonly localityBonus: boolean;
} }
export interface InternalParameterHintOptions { export interface InternalParameterHintOptions {
...@@ -1336,7 +1341,8 @@ export class InternalEditorOptions { ...@@ -1336,7 +1341,8 @@ export class InternalEditorOptions {
} else { } else {
return a.filterGraceful === b.filterGraceful return a.filterGraceful === b.filterGraceful
&& a.snippets === b.snippets && a.snippets === b.snippets
&& a.snippetsPreventQuickSuggestions === b.snippetsPreventQuickSuggestions; && a.snippetsPreventQuickSuggestions === b.snippetsPreventQuickSuggestions
&& a.localityBonus === b.localityBonus;
} }
} }
...@@ -1866,6 +1872,7 @@ export class EditorOptionsValidator { ...@@ -1866,6 +1872,7 @@ export class EditorOptionsValidator {
filterGraceful: _boolean(suggestOpts.filterGraceful, defaults.filterGraceful), filterGraceful: _boolean(suggestOpts.filterGraceful, defaults.filterGraceful),
snippets: _stringSet<'top' | 'bottom' | 'inline' | 'none'>(opts.snippetSuggestions, defaults.snippets, ['top', 'bottom', 'inline', 'none']), snippets: _stringSet<'top' | 'bottom' | 'inline' | 'none'>(opts.snippetSuggestions, defaults.snippets, ['top', 'bottom', 'inline', 'none']),
snippetsPreventQuickSuggestions: _boolean(suggestOpts.snippetsPreventQuickSuggestions, defaults.filterGraceful), snippetsPreventQuickSuggestions: _boolean(suggestOpts.snippetsPreventQuickSuggestions, defaults.filterGraceful),
localityBonus: _boolean(suggestOpts.localityBonus, defaults.localityBonus),
}; };
} }
...@@ -2610,7 +2617,8 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { ...@@ -2610,7 +2617,8 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
suggest: { suggest: {
filterGraceful: true, filterGraceful: true,
snippets: 'inline', snippets: 'inline',
snippetsPreventQuickSuggestions: true snippetsPreventQuickSuggestions: true,
localityBonus: false
}, },
selectionHighlight: true, selectionHighlight: true,
occurrencesHighlight: true, occurrencesHighlight: true,
......
...@@ -168,7 +168,7 @@ suite('CompletionModel', function () { ...@@ -168,7 +168,7 @@ suite('CompletionModel', function () {
], 1, { ], 1, {
leadingLineContent: 's', leadingLineContent: 's',
characterCountDelta: 0 characterCountDelta: 0
}, WordDistance.None, { snippets: 'top', snippetsPreventQuickSuggestions: true, filterGraceful: true }); }, WordDistance.None, { snippets: 'top', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false });
assert.equal(model.items.length, 2); assert.equal(model.items.length, 2);
const [a, b] = model.items; const [a, b] = model.items;
...@@ -187,7 +187,7 @@ suite('CompletionModel', function () { ...@@ -187,7 +187,7 @@ suite('CompletionModel', function () {
], 1, { ], 1, {
leadingLineContent: 's', leadingLineContent: 's',
characterCountDelta: 0 characterCountDelta: 0
}, WordDistance.None, { snippets: 'bottom', snippetsPreventQuickSuggestions: true, filterGraceful: true }); }, WordDistance.None, { snippets: 'bottom', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false });
assert.equal(model.items.length, 2); assert.equal(model.items.length, 2);
const [a, b] = model.items; const [a, b] = model.items;
...@@ -205,7 +205,7 @@ suite('CompletionModel', function () { ...@@ -205,7 +205,7 @@ suite('CompletionModel', function () {
], 1, { ], 1, {
leadingLineContent: 's', leadingLineContent: 's',
characterCountDelta: 0 characterCountDelta: 0
}, WordDistance.None, { snippets: 'inline', snippetsPreventQuickSuggestions: true, filterGraceful: true }); }, WordDistance.None, { snippets: 'inline', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false });
assert.equal(model.items.length, 2); assert.equal(model.items.length, 2);
const [a, b] = model.items; const [a, b] = model.items;
......
...@@ -20,6 +20,10 @@ export abstract class WordDistance { ...@@ -20,6 +20,10 @@ export abstract class WordDistance {
static create(service: IEditorWorkerService, editor: ICodeEditor): Thenable<WordDistance> { static create(service: IEditorWorkerService, editor: ICodeEditor): Thenable<WordDistance> {
if (!editor.getConfiguration().contribInfo.suggest.localityBonus) {
return Promise.resolve(WordDistance.None);
}
const model = editor.getModel(); const model = editor.getModel();
const position = editor.getPosition(); const position = editor.getPosition();
const range = new Range(Math.max(1, position.lineNumber - 100), 1, Math.min(model.getLineCount() - 1, position.lineNumber + 100), 1); const range = new Range(Math.max(1, position.lineNumber - 100), 1, Math.min(model.getLineCount() - 1, position.lineNumber + 100), 1);
......
...@@ -2540,6 +2540,10 @@ declare namespace monaco.editor { ...@@ -2540,6 +2540,10 @@ declare namespace monaco.editor {
* Prevent quick suggestions when a snippet is active. Defaults to true. * Prevent quick suggestions when a snippet is active. Defaults to true.
*/ */
snippetsPreventQuickSuggestions?: boolean; snippetsPreventQuickSuggestions?: boolean;
/**
* Favours words that appear close to the cursor.
*/
localityBonus?: boolean;
} }
/** /**
...@@ -3169,6 +3173,7 @@ declare namespace monaco.editor { ...@@ -3169,6 +3173,7 @@ declare namespace monaco.editor {
readonly filterGraceful: boolean; readonly filterGraceful: boolean;
readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; readonly snippets: 'top' | 'bottom' | 'inline' | 'none';
readonly snippetsPreventQuickSuggestions: boolean; readonly snippetsPreventQuickSuggestions: boolean;
readonly localityBonus: boolean;
} }
export interface InternalParameterHintOptions { export interface InternalParameterHintOptions {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册