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

fill in snippets, reuse array

上级 b22a4637
......@@ -196,13 +196,13 @@ export class SnippetsRegistry {
}
public static getSnippetsStrict(model: IReadOnlyModel, position: IPosition): modes.ISuggestion[] {
public static fillInSnippets(bucket: modes.ISuggestion[], model: IReadOnlyModel, position: IPosition): void {
const match = model.getLineContent(position.lineNumber).substr(0, position.column - 1).match(/[^\s]+$/);
if (!match) {
return [];
return;
}
let idx = 0;
const prefix = match[0];
const result: modes.ISuggestion[] = [];
let snipppetsByMode = this._snippets[model.getModeId()];
if (snipppetsByMode) {
for (let path in snipppetsByMode) {
......@@ -210,12 +210,12 @@ export class SnippetsRegistry {
if (suggestions) {
for (const suggestion of suggestions) {
if (strings.endsWith(prefix, suggestion.label)) {
result.push(suggestion);
bucket[idx++] = suggestion;
}
}
}
}
}
return result;
bucket.length = idx;
}
}
......@@ -31,8 +31,7 @@ class TabCompletionController implements editor.IEditorContribution {
this._snippetController = getSnippetController(editor);
const hasSnippets = keybindingService.createKey(TabCompletionController.ContextKey, undefined);
this._cursorChangeSubscription = editor.onDidChangeCursorPosition(e => {
this._currentCompletions.length = 0;
this._currentCompletions = SnippetsRegistry.getSnippetsStrict(editor.getModel(), editor.getPosition());
SnippetsRegistry.fillInSnippets(this._currentCompletions, editor.getModel(), editor.getPosition());
hasSnippets.set(this._currentCompletions.length === 1); //todo@joh make it work with N
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册