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

perf - pre-compute and cache lower case variants for label, sortText, and filterText

上级 46238353
......@@ -437,8 +437,17 @@ export interface CompletionItem {
* A command that should be run upon acceptance of this item.
*/
command?: Command;
/**@internal*/
noWhitespaceAdjust?: boolean;
/**@internal*/
noAutoAccept?: boolean;
/**@internal*/
_labelLow?: string;
/**@internal*/
_sortTextLow?: string;
/**@internal*/
_filterTextLow?: string;
}
export interface CompletionList {
......
......@@ -21,7 +21,6 @@ export interface ICompletionItem extends ISuggestionItem {
word?: string;
}
/* __GDPR__FRAGMENT__
"ICompletionStats" : {
"suggestionCount" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
......@@ -221,16 +220,16 @@ export class CompletionModel {
// if it matches we check with the label to compute highlights
// and if that doesn't yield a result we have no highlights,
// despite having the match
let match = scoreFn(word, wordLow, wordPos, suggestion.filterText, suggestion.filterText.toLowerCase(), 0, false);
let match = scoreFn(word, wordLow, wordPos, suggestion.filterText, suggestion._filterTextLow, 0, false);
if (!match) {
continue;
}
item.score = match[0];
item.matches = (fuzzyScore(word, wordLow, 0, suggestion.label, suggestion.label.toLowerCase(), 0, true) || anyScore(word, suggestion.label))[1];
item.matches = (fuzzyScore(word, wordLow, 0, suggestion.label, suggestion._labelLow, 0, true) || anyScore(word, suggestion.label))[1];
} else {
// by default match `word` against the `label`
let match = scoreFn(word, wordLow, wordPos, suggestion.label, suggestion.label.toLowerCase(), 0, false);
let match = scoreFn(word, wordLow, wordPos, suggestion.label, suggestion._labelLow, 0, false);
if (match) {
item.score = match[0];
item.matches = match[1];
......
......@@ -5,7 +5,6 @@
import { first } from 'vs/base/common/async';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { compareIgnoreCase } from 'vs/base/common/strings';
import { assign } from 'vs/base/common/objects';
import { onUnexpectedExternalError, canceled } from 'vs/base/common/errors';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
......@@ -94,10 +93,22 @@ export function provideSuggestionItems(
for (let suggestion of container.suggestions) {
if (acceptSuggestion(suggestion)) {
// fill in default range when missing
if (!suggestion.range) {
suggestion.range = defaultRange;
}
// fill in lower-case text
if (!suggestion._labelLow) {
suggestion._labelLow = suggestion.label.toLowerCase();
}
if (suggestion.sortText && !suggestion._sortTextLow) {
suggestion._sortTextLow = suggestion.sortText.toLowerCase();
}
if (suggestion.filterText && !suggestion._filterTextLow) {
suggestion._filterTextLow = suggestion.filterText.toLowerCase();
}
allSuggestions.push({
position,
container,
......@@ -156,28 +167,32 @@ function createSuggesionFilter(snippetConfig: SnippetConfig): (candidate: Comple
}
function defaultComparator(a: ISuggestionItem, b: ISuggestionItem): number {
let ret = 0;
// check with 'sortText'
if (typeof a.suggestion.sortText === 'string' && typeof b.suggestion.sortText === 'string') {
ret = compareIgnoreCase(a.suggestion.sortText, b.suggestion.sortText);
if (a.suggestion._sortTextLow < b.suggestion._sortTextLow) {
return -1;
} else if (a.suggestion._sortTextLow > b.suggestion._sortTextLow) {
return 1;
}
}
// check with 'label'
if (ret === 0) {
ret = compareIgnoreCase(a.suggestion.label, b.suggestion.label);
if (a.suggestion.label < b.suggestion.label) {
return -1;
} else if (a.suggestion.label > b.suggestion.label) {
return 1;
}
// check with 'type' and lower snippets
if (ret === 0 && a.suggestion.kind !== b.suggestion.kind) {
if (a.suggestion.kind !== b.suggestion.kind) {
if (a.suggestion.kind === CompletionItemKind.Snippet) {
ret = 1;
return 1;
} else if (b.suggestion.kind === CompletionItemKind.Snippet) {
ret = -1;
return -1;
}
}
return ret;
return 0;
}
function snippetUpComparator(a: ISuggestionItem, b: ISuggestionItem): number {
......
......@@ -4757,8 +4757,6 @@ declare namespace monaco.languages {
* A command that should be run upon acceptance of this item.
*/
command?: Command;
noWhitespaceAdjust?: boolean;
noAutoAccept?: boolean;
}
export interface CompletionList {
......
......@@ -675,7 +675,11 @@ class SuggestAdapter {
insertText: undefined,
additionalTextEdits: item.additionalTextEdits && item.additionalTextEdits.map(typeConvert.TextEdit.from),
command: this._commands.toInternal(item.command),
commitCharacters: item.commitCharacters
commitCharacters: item.commitCharacters,
// help with perf
_labelLow: item.label.toLowerCase(),
_filterTextLow: item.filterText && item.filterText.toLowerCase(),
_sortTextLow: item.sortText && item.sortText.toLowerCase()
};
// 'insertText'-logic
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册