提交 9b391e82 编写于 作者: M Martin Aeschlimann

[html] use proposalprovider for region snippets

上级 09166c4f
......@@ -6,7 +6,7 @@
import * as path from 'path';
import { languages, ExtensionContext, IndentAction, Position, TextDocument, Color, ColorInformation, ColorPresentation } from 'vscode';
import { languages, ExtensionContext, IndentAction, Position, TextDocument, Color, ColorInformation, ColorPresentation, Range, CompletionItem, CompletionItemKind, TextEdit, SnippetString } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RequestType, TextDocumentPositionParams } from 'vscode-languageclient';
import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared';
import { activateTagClosing } from './tagClosing';
......@@ -163,6 +163,31 @@ export function activate(context: ExtensionContext) {
}
],
});
const regionCompletionRegExpr = /^(\s*)(<(!(-(-\s*(#\w*)?)?)?)?)?/;
languages.registerCompletionItemProvider(documentSelector, {
provideCompletionItems(doc, pos) {
let lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));
let match = lineUntilPos.match(regionCompletionRegExpr);
if (match) {
let range = new Range(new Position(pos.line, match[1].length), pos);
let beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet);
beginProposal.range = range;
beginProposal.insertText = new SnippetString('<!-- #region $1-->');
beginProposal.documentation = localize('folding.start', 'Folding Region Start');
beginProposal.filterText = match[2];
beginProposal.sortText = 'za';
let endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet);
endProposal.range = range;
endProposal.insertText = new SnippetString('<!-- #endregion -->');
endProposal.documentation = localize('folding.end', 'Folding Region End');
endProposal.filterText = match[2];
endProposal.sortText = 'zb';
return [beginProposal, endProposal];
}
return null;
}
});
}
function getPackageInfo(context: ExtensionContext): IPackageInfo | null {
......
......@@ -18,19 +18,5 @@
"</html>"
],
"description": "Simple HTML5 starting point"
},
"Region Start": {
"prefix": "#region",
"body": [
"<!-- #region -->"
],
"description": "Folding Region Start"
},
"Region End": {
"prefix": "#endregion",
"body": [
"<!-- #endregion -->"
],
"description": "Folding Region End"
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册