From 09166c4f44266a74627eed150ff4ea0a01acb565 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Fri, 1 Dec 2017 17:12:45 +0100 Subject: [PATCH] [css] use proposalprovider for region snippets --- extensions/css/client/src/cssMain.ts | 29 +++++++++++++++++++-- extensions/css/package.json | 4 --- extensions/css/snippets/css.snippets.json | 16 ------------ extensions/less/package.json | 4 --- extensions/less/snippets/less.snippets.json | 16 ------------ extensions/scss/package.json | 4 --- extensions/scss/snippets/scss.snippets.json | 16 ------------ 7 files changed, 27 insertions(+), 62 deletions(-) delete mode 100644 extensions/css/snippets/css.snippets.json delete mode 100644 extensions/less/snippets/less.snippets.json delete mode 100644 extensions/scss/snippets/scss.snippets.json diff --git a/extensions/css/client/src/cssMain.ts b/extensions/css/client/src/cssMain.ts index 1f8095776ad..19f131224ed 100644 --- a/extensions/css/client/src/cssMain.ts +++ b/extensions/css/client/src/cssMain.ts @@ -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[]) { diff --git a/extensions/css/package.json b/extensions/css/package.json index 51f35887735..e404748578a 100644 --- a/extensions/css/package.json +++ b/extensions/css/package.json @@ -43,10 +43,6 @@ "path": "./syntaxes/css.tmLanguage.json" } ], - "snippets": [{ - "language": "css", - "path": "./snippets/css.snippets.json" - }], "configuration": [ { "order": 22, diff --git a/extensions/css/snippets/css.snippets.json b/extensions/css/snippets/css.snippets.json deleted file mode 100644 index 30207dbb525..00000000000 --- a/extensions/css/snippets/css.snippets.json +++ /dev/null @@ -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" - } -} diff --git a/extensions/less/package.json b/extensions/less/package.json index d9aef5866b7..b23dfe356b9 100644 --- a/extensions/less/package.json +++ b/extensions/less/package.json @@ -19,10 +19,6 @@ "scopeName": "source.css.less", "path": "./syntaxes/less.tmLanguage.json" }], - "snippets": [{ - "language": "less", - "path": "./snippets/less.snippets.json" - }], "problemMatchers": [ { "name": "lessc", diff --git a/extensions/less/snippets/less.snippets.json b/extensions/less/snippets/less.snippets.json deleted file mode 100644 index 30207dbb525..00000000000 --- a/extensions/less/snippets/less.snippets.json +++ /dev/null @@ -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" - } -} diff --git a/extensions/scss/package.json b/extensions/scss/package.json index 74ae7f718fc..37e3abc67c5 100644 --- a/extensions/scss/package.json +++ b/extensions/scss/package.json @@ -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", diff --git a/extensions/scss/snippets/scss.snippets.json b/extensions/scss/snippets/scss.snippets.json deleted file mode 100644 index 30207dbb525..00000000000 --- a/extensions/scss/snippets/scss.snippets.json +++ /dev/null @@ -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" - } -}