Skip to content

Commit edecd8b

Browse files
committed
Adopt css to language-configuration
1 parent f4a8c7a commit edecd8b

8 files changed

Lines changed: 95 additions & 55 deletions

File tree

extensions/css/client/src/cssMain.ts

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -54,58 +54,15 @@ export function activate(context: ExtensionContext) {
5454
context.subscriptions.push(disposable);
5555

5656
languages.setLanguageConfiguration('css', {
57-
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g,
58-
comments: {
59-
blockComment: ['/*', '*/']
60-
},
61-
brackets: [['{', '}'], ['[', ']'], ['(', ')']],
62-
__characterPairSupport: {
63-
autoClosingPairs: [
64-
{ open: '{', close: '}' },
65-
{ open: '[', close: ']' },
66-
{ open: '(', close: ')' },
67-
{ open: '"', close: '"', notIn: ['string'] },
68-
{ open: '\'', close: '\'', notIn: ['string'] }
69-
]
70-
}
57+
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g
7158
});
7259

7360
languages.setLanguageConfiguration('less', {
74-
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g,
75-
comments: {
76-
blockComment: ['/*', '*/'],
77-
lineComment: '//'
78-
},
79-
brackets: [['{', '}'], ['[', ']'], ['(', ')'], ['<', '>']],
80-
__characterPairSupport: {
81-
autoClosingPairs: [
82-
{ open: '"', close: '"', notIn: ['string', 'comment'] },
83-
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
84-
{ open: '{', close: '}', notIn: ['string', 'comment'] },
85-
{ open: '[', close: ']', notIn: ['string', 'comment'] },
86-
{ open: '(', close: ')', notIn: ['string', 'comment'] },
87-
{ open: '<', close: '>', notIn: ['string', 'comment'] },
88-
]
89-
}
61+
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g
9062
});
9163

9264
languages.setLanguageConfiguration('scss', {
93-
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@$#.!])?[\w-?]+%?|[@#!$.])/g,
94-
comments: {
95-
blockComment: ['/*', '*/'],
96-
lineComment: '//'
97-
},
98-
brackets: [['{', '}'], ['[', ']'], ['(', ')'], ['<', '>']],
99-
__characterPairSupport: {
100-
autoClosingPairs: [
101-
{ open: '"', close: '"', notIn: ['string', 'comment'] },
102-
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
103-
{ open: '{', close: '}', notIn: ['string', 'comment'] },
104-
{ open: '[', close: ']', notIn: ['string', 'comment'] },
105-
{ open: '(', close: ')', notIn: ['string', 'comment'] },
106-
{ open: '<', close: '>', notIn: ['string', 'comment'] },
107-
]
108-
}
65+
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@$#.!])?[\w-?]+%?|[@#!$.])/g
10966
});
11067

11168
commands.registerCommand('_css.applyCodeAction', applyCodeAction);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"comments": {
3+
"blockComment": ["/*", "*/"]
4+
},
5+
"brackets": [
6+
["{", "}"],
7+
["[", "]"],
8+
["(", ")"]
9+
],
10+
"autoClosingPairs": [
11+
{ "open": "{", "close": "}", "notIn": ["string", "comment"] },
12+
{ "open": "[", "close": "]", "notIn": ["string", "comment"] },
13+
{ "open": "(", "close": ")", "notIn": ["string", "comment"] },
14+
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
15+
{ "open": "'", "close": "'", "notIn": ["string", "comment"] }
16+
],
17+
"surroundingPairs": [
18+
["{", "}"],
19+
["[", "]"],
20+
["(", ")"],
21+
["\"", "\""],
22+
["'", "'"]
23+
]
24+
}

