Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -2,13 +2,15 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { ICompletionItem } from 'vs/editor/contrib/suggest/completionModel';
import { LRUCache, TernarySearchTree } from 'vs/base/common/map';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ITextModel } from 'vs/editor/common/model';
import { IPosition } from 'vs/editor/common/core/position';
import { CompletionItemKind, completionKindFromLegacyString } from 'vs/editor/common/modes';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { Disposable } from 'vs/base/common/lifecycle';
import { RunOnceScheduler } from 'vs/base/common/async';
export abstract class Memory {
@@ -55,7 +57,7 @@ export class NoMemory extends Memory {
}
export interface MemItem {
type: string;
type: string | CompletionItemKind;
insertText: string;
touch: number;
}
@@ -70,7 +72,7 @@ export class LRUMemory extends Memory {
const key = `${model.getLanguageIdentifier().language}/${label}`;
this._cache.set(key, {
touch: this._seq++,
type: item.suggestion.type,
type: item.suggestion.kind,
insertText: item.suggestion.insertText
});
}
@@ -94,7 +96,7 @@ export class LRUMemory extends Memory {
const { suggestion } = items[i];
const key = `${model.getLanguageIdentifier().language}/${suggestion.label}`;
const item = this._cache.get(key);
if (item && item.touch > seq && item.type === suggestion.type && item.insertText === suggestion.insertText) {
if (item && item.touch > seq && item.type === suggestion.kind && item.insertText === suggestion.insertText) {
seq = item.touch;
res = i;
}
@@ -119,6 +121,7 @@ export class LRUMemory extends Memory {
let seq = 0;
for (const [key, value] of data) {
value.touch = seq;
value.type = typeof value.type === 'number' ? value.type : completionKindFromLegacyString(value.type);
this._cache.set(key, value);
}
this._seq = this._cache.size;
@@ -135,7 +138,7 @@ export class PrefixMemory extends Memory {
const { word } = model.getWordUntilPosition(pos);
const key = `${model.getLanguageIdentifier().language}/${word}`;
this._trie.set(key, {
type: item.suggestion.type,
type: item.suggestion.kind,
insertText: item.suggestion.insertText,
touch: this._seq++
});
@@ -153,8 +156,8 @@ export class PrefixMemory extends Memory {
}
if (item) {
for (let i = 0; i < items.length; i++) {
let { type, insertText } = items[i].suggestion;
if (type === item.type && insertText === item.insertText) {
let { kind, insertText } = items[i].suggestion;
if (kind === item.type && insertText === item.insertText) {
return i;
}
}
@@ -182,6 +185,7 @@ export class PrefixMemory extends Memory {
if (data.length > 0) {
this._seq = data[0][1].touch + 1;
for (const [key, value] of data) {
value.type = typeof value.type === 'number' ? value.type : completionKindFromLegacyString(value.type);
this._trie.set(key, value);
}
}
@@ -190,23 +194,27 @@ export class PrefixMemory extends Memory {
export type MemMode = 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix';
export class SuggestMemories {
export class SuggestMemories extends Disposable {
private readonly _storagePrefix = 'suggest/memories';
private _mode: MemMode;
private _strategy: Memory;
private _persistSoon: RunOnceScheduler;
private readonly _persistSoon: RunOnceScheduler;
constructor(
mode: MemMode,
@IStorageService private readonly _storageService: IStorageService
editor: ICodeEditor,
@IStorageService private readonly _storageService: IStorageService,
) {
this._persistSoon = new RunOnceScheduler(() => this._flush(), 3000);
this.setMode(mode);
super();
this._persistSoon = this._register(new RunOnceScheduler(() => this._saveState(editor.getConfiguration().contribInfo.suggest.shareSuggestSelections), 3000));
this._setMode(editor.getConfiguration().contribInfo.suggestSelection, editor.getConfiguration().contribInfo.suggest.shareSuggestSelections);
this._register(editor.onDidChangeConfiguration(e => e.contribInfo && this._setMode(editor.getConfiguration().contribInfo.suggestSelection, editor.getConfiguration().contribInfo.suggest.shareSuggestSelections)));
this._register(_storageService.onWillSaveState(() => this._saveState(editor.getConfiguration().contribInfo.suggest.shareSuggestSelections)));
}
setMode(mode: MemMode): void {
private _setMode(mode: MemMode, useGlobalStorageForSuggestions: boolean): void {
if (this._mode === mode) {
return;
}
@@ -214,7 +222,7 @@ export class SuggestMemories {
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));
}
@@ -232,8 +240,8 @@ export class SuggestMemories {
return this._strategy.select(model, pos, items);
}
private _flush() {
private _saveState(useGlobalStorageForSuggestions: boolean) {
const raw = JSON.stringify(this._strategy);
this._storageService.store(`${this._storagePrefix}/${this._mode}`, raw, StorageScope.WORKSPACE);
this._storageService.store(`${this._storagePrefix}/${this._mode}`, raw, useGlobalStorageForSuggestions ? StorageScope.GLOBAL : StorageScope.WORKSPACE);
}
}