[css] use proposalprovider for region snippets
parent
46842f0e38
commit
09166c4f44
|
@ -6,8 +6,8 @@
|
|||
|
||||
import * as path from 'path';
|
||||
|
||||
import { languages, window, commands, ExtensionContext, TextDocument, ColorInformation, ColorPresentation, Color } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, TextEdit } from 'vscode-languageclient';
|
||||
import { languages, window, commands, ExtensionContext, TextDocument, ColorInformation, ColorPresentation, Color, Range, Position, CompletionItem, CompletionItemKind, TextEdit, SnippetString } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient';
|
||||
|
||||
import { ConfigurationFeature } from 'vscode-languageclient/lib/configuration.proposed';
|
||||
import { DocumentColorRequest, DocumentColorParams, ColorPresentationRequest, ColorPresentationParams } from 'vscode-languageserver-protocol/lib/protocol.colorProvider.proposed';
|
||||
|
@ -104,6 +104,31 @@ export function activate(context: ExtensionContext) {
|
|||
indentationRules: indentationRules
|
||||
});
|
||||
|
||||
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; TextEdit.replace(range, '/* #region */');
|
||||
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 = '/* #endregion */';
|
||||
endProposal.documentation = localize('folding.end', 'Folding Region End');
|
||||
endProposal.sortText = 'zb';
|
||||
endProposal.filterText = match[2];
|
||||
return [beginProposal, endProposal];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
commands.registerCommand('_css.applyCodeAction', applyCodeAction);
|
||||
|
||||
function applyCodeAction(uri: string, documentVersion: number, edits: TextEdit[]) {
|
||||
|
|
|
@ -43,10 +43,6 @@
|
|||
"path": "./syntaxes/css.tmLanguage.json"
|
||||
}
|
||||
],
|
||||
"snippets": [{
|
||||
"language": "css",
|
||||
"path": "./snippets/css.snippets.json"
|
||||
}],
|
||||
"configuration": [
|
||||
{
|
||||
"order": 22,
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"Region Start": {
|
||||
"prefix": "#region",
|
||||
"body": [
|
||||
"/*#region $0*/"
|
||||
],
|
||||
"description": "Folding Region Start"
|
||||
},
|
||||
"Region End": {
|
||||
"prefix": "#endregion",
|
||||
"body": [
|
||||
"/*#endregion $0*/"
|
||||
],
|
||||
"description": "Folding Region End"
|
||||
}
|
||||
}
|
|
@ -19,10 +19,6 @@
|
|||
"scopeName": "source.css.less",
|
||||
"path": "./syntaxes/less.tmLanguage.json"
|
||||
}],
|
||||
"snippets": [{
|
||||
"language": "less",
|
||||
"path": "./snippets/less.snippets.json"
|
||||
}],
|
||||
"problemMatchers": [
|
||||
{
|
||||
"name": "lessc",
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"Region Start": {
|
||||
"prefix": "#region",
|
||||
"body": [
|
||||
"/*#region $0*/"
|
||||
],
|
||||
"description": "Folding Region Start"
|
||||
},
|
||||
"Region End": {
|
||||
"prefix": "#endregion",
|
||||
"body": [
|
||||
"/*#endregion $0*/"
|
||||
],
|
||||
"description": "Folding Region End"
|
||||
}
|
||||
}
|
|
@ -19,10 +19,6 @@
|
|||
"scopeName": "source.css.scss",
|
||||
"path": "./syntaxes/scss.json"
|
||||
}],
|
||||
"snippets": [{
|
||||
"language": "scss",
|
||||
"path": "./snippets/scss.snippets.json"
|
||||
}],
|
||||
"problemMatchers": [{
|
||||
"name": "node-sass",
|
||||
"label": "Node Sass Compiler",
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"Region Start": {
|
||||
"prefix": "#region",
|
||||
"body": [
|
||||
"/*#region $0*/"
|
||||
],
|
||||
"description": "Folding Region Start"
|
||||
},
|
||||
"Region End": {
|
||||
"prefix": "#endregion",
|
||||
"body": [
|
||||
"/*#endregion $0*/"
|
||||
],
|
||||
"description": "Folding Region End"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue