mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-21 03:36:14 +01:00
Merge pull request #63193 from skprabhanjan/fix-62365
Fix #62365 : Added useGlobalStorageForSuggestions Setting
This commit is contained in:
@@ -639,6 +639,11 @@ const editorConfiguration: IConfigurationNode = {
|
||||
default: false,
|
||||
description: nls.localize('suggest.localityBonus', "Controls whether sorting favours words that appear close to the cursor.")
|
||||
},
|
||||
'editor.suggest.useGlobalStorageForSuggestions': {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: nls.localize('suggest.useGlobalStorageForSuggestions', "Controls whether global storage is used for remembering suggestions.")
|
||||
},
|
||||
'editor.suggest.snippetsPreventQuickSuggestions': {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
|
||||
@@ -194,6 +194,11 @@ export interface ISuggestOptions {
|
||||
* Favours words that appear close to the cursor.
|
||||
*/
|
||||
localityBonus?: boolean;
|
||||
|
||||
/**
|
||||
* Enable using global storage for remembering suggestions.
|
||||
*/
|
||||
useGlobalStorageForSuggestions?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -900,6 +905,7 @@ export interface InternalSuggestOptions {
|
||||
readonly snippets: 'top' | 'bottom' | 'inline' | 'none';
|
||||
readonly snippetsPreventQuickSuggestions: boolean;
|
||||
readonly localityBonus: boolean;
|
||||
readonly useGlobalStorageForSuggestions: boolean;
|
||||
}
|
||||
|
||||
export interface InternalParameterHintOptions {
|
||||
@@ -1346,7 +1352,8 @@ export class InternalEditorOptions {
|
||||
return a.filterGraceful === b.filterGraceful
|
||||
&& a.snippets === b.snippets
|
||||
&& a.snippetsPreventQuickSuggestions === b.snippetsPreventQuickSuggestions
|
||||
&& a.localityBonus === b.localityBonus;
|
||||
&& a.localityBonus === b.localityBonus
|
||||
&& a.useGlobalStorageForSuggestions === b.useGlobalStorageForSuggestions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1877,6 +1884,7 @@ export class EditorOptionsValidator {
|
||||
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),
|
||||
useGlobalStorageForSuggestions: _boolean(suggestOpts.useGlobalStorageForSuggestions, defaults.useGlobalStorageForSuggestions)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2625,7 +2633,8 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
|
||||
filterGraceful: true,
|
||||
snippets: 'inline',
|
||||
snippetsPreventQuickSuggestions: true,
|
||||
localityBonus: false
|
||||
localityBonus: false,
|
||||
useGlobalStorageForSuggestions: false
|
||||
},
|
||||
selectionHighlight: true,
|
||||
occurrencesHighlight: true,
|
||||
|
||||
@@ -206,12 +206,12 @@ export class SuggestMemories extends Disposable {
|
||||
) {
|
||||
super();
|
||||
|
||||
this._setMode(editor.getConfiguration().contribInfo.suggestSelection);
|
||||
this._register(editor.onDidChangeConfiguration(e => e.contribInfo && this._setMode(editor.getConfiguration().contribInfo.suggestSelection)));
|
||||
this._register(_storageService.onWillSaveState(() => this._saveState()));
|
||||
this._setMode(editor.getConfiguration().contribInfo.suggestSelection, editor.getConfiguration().contribInfo.suggest.useGlobalStorageForSuggestions);
|
||||
this._register(editor.onDidChangeConfiguration(e => e.contribInfo && this._setMode(editor.getConfiguration().contribInfo.suggestSelection, editor.getConfiguration().contribInfo.suggest.useGlobalStorageForSuggestions)));
|
||||
this._register(_storageService.onWillSaveState(() => this._saveState(editor.getConfiguration().contribInfo.suggest.useGlobalStorageForSuggestions)));
|
||||
}
|
||||
|
||||
private _setMode(mode: MemMode): void {
|
||||
private _setMode(mode: MemMode, useGlobalStorageForSuggestions: boolean): void {
|
||||
if (this._mode === mode) {
|
||||
return;
|
||||
}
|
||||
@@ -219,7 +219,7 @@ export class SuggestMemories extends Disposable {
|
||||
this._strategy = mode === 'recentlyUsedByPrefix' ? new PrefixMemory() : mode === 'recentlyUsed' ? new LRUMemory() : new NoMemory();
|
||||
|
||||
try {
|
||||
const raw = this._storageService.get(`${this._storagePrefix}/${this._mode}`, StorageScope.WORKSPACE);
|
||||
const raw = useGlobalStorageForSuggestions ? this._storageService.get(`${this._storagePrefix}/${this._mode}`, StorageScope.GLOBAL) : this._storageService.get(`${this._storagePrefix}/${this._mode}`, StorageScope.WORKSPACE);
|
||||
if (raw) {
|
||||
this._strategy.fromJSON(JSON.parse(raw));
|
||||
}
|
||||
@@ -236,8 +236,8 @@ export class SuggestMemories extends Disposable {
|
||||
return this._strategy.select(model, pos, items);
|
||||
}
|
||||
|
||||
private _saveState() {
|
||||
private _saveState(useGlobalStorageForSuggestions: boolean) {
|
||||
const raw = JSON.stringify(this._strategy);
|
||||
this._storageService.store(`${this._storagePrefix}/${this._mode}`, raw, StorageScope.WORKSPACE);
|
||||
useGlobalStorageForSuggestions ? this._storageService.store(`${this._storagePrefix}/${this._mode}`, raw, StorageScope.GLOBAL) : this._storageService.store(`${this._storagePrefix}/${this._mode}`, raw, StorageScope.WORKSPACE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: 's',
|
||||
characterCountDelta: 0
|
||||
}, WordDistance.None, { snippets: 'top', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false });
|
||||
}, WordDistance.None, { snippets: 'top', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false, useGlobalStorageForSuggestions: false });
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
const [a, b] = model.items;
|
||||
@@ -184,7 +184,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: 's',
|
||||
characterCountDelta: 0
|
||||
}, WordDistance.None, { snippets: 'bottom', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false });
|
||||
}, WordDistance.None, { snippets: 'bottom', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false, useGlobalStorageForSuggestions: false });
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
const [a, b] = model.items;
|
||||
@@ -202,7 +202,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: 's',
|
||||
characterCountDelta: 0
|
||||
}, WordDistance.None, { snippets: 'inline', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false });
|
||||
}, WordDistance.None, { snippets: 'inline', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false, useGlobalStorageForSuggestions: false });
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
const [a, b] = model.items;
|
||||
|
||||
Vendored
+5
@@ -2558,6 +2558,10 @@ declare namespace monaco.editor {
|
||||
* Favours words that appear close to the cursor.
|
||||
*/
|
||||
localityBonus?: boolean;
|
||||
/**
|
||||
* Enable using global storage for remembering suggestions.
|
||||
*/
|
||||
useGlobalStorageForSuggestions?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3193,6 +3197,7 @@ declare namespace monaco.editor {
|
||||
readonly snippets: 'top' | 'bottom' | 'inline' | 'none';
|
||||
readonly snippetsPreventQuickSuggestions: boolean;
|
||||
readonly localityBonus: boolean;
|
||||
readonly useGlobalStorageForSuggestions: boolean;
|
||||
}
|
||||
|
||||
export interface InternalParameterHintOptions {
|
||||
|
||||
Reference in New Issue
Block a user