Adopt css to language-configuration

This commit is contained in:
Martin Aeschlimann 2016-07-21 18:52:34 +02:00
parent f4a8c7a5e1
commit edecd8bc74
8 changed files with 95 additions and 55 deletions

View file

@ -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);

View file

@ -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": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}

View file

@ -21,7 +21,8 @@
"id": "css",
"aliases": ["CSS", "css"],
"extensions": [".css"],
"mimetypes": ["text/css"]
"mimetypes": ["text/css"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "css",

View file

@ -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": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
["<", ">"]
]
}

View file

@ -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",

View file

@ -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": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
["<", ">"]
]
}

View file

@ -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",

View file

@ -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 <IAutoClosingPairConditional> pair;
});
}
}