extensions/css/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"id": "css",
2222
"aliases": ["CSS", "css"],
2323
"extensions": [".css"],
24-
"mimetypes": ["text/css"]
24+
"mimetypes": ["text/css"],
25+
"configuration": "./language-configuration.json"
2526
}],
2627
"grammars": [{
2728
"language": "css",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"comments": {
3+
"blockComment": ["/*", "*/"],
4+
"lineComment": "//"
5+
},
6+
"brackets": [
7+
["{", "}"],
8+
["[", "]"],
9+
["(", ")"],
10+
["<", ">"]
11+
],
12+
"autoClosingPairs": [
13+
{ "open": "{", "close": "}", "notIn": ["string", "comment"] },
14+
{ "open": "[", "close": "]", "notIn": ["string", "comment"] },
15+
{ "open": "(", "close": ")", "notIn": ["string", "comment"] },
16+
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
17+
{ "open": "'", "close": "'", "notIn": ["string", "comment"] }
18+
],
19+
"surroundingPairs": [
20+
["{", "}"],
21+
["[", "]"],
22+
["(", ")"],
23+
["\"", "\""],
24+
["'", "'"],
25+
["<", ">"]
26+
]
27+
}

extensions/less/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"id": "less",
99
"aliases": ["Less", "less"],
1010
"extensions": [".less"],
11-
"mimetypes": ["text/x-less", "text/less"]
11+
"mimetypes": ["text/x-less", "text/less"],
12+
"configuration": "./language-configuration.json"
1213
}],
1314
"grammars": [{
1415
"language": "less",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"comments": {
3+
"blockComment": ["/*", "*/"],
4+
"lineComment": "//"
5+
},
6+
"brackets": [
7+
["{", "}"],
8+
["[", "]"],
9+
["(", ")"],
10+
["<", ">"]
11+
],
12+
"autoClosingPairs": [
13+
{ "open": "{", "close": "}", "notIn": ["string", "comment"] },
14+
{ "open": "[", "close": "]", "notIn": ["string", "comment"] },
15+
{ "open": "(", "close": ")", "notIn": ["string", "comment"] },
16+
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
17+
{ "open": "'", "close": "'", "notIn": ["string", "comment"] }
18+
],
19+
"surroundingPairs": [
20+
["{", "}"],
21+
["[", "]"],
22+
["(", ")"],
23+
["\"", "\""],
24+
["'", "'"],
25+
["<", ">"]
26+
]
27+
}

extensions/scss/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"id": "scss",
99
"aliases": ["Sass", "scss"],
1010
"extensions": [".scss"],
11-
"mimetypes": ["text/x-scss", "text/scss"]
11+
"mimetypes": ["text/x-scss", "text/scss"],
12+
"configuration": "./language-configuration.json"
1213
}],
1314
"grammars": [{
1415
"language": "scss",

src/vs/editor/node/languageConfiguration.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {parse} from 'vs/base/common/json';
99
import {readFile} from 'vs/base/node/pfs';
1010
import {LanguageConfiguration} from 'vs/editor/common/modes/languageConfigurationRegistry';
1111
import {IModeService} from 'vs/editor/common/services/modeService';
12-
import {IAutoClosingPair} from 'vs/editor/common/modes';
12+
import {IAutoClosingPair, IAutoClosingPairConditional} from 'vs/editor/common/modes';
1313
import {LanguageConfigurationRegistry} from 'vs/editor/common/modes/languageConfigurationRegistry';
1414

1515
type CharacterPair = [string, string];
@@ -22,8 +22,8 @@ interface ICommentRule {
2222
interface ILanguageConfiguration {
2323
comments?: ICommentRule;
2424
brackets?: CharacterPair[];
25-
autoClosingPairs?: CharacterPair[];
26-
surroundingPairs?: CharacterPair[];
25+
autoClosingPairs?: (CharacterPair | IAutoClosingPairConditional)[];
26+
surroundingPairs?: (CharacterPair | IAutoClosingPair)[];
2727
}
2828

2929
export class LanguageConfigurationFileHandler {
@@ -92,10 +92,12 @@ export class LanguageConfigurationFileHandler {
9292
LanguageConfigurationRegistry.register(modeId, richEditConfig);
9393
}
9494

95-
private _mapCharacterPairs(pairs:CharacterPair[]): IAutoClosingPair[] {
95+
private _mapCharacterPairs(pairs: (CharacterPair | IAutoClosingPairConditional)[]): IAutoClosingPairConditional[] {
9696
return pairs.map(pair => {
97-
let [open, close] = pair;
98-
return { open: open, close: close };
97+
if (Array.isArray(pair)) {
98+
return { open: pair[0], close: pair[1] };
99+
}
100+
return <IAutoClosingPairConditional> pair;
99101
});
100102
}
101103
}

0 commit comments

Comments
 (0)