mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
Adopt css to language-configuration
This commit is contained in:
parent
f4a8c7a5e1
commit
edecd8bc74
|
@ -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);
|
||||
|
|
24
extensions/css/language-configuration.json
Normal file
24
extensions/css/language-configuration.json
Normal 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": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
["'", "'"]
|
||||
]
|
||||
}
|
|
@ -21,7 +21,8 @@
|
|||
"id": "css",
|
||||
"aliases": ["CSS", "css"],
|
||||
"extensions": [".css"],
|
||||
"mimetypes": ["text/css"]
|
||||
"mimetypes": ["text/css"],
|
||||
"configuration": "./language-configuration.json"
|
||||
}],
|
||||
"grammars": [{
|
||||
"language": "css",
|
||||
|
|
27
extensions/less/language-configuration.json
Normal file
27
extensions/less/language-configuration.json
Normal 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": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
["'", "'"],
|
||||
["<", ">"]
|
||||
]
|
||||
}
|
|
@ -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",
|
||||
|
|
27
extensions/scss/language-configuration.json
Normal file
27
extensions/scss/language-configuration.json
Normal 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": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
["'", "'"],
|
||||
["<", ">"]
|
||||
]
|
||||
}
|
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue