Merge from vscode 52dcb723a39ae75bee1bd56b3312d7fcdc87aeed (#6719)

This commit is contained in:
Anthony Dresser
2019-08-12 21:31:51 -07:00
committed by GitHub
parent 00250839fc
commit 7eba8c4c03
616 changed files with 9472 additions and 7087 deletions

View File

@@ -22,10 +22,10 @@ export abstract class Memory {
if (items.length === 0) {
return 0;
}
let topScore = items[0].score;
let topScore = items[0].score[0];
for (let i = 1; i < items.length; i++) {
const { score, completion: suggestion } = items[i];
if (score !== topScore) {
if (score[0] !== topScore) {
// stop when leaving the group of top matches
break;
}
@@ -81,33 +81,42 @@ export class LRUMemory extends Memory {
}
select(model: ITextModel, pos: IPosition, items: CompletionItem[]): number {
// in order of completions, select the first
// that has been used in the past
let { word } = model.getWordUntilPosition(pos);
if (word.length !== 0) {
return super.select(model, pos, items);
if (items.length === 0) {
return 0;
}
let lineSuffix = model.getLineContent(pos.lineNumber).substr(pos.column - 10, pos.column - 1);
const lineSuffix = model.getLineContent(pos.lineNumber).substr(pos.column - 10, pos.column - 1);
if (/\s$/.test(lineSuffix)) {
return super.select(model, pos, items);
}
let res = -1;
let topScore = items[0].score[0];
let indexPreselect = -1;
let indexRecency = -1;
let seq = -1;
for (let i = 0; i < items.length; i++) {
const { completion: suggestion } = items[i];
const key = `${model.getLanguageIdentifier().language}/${suggestion.label}`;
const item = this._cache.get(key);
if (item && item.touch > seq && item.type === suggestion.kind && item.insertText === suggestion.insertText) {
if (items[i].score[0] !== topScore) {
// consider only top items
break;
}
const key = `${model.getLanguageIdentifier().language}/${items[i].completion.label}`;
const item = this._cache.peek(key);
if (item && item.touch > seq && item.type === items[i].completion.kind && item.insertText === items[i].completion.insertText) {
seq = item.touch;
res = i;
indexRecency = i;
}
if (items[i].completion.preselect && indexPreselect === -1) {
// stop when seeing an auto-select-item
return indexPreselect = i;
}
}
if (res === -1) {
return super.select(model, pos, items);
if (indexRecency !== -1) {
return indexRecency;
} else if (indexPreselect !== -1) {
return indexPreselect;
} else {
return res;
return 0;
}
}
@@ -204,9 +213,9 @@ export class SuggestMemoryService extends Disposable implements ISuggestMemorySe
private readonly _storagePrefix = 'suggest/memories';
private readonly _persistSoon: RunOnceScheduler;
private _mode: MemMode;
private _shareMem: boolean;
private _strategy: Memory;
private _mode!: MemMode;
private _shareMem!: boolean;
private _strategy!: Memory;
constructor(
@IStorageService private readonly _storageService: IStorageService,