Skip to content

Commit a1af8aa

Browse files
committed
Refactors calls to languages.setLanguageConfiguration to declarative descriptions in language-configuration.json. This fixes microsoft#98621.
1 parent 82767cc commit a1af8aa

File tree

14 files changed

+120
-127
lines changed

14 files changed

+120
-127
lines changed

extensions/css-language-features/client/src/cssClient.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,6 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
9292
// client can be deactivated on extension deactivation
9393
context.subscriptions.push(disposable);
9494

95-
let indentationRules = {
96-
increaseIndentPattern: /(^.*\{[^}]*$)/,
97-
decreaseIndentPattern: /^\s*\}/
98-
};
99-
100-
languages.setLanguageConfiguration('css', {
101-
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g,
102-
indentationRules: indentationRules
103-
});
104-
105-
languages.setLanguageConfiguration('less', {
106-
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g,
107-
indentationRules: indentationRules
108-
});
109-
110-
languages.setLanguageConfiguration('scss', {
111-
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@$#.!])?[\w-?]+%?|[@#!$.])/g,
112-
indentationRules: indentationRules
113-
});
114-
11595
client.onReady().then(() => {
11696
context.subscriptions.push(initCompletionProvider());
11797
});

extensions/css/language-configuration.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@
2626
"start": "^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\/",
2727
"end": "^\\s*\\/\\*\\s*#endregion\\b.*\\*\\/"
2828
}
29-
}
29+
},
30+
"indentationRules": {
31+
"increaseIndentPattern": "(^.*\\{[^}]*$)",
32+
"decreaseIndentPattern": "^\\s*\\}"
33+
},
34+
"wordPattern": { "pattern": "(#?-?\\d*\\.\\d\\w*%?)|(::?[\\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\\w-?]+%?|[@#!.])", "flags": "g" }
3035
}

extensions/handlebars/language-configuration.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,24 @@
2222
{ "open": "\"", "close": "\"" },
2323
{ "open": "<", "close": ">" },
2424
{ "open": "{", "close": "}" }
25-
]
25+
],
26+
"wordPattern": {
27+
"pattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\$\\^\\&\\*\\(\\)\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\s]+)",
28+
"flags": "g"
29+
},
30+
"onEnterRules": [
31+
{
32+
"beforeText": { "pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!\\/)>)[^<]*$", "flags": "i" },
33+
"afterText": { "pattern": "^<\\/([_:\\w][_:\\w-.\\d]*)\\s*>", "flags": "i" },
34+
"action": {
35+
"indent": "indentOutdent"
36+
}
37+
},
38+
{
39+
"beforeText": { "pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))(\\w[\\w\\d]*)([^/>]*(?!\\/)>)[^<]*$", "flags": "i" },
40+
"action": {
41+
"indent": "indent"
42+
}
43+
}
44+
],
2645
}

extensions/html-language-features/client/src/htmlClient.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import * as nls from 'vscode-nls';
77
const localize = nls.loadMessageBundle();
88

99
import {
10-
languages, ExtensionContext, IndentAction, Position, TextDocument, Range, CompletionItem, CompletionItemKind, SnippetString, workspace, extensions,
10+
languages, ExtensionContext, Position, TextDocument, Range, CompletionItem, CompletionItemKind, SnippetString, workspace, extensions,
1111
Disposable, FormattingOptions, CancellationToken, ProviderResult, TextEdit, CompletionContext, CompletionList, SemanticTokensLegend,
1212
DocumentSemanticTokensProvider, DocumentRangeSemanticTokensProvider, SemanticTokens, window, commands
1313
} from 'vscode';
1414
import {
1515
LanguageClientOptions, RequestType, TextDocumentPositionParams, DocumentRangeFormattingParams,
1616
DocumentRangeFormattingRequest, ProvideCompletionItemsSignature, TextDocumentIdentifier, RequestType0, Range as LspRange, NotificationType, CommonLanguageClient
1717
} from 'vscode-languageclient';
18-
import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared';
1918
import { activateTagClosing } from './tagClosing';
2019
import { RequestService } from './requests';
2120
import { getCustomDataSource } from './customData';
@@ -197,40 +196,6 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
197196
}
198197
}
199198

200-
languages.setLanguageConfiguration('html', {
201-
indentationRules: {
202-
increaseIndentPattern: /<(?!\?|(?:area|base|br|col|frame|hr|html|img|input|keygen|link|menuitem|meta|param|source|track|wbr)\b|[^>]*\/>)([-_\.A-Za-z0-9]+)(?=\s|>)\b[^>]*>(?!.*<\/\1>)|<!--(?!.*-->)|\{[^}"']*$/,
203-
decreaseIndentPattern: /^\s*(<\/(?!html)[-_\.A-Za-z0-9]+\b[^>]*>|-->|\})/
204-
},
205-
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g,
206-
onEnterRules: [
207-
{
208-
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
209-
afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>/i,
210-
action: { indentAction: IndentAction.IndentOutdent }
211-
},
212-
{
213-
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
214-
action: { indentAction: IndentAction.Indent }
215-
}
216-
],
217-
});
218-
219-
languages.setLanguageConfiguration('handlebars', {
220-
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g,
221-
onEnterRules: [
222-
{
223-
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
224-
afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>/i,
225-
action: { indentAction: IndentAction.IndentOutdent }
226-
},
227-
{
228-
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
229-
action: { indentAction: IndentAction.Indent }
230-
}
231-
],
232-
});
233-
234199
const regionCompletionRegExpr = /^(\s*)(<(!(-(-\s*(#\w*)?)?)?)?)?$/;
235200
const htmlSnippetCompletionRegExpr = /^(\s*)(<(h(t(m(l)?)?)?)?)?$/;
236201
languages.registerCompletionItemProvider(documentSelector, {

extensions/html-language-features/client/src/htmlEmptyTagsShared.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

extensions/html/language-configuration.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,28 @@
2929
"start": "^\\s*<!--\\s*#region\\b.*-->",
3030
"end": "^\\s*<!--\\s*#endregion\\b.*-->"
3131
}
32+
},
33+
"wordPattern": {
34+
"pattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\$\\^\\&\\*\\(\\)\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\s]+)",
35+
"flags": "g"
36+
},
37+
"onEnterRules": [
38+
{
39+
"beforeText": { "pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!\\/)>)[^<]*$", "flags": "i" },
40+
"afterText": { "pattern": "^<\\/([_:\\w][_:\\w-.\\d]*)\\s*>", "flags": "i" },
41+
"action": {
42+
"indent": "indentOutdent"
43+
}
44+
},
45+
{
46+
"beforeText": { "pattern": "<(?!(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr))(\\w[\\w\\d]*)([^/>]*(?!\\/)>)[^<]*$", "flags": "i" },
47+
"action": {
48+
"indent": "indent"
49+
}
50+
}
51+
],
52+
"indentationRules": {
53+
"increaseIndentPattern": "<(?!\\?|(?:area|base|br|col|frame|hr|html|img|input|keygen|link|menuitem|meta|param|source|track|wbr)\\b|[^>]*\\/>)([-_\\.A-Za-z0-9]+)(?=\\s|>)\\b[^>]*>(?!.*<\\/\\1>)|<!--(?!.*-->)|\\{[^}\"']*$",
54+
"decreaseIndentPattern": "^\\s*(<\\/(?!html)[-_\\.A-Za-z0-9]+\\b[^>]*>|-->|\\})"
3255
}
33-
}
56+
}

extensions/json-language-features/client/src/jsonClient.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as nls from 'vscode-nls';
77
const localize = nls.loadMessageBundle();
88

99
import {
10-
workspace, window, languages, commands, ExtensionContext, extensions, Uri, LanguageConfiguration,
10+
workspace, window, languages, commands, ExtensionContext, extensions, Uri,
1111
Diagnostic, StatusBarAlignment, TextEditor, TextDocument, FormattingOptions, CancellationToken,
1212
ProviderResult, TextEdit, Range, Position, Disposable, CompletionItem, CompletionList, CompletionContext, Hover, MarkdownString,
1313
} from 'vscode';
@@ -362,17 +362,6 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
362362
}
363363

364364
});
365-
366-
const languageConfiguration: LanguageConfiguration = {
367-
wordPattern: /("(?:[^\\\"]*(?:\\.)?)*"?)|[^\s{}\[\],:]+/,
368-
indentationRules: {
369-
increaseIndentPattern: /({+(?=([^"]*"[^"]*")*[^"}]*$))|(\[+(?=([^"]*"[^"]*")*[^"\]]*$))/,
370-
decreaseIndentPattern: /^\s*[}\]],?\s*$/
371-
}
372-
};
373-
languages.setLanguageConfiguration('json', languageConfiguration);
374-
languages.setLanguageConfiguration('jsonc', languageConfiguration);
375-
376365
}
377366

378367
function getSchemaAssociations(_context: ExtensionContext): ISchemaAssociation[] {

extensions/json/language-configuration.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@
1414
{ "open": "'", "close": "'", "notIn": ["string"] },
1515
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
1616
{ "open": "`", "close": "`", "notIn": ["string", "comment"] }
17-
]
17+
],
18+
"wordPattern": "(\"(?:[^\\\\\\\"]*(?:\\\\.)?)*\"?)|[^\\s{}\\[\\],:]+",
19+
"indentationRules": {
20+
"increaseIndentPattern": "({+(?=([^\"]*\"[^\"]*\")*[^\"}]*$))|(\\[+(?=([^\"]*\"[^\"]*\")*[^\"\\]]*$))",
21+
"decreaseIndentPattern": "^\\s*[}\\]],?\\s*$"
22+
}
1823
}

extensions/less/language-configuration.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
["\"", "\""],
2323
["'", "'"]
2424
],
25-
"indentationRules": {
26-
"increaseIndentPattern": "(^.*\\{[^}]*$)",
27-
"decreaseIndentPattern": "^\\s*\\}"
28-
},
2925
"folding": {
3026
"markers": {
3127
"start": "^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\/",
3228
"end": "^\\s*\\/\\*\\s*#endregion\\b.*\\*\\/"
3329
}
34-
}
35-
}
30+
},
31+
"indentationRules": {
32+
"increaseIndentPattern": "(^.*\\{[^}]*$)",
33+
"decreaseIndentPattern": "^\\s*\\}"
34+
},
35+
"wordPattern": { "pattern": "(#?-?\\d*\\.\\d\\w*%?)|(::?[\\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\\w-?]+%?|[@#!.])", "flags": "g" }
36+
}

extensions/markdown-basics/language-configuration.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@
4949
"start": "^\\s*<!--\\s*#?region\\b.*-->",
5050
"end": "^\\s*<!--\\s*#?endregion\\b.*-->"
5151
}
52-
}
52+
},
53+
"wordPattern": { "pattern": "(\\p{Alphabetic}|\\p{Number}|\\p{Nonspacing_Mark})(((\\p{Alphabetic}|\\p{Number}|\\p{Nonspacing_Mark})|[_])?(\\p{Alphabetic}|\\p{Number}|\\p{Nonspacing_Mark}))*", "flags": "ug" },
5354
}

0 commit comments

Comments
 (0)