diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index edb0514d0c6de63940a868940783288d10d64fba..83482c51c63432e4da6cf8e11253e1e0f98ebb91 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -636,6 +636,11 @@ const editorConfiguration: IConfigurationNode = { default: true, 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': { type: 'boolean', default: true, diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 610d6e0bdf4fe55263eeba1603f6b2da696f5a8f..dd5100ba8793530aceb43711de4c63c2d9c11ba7 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -193,6 +193,10 @@ export interface ISuggestOptions { * Prevent quick suggestions when a snippet is active. Defaults to true. */ snippetsPreventQuickSuggestions?: boolean; + /** + * Favours words that appear close to the cursor. + */ + localityBonus?: boolean; } /** @@ -893,6 +897,7 @@ export interface InternalSuggestOptions { readonly filterGraceful: boolean; readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; readonly snippetsPreventQuickSuggestions: boolean; + readonly localityBonus: boolean; } export interface InternalParameterHintOptions { @@ -1336,7 +1341,8 @@ export class InternalEditorOptions { } else { return a.filterGraceful === b.filterGraceful && a.snippets === b.snippets - && a.snippetsPreventQuickSuggestions === b.snippetsPreventQuickSuggestions; + && a.snippetsPreventQuickSuggestions === b.snippetsPreventQuickSuggestions + && a.localityBonus === b.localityBonus; } } @@ -1866,6 +1872,7 @@ export class EditorOptionsValidator { filterGraceful: _boolean(suggestOpts.filterGraceful, defaults.filterGraceful), snippets: _stringSet<'top' | 'bottom' | 'inline' | 'none'>(opts.snippetSuggestions, defaults.snippets, ['top', 'bottom', 'inline', 'none']), snippetsPreventQuickSuggestions: _boolean(suggestOpts.snippetsPreventQuickSuggestions, defaults.filterGraceful), + localityBonus: _boolean(suggestOpts.localityBonus, defaults.localityBonus), }; } @@ -2610,7 +2617,8 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { suggest: { filterGraceful: true, snippets: 'inline', - snippetsPreventQuickSuggestions: true + snippetsPreventQuickSuggestions: true, + localityBonus: false }, selectionHighlight: true, occurrencesHighlight: true, diff --git a/src/vs/editor/contrib/suggest/test/completionModel.test.ts b/src/vs/editor/contrib/suggest/test/completionModel.test.ts index 2cb0ce9cc75f77b1f9c025e6c1175c1bd42c53f0..f7ccbd51b1abc8ca5ba57fba574a94718455734b 100644 --- a/src/vs/editor/contrib/suggest/test/completionModel.test.ts +++ b/src/vs/editor/contrib/suggest/test/completionModel.test.ts @@ -168,7 +168,7 @@ suite('CompletionModel', function () { ], 1, { leadingLineContent: 's', 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); const [a, b] = model.items; @@ -187,7 +187,7 @@ suite('CompletionModel', function () { ], 1, { leadingLineContent: 's', 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); const [a, b] = model.items; @@ -205,7 +205,7 @@ suite('CompletionModel', function () { ], 1, { leadingLineContent: 's', 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); const [a, b] = model.items; diff --git a/src/vs/editor/contrib/suggest/wordDistance.ts b/src/vs/editor/contrib/suggest/wordDistance.ts index 514fde28db31dc2fa4a999d661193faa5fcc81dd..3d0f430c14dff6d3c20131efec4e1cf057d83ba3 100644 --- a/src/vs/editor/contrib/suggest/wordDistance.ts +++ b/src/vs/editor/contrib/suggest/wordDistance.ts @@ -20,6 +20,10 @@ export abstract class WordDistance { static create(service: IEditorWorkerService, editor: ICodeEditor): Thenable { + if (!editor.getConfiguration().contribInfo.suggest.localityBonus) { + return Promise.resolve(WordDistance.None); + } + const model = editor.getModel(); const position = editor.getPosition(); const range = new Range(Math.max(1, position.lineNumber - 100), 1, Math.min(model.getLineCount() - 1, position.lineNumber + 100), 1); diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index d0451a54ca8533572d608cf5eab47945fb547107..d2f85c3b0e4d201d939d67fdfc04e2eafedf6091 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2540,6 +2540,10 @@ declare namespace monaco.editor { * Prevent quick suggestions when a snippet is active. Defaults to true. */ snippetsPreventQuickSuggestions?: boolean; + /** + * Favours words that appear close to the cursor. + */ + localityBonus?: boolean; } /** @@ -3169,6 +3173,7 @@ declare namespace monaco.editor { readonly filterGraceful: boolean; readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; readonly snippetsPreventQuickSuggestions: boolean; + readonly localityBonus: boolean; } export interface InternalParameterHintOptions {