From edecd8bc74408d82b96c5d8b7750480bdb163379 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Thu, 21 Jul 2016 18:52:34 +0200 Subject: [PATCH] Adopt css to language-configuration --- extensions/css/client/src/cssMain.ts | 49 ++------------------- extensions/css/language-configuration.json | 24 ++++++++++ extensions/css/package.json | 3 +- extensions/less/language-configuration.json | 27 ++++++++++++ extensions/less/package.json | 3 +- extensions/scss/language-configuration.json | 27 ++++++++++++ extensions/scss/package.json | 3 +- src/vs/editor/node/languageConfiguration.ts | 14 +++--- 8 files changed, 95 insertions(+), 55 deletions(-) create mode 100644 extensions/css/language-configuration.json create mode 100644 extensions/less/language-configuration.json create mode 100644 extensions/scss/language-configuration.json diff --git a/extensions/css/client/src/cssMain.ts b/extensions/css/client/src/cssMain.ts index 9c932a2d927..bf5d06089b1 100644 --- a/extensions/css/client/src/cssMain.ts +++ b/extensions/css/client/src/cssMain.ts @@ -54,58 +54,15 @@ export function activate(context: ExtensionContext) { context.subscriptions.push(disposable); languages.setLanguageConfiguration('css', { - wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g, - comments: { - blockComment: ['/*', '*/'] - }, - brackets: [['{', '}'], ['[', ']'], ['(', ')']], - __characterPairSupport: { - autoClosingPairs: [ - { open: '{', close: '}' }, - { open: '[', close: ']' }, - { open: '(', close: ')' }, - { open: '"', close: '"', notIn: ['string'] }, - { open: '\'', close: '\'', notIn: ['string'] } - ] - } + wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g }); languages.setLanguageConfiguration('less', { - wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g, - comments: { - blockComment: ['/*', '*/'], - lineComment: '//' - }, - brackets: [['{', '}'], ['[', ']'], ['(', ')'], ['<', '>']], - __characterPairSupport: { - autoClosingPairs: [ - { open: '"', close: '"', notIn: ['string', 'comment'] }, - { open: '\'', close: '\'', notIn: ['string', 'comment'] }, - { open: '{', close: '}', notIn: ['string', 'comment'] }, - { open: '[', close: ']', notIn: ['string', 'comment'] }, - { open: '(', close: ')', notIn: ['string', 'comment'] }, - { open: '<', close: '>', notIn: ['string', 'comment'] }, - ] - } + wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g }); languages.setLanguageConfiguration('scss', { - wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@$#.!])?[\w-?]+%?|[@#!$.])/g, - comments: { - blockComment: ['/*', '*/'], - lineComment: '//' - }, - brackets: [['{', '}'], ['[', ']'], ['(', ')'], ['<', '>']], - __characterPairSupport: { - autoClosingPairs: [ - { open: '"', close: '"', notIn: ['string', 'comment'] }, - { open: '\'', close: '\'', notIn: ['string', 'comment'] }, - { open: '{', close: '}', notIn: ['string', 'comment'] }, - { open: '[', close: ']', notIn: ['string', 'comment'] }, - { open: '(', close: ')', notIn: ['string', 'comment'] }, - { open: '<', close: '>', notIn: ['string', 'comment'] }, - ] - } + wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@$#.!])?[\w-?]+%?|[@#!$.])/g }); commands.registerCommand('_css.applyCodeAction', applyCodeAction); diff --git a/extensions/css/language-configuration.json b/extensions/css/language-configuration.json new file mode 100644 index 00000000000..ae86befcd2a --- /dev/null +++ b/extensions/css/language-configuration.json @@ -0,0 +1,24 @@ +{ + "comments": { + "blockComment": ["/*", "*/"] + }, + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + "autoClosingPairs": [ + { "open": "{", "close": "}", "notIn": ["string", "comment"] }, + { "open": "[", "close": "]", "notIn": ["string", "comment"] }, + { "open": "(", "close": ")", "notIn": ["string", "comment"] }, + { "open": "\"", "close": "\"", "notIn": ["string", "comment"] }, + { "open": "'", "close": "'", "notIn": ["string", "comment"] } + ], + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ] +} \ No newline at end of file diff --git a/extensions/css/package.json b/extensions/css/package.json index 56058f2bde8..b9c09564918 100644 --- a/extensions/css/package.json +++ b/extensions/css/package.json @@ -21,7 +21,8 @@ "id": "css", "aliases": ["CSS", "css"], "extensions": [".css"], - "mimetypes": ["text/css"] + "mimetypes": ["text/css"], + "configuration": "./language-configuration.json" }], "grammars": [{ "language": "css", diff --git a/extensions/less/language-configuration.json b/extensions/less/language-configuration.json new file mode 100644 index 00000000000..570a46c4c9e --- /dev/null +++ b/extensions/less/language-configuration.json @@ -0,0 +1,27 @@ +{ + "comments": { + "blockComment": ["/*", "*/"], + "lineComment": "//" + }, + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["<", ">"] + ], + "autoClosingPairs": [ + { "open": "{", "close": "}", "notIn": ["string", "comment"] }, + { "open": "[", "close": "]", "notIn": ["string", "comment"] }, + { "open": "(", "close": ")", "notIn": ["string", "comment"] }, + { "open": "\"", "close": "\"", "notIn": ["string", "comment"] }, + { "open": "'", "close": "'", "notIn": ["string", "comment"] } + ], + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"], + ["<", ">"] + ] +} \ No newline at end of file diff --git a/extensions/less/package.json b/extensions/less/package.json index 96142a610ff..e6b9fd6368e 100644 --- a/extensions/less/package.json +++ b/extensions/less/package.json @@ -8,7 +8,8 @@ "id": "less", "aliases": ["Less", "less"], "extensions": [".less"], - "mimetypes": ["text/x-less", "text/less"] + "mimetypes": ["text/x-less", "text/less"], + "configuration": "./language-configuration.json" }], "grammars": [{ "language": "less", diff --git a/extensions/scss/language-configuration.json b/extensions/scss/language-configuration.json new file mode 100644 index 00000000000..570a46c4c9e --- /dev/null +++ b/extensions/scss/language-configuration.json @@ -0,0 +1,27 @@ +{ + "comments": { + "blockComment": ["/*", "*/"], + "lineComment": "//" + }, + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["<", ">"] + ], + "autoClosingPairs": [ + { "open": "{", "close": "}", "notIn": ["string", "comment"] }, + { "open": "[", "close": "]", "notIn": ["string", "comment"] }, + { "open": "(", "close": ")", "notIn": ["string", "comment"] }, + { "open": "\"", "close": "\"", "notIn": ["string", "comment"] }, + { "open": "'", "close": "'", "notIn": ["string", "comment"] } + ], + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"], + ["<", ">"] + ] +} \ No newline at end of file diff --git a/extensions/scss/package.json b/extensions/scss/package.json index 1a3ba922e02..1f1cb3bc7d7 100644 --- a/extensions/scss/package.json +++ b/extensions/scss/package.json @@ -8,7 +8,8 @@ "id": "scss", "aliases": ["Sass", "scss"], "extensions": [".scss"], - "mimetypes": ["text/x-scss", "text/scss"] + "mimetypes": ["text/x-scss", "text/scss"], + "configuration": "./language-configuration.json" }], "grammars": [{ "language": "scss", diff --git a/src/vs/editor/node/languageConfiguration.ts b/src/vs/editor/node/languageConfiguration.ts index 978827da063..8b0b55712fe 100644 --- a/src/vs/editor/node/languageConfiguration.ts +++ b/src/vs/editor/node/languageConfiguration.ts @@ -9,7 +9,7 @@ import {parse} from 'vs/base/common/json'; import {readFile} from 'vs/base/node/pfs'; import {LanguageConfiguration} from 'vs/editor/common/modes/languageConfigurationRegistry'; import {IModeService} from 'vs/editor/common/services/modeService'; -import {IAutoClosingPair} from 'vs/editor/common/modes'; +import {IAutoClosingPair, IAutoClosingPairConditional} from 'vs/editor/common/modes'; import {LanguageConfigurationRegistry} from 'vs/editor/common/modes/languageConfigurationRegistry'; type CharacterPair = [string, string]; @@ -22,8 +22,8 @@ interface ICommentRule { interface ILanguageConfiguration { comments?: ICommentRule; brackets?: CharacterPair[]; - autoClosingPairs?: CharacterPair[]; - surroundingPairs?: CharacterPair[]; + autoClosingPairs?: (CharacterPair | IAutoClosingPairConditional)[]; + surroundingPairs?: (CharacterPair | IAutoClosingPair)[]; } export class LanguageConfigurationFileHandler { @@ -92,10 +92,12 @@ export class LanguageConfigurationFileHandler { LanguageConfigurationRegistry.register(modeId, richEditConfig); } - private _mapCharacterPairs(pairs:CharacterPair[]): IAutoClosingPair[] { + private _mapCharacterPairs(pairs: (CharacterPair | IAutoClosingPairConditional)[]): IAutoClosingPairConditional[] { return pairs.map(pair => { - let [open, close] = pair; - return { open: open, close: close }; + if (Array.isArray(pair)) { + return { open: pair[0], close: pair[1] }; + } + return pair; }); } } -- GitLab