vscode-css-languageservice 6.3.4 → 6.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/data/webCustomData.js +782 -421
- package/lib/esm/parser/cssNodes.js +78 -39
- package/lib/esm/parser/cssParser.js +54 -0
- package/lib/esm/services/cssHover.js +14 -8
- package/lib/esm/services/cssNavigation.js +8 -0
- package/lib/esm/services/selectorPrinting.js +5 -5
- package/lib/umd/data/webCustomData.js +782 -421
- package/lib/umd/parser/cssNodes.js +81 -40
- package/lib/umd/parser/cssParser.js +54 -0
- package/lib/umd/services/cssHover.js +14 -8
- package/lib/umd/services/cssNavigation.js +8 -0
- package/lib/umd/services/selectorPrinting.js +5 -5
- package/package.json +6 -6
|
@@ -62,45 +62,46 @@ export var NodeType;
|
|
|
62
62
|
NodeType[NodeType["MixinContentReference"] = 49] = "MixinContentReference";
|
|
63
63
|
NodeType[NodeType["MixinContentDeclaration"] = 50] = "MixinContentDeclaration";
|
|
64
64
|
NodeType[NodeType["Media"] = 51] = "Media";
|
|
65
|
-
NodeType[NodeType["
|
|
66
|
-
NodeType[NodeType["
|
|
67
|
-
NodeType[NodeType["
|
|
68
|
-
NodeType[NodeType["
|
|
69
|
-
NodeType[NodeType["
|
|
70
|
-
NodeType[NodeType["
|
|
71
|
-
NodeType[NodeType["
|
|
72
|
-
NodeType[NodeType["
|
|
73
|
-
NodeType[NodeType["
|
|
74
|
-
NodeType[NodeType["
|
|
75
|
-
NodeType[NodeType["
|
|
76
|
-
NodeType[NodeType["
|
|
77
|
-
NodeType[NodeType["
|
|
78
|
-
NodeType[NodeType["
|
|
79
|
-
NodeType[NodeType["
|
|
80
|
-
NodeType[NodeType["
|
|
81
|
-
NodeType[NodeType["
|
|
82
|
-
NodeType[NodeType["
|
|
83
|
-
NodeType[NodeType["
|
|
84
|
-
NodeType[NodeType["
|
|
85
|
-
NodeType[NodeType["
|
|
86
|
-
NodeType[NodeType["
|
|
87
|
-
NodeType[NodeType["
|
|
88
|
-
NodeType[NodeType["
|
|
89
|
-
NodeType[NodeType["
|
|
90
|
-
NodeType[NodeType["
|
|
91
|
-
NodeType[NodeType["
|
|
92
|
-
NodeType[NodeType["
|
|
93
|
-
NodeType[NodeType["
|
|
94
|
-
NodeType[NodeType["
|
|
95
|
-
NodeType[NodeType["
|
|
96
|
-
NodeType[NodeType["
|
|
97
|
-
NodeType[NodeType["
|
|
98
|
-
NodeType[NodeType["
|
|
99
|
-
NodeType[NodeType["
|
|
100
|
-
NodeType[NodeType["
|
|
101
|
-
NodeType[NodeType["
|
|
102
|
-
NodeType[NodeType["
|
|
103
|
-
NodeType[NodeType["
|
|
65
|
+
NodeType[NodeType["Scope"] = 52] = "Scope";
|
|
66
|
+
NodeType[NodeType["Keyframe"] = 53] = "Keyframe";
|
|
67
|
+
NodeType[NodeType["FontFace"] = 54] = "FontFace";
|
|
68
|
+
NodeType[NodeType["Import"] = 55] = "Import";
|
|
69
|
+
NodeType[NodeType["Namespace"] = 56] = "Namespace";
|
|
70
|
+
NodeType[NodeType["Invocation"] = 57] = "Invocation";
|
|
71
|
+
NodeType[NodeType["FunctionDeclaration"] = 58] = "FunctionDeclaration";
|
|
72
|
+
NodeType[NodeType["ReturnStatement"] = 59] = "ReturnStatement";
|
|
73
|
+
NodeType[NodeType["MediaQuery"] = 60] = "MediaQuery";
|
|
74
|
+
NodeType[NodeType["MediaCondition"] = 61] = "MediaCondition";
|
|
75
|
+
NodeType[NodeType["MediaFeature"] = 62] = "MediaFeature";
|
|
76
|
+
NodeType[NodeType["FunctionParameter"] = 63] = "FunctionParameter";
|
|
77
|
+
NodeType[NodeType["FunctionArgument"] = 64] = "FunctionArgument";
|
|
78
|
+
NodeType[NodeType["KeyframeSelector"] = 65] = "KeyframeSelector";
|
|
79
|
+
NodeType[NodeType["ViewPort"] = 66] = "ViewPort";
|
|
80
|
+
NodeType[NodeType["Document"] = 67] = "Document";
|
|
81
|
+
NodeType[NodeType["AtApplyRule"] = 68] = "AtApplyRule";
|
|
82
|
+
NodeType[NodeType["CustomPropertyDeclaration"] = 69] = "CustomPropertyDeclaration";
|
|
83
|
+
NodeType[NodeType["CustomPropertySet"] = 70] = "CustomPropertySet";
|
|
84
|
+
NodeType[NodeType["ListEntry"] = 71] = "ListEntry";
|
|
85
|
+
NodeType[NodeType["Supports"] = 72] = "Supports";
|
|
86
|
+
NodeType[NodeType["SupportsCondition"] = 73] = "SupportsCondition";
|
|
87
|
+
NodeType[NodeType["NamespacePrefix"] = 74] = "NamespacePrefix";
|
|
88
|
+
NodeType[NodeType["GridLine"] = 75] = "GridLine";
|
|
89
|
+
NodeType[NodeType["Plugin"] = 76] = "Plugin";
|
|
90
|
+
NodeType[NodeType["UnknownAtRule"] = 77] = "UnknownAtRule";
|
|
91
|
+
NodeType[NodeType["Use"] = 78] = "Use";
|
|
92
|
+
NodeType[NodeType["ModuleConfiguration"] = 79] = "ModuleConfiguration";
|
|
93
|
+
NodeType[NodeType["Forward"] = 80] = "Forward";
|
|
94
|
+
NodeType[NodeType["ForwardVisibility"] = 81] = "ForwardVisibility";
|
|
95
|
+
NodeType[NodeType["Module"] = 82] = "Module";
|
|
96
|
+
NodeType[NodeType["UnicodeRange"] = 83] = "UnicodeRange";
|
|
97
|
+
NodeType[NodeType["Layer"] = 84] = "Layer";
|
|
98
|
+
NodeType[NodeType["LayerNameList"] = 85] = "LayerNameList";
|
|
99
|
+
NodeType[NodeType["LayerName"] = 86] = "LayerName";
|
|
100
|
+
NodeType[NodeType["PropertyAtRule"] = 87] = "PropertyAtRule";
|
|
101
|
+
NodeType[NodeType["Container"] = 88] = "Container";
|
|
102
|
+
NodeType[NodeType["ModuleConfig"] = 89] = "ModuleConfig";
|
|
103
|
+
NodeType[NodeType["SelectorList"] = 90] = "SelectorList";
|
|
104
|
+
NodeType[NodeType["StartingStyleAtRule"] = 91] = "StartingStyleAtRule";
|
|
104
105
|
})(NodeType || (NodeType = {}));
|
|
105
106
|
export var ReferenceType;
|
|
106
107
|
(function (ReferenceType) {
|
|
@@ -871,6 +872,44 @@ export class Media extends BodyDeclaration {
|
|
|
871
872
|
return NodeType.Media;
|
|
872
873
|
}
|
|
873
874
|
}
|
|
875
|
+
export class Scope extends BodyDeclaration {
|
|
876
|
+
constructor(offset, length) {
|
|
877
|
+
super(offset, length);
|
|
878
|
+
}
|
|
879
|
+
get type() {
|
|
880
|
+
return NodeType.Scope;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
export class ScopeLimits extends Node {
|
|
884
|
+
constructor(offset, length) {
|
|
885
|
+
super(offset, length);
|
|
886
|
+
}
|
|
887
|
+
get type() {
|
|
888
|
+
return NodeType.Scope;
|
|
889
|
+
}
|
|
890
|
+
getScopeStart() {
|
|
891
|
+
return this.scopeStart;
|
|
892
|
+
}
|
|
893
|
+
setScopeStart(right) {
|
|
894
|
+
return this.setNode('scopeStart', right);
|
|
895
|
+
}
|
|
896
|
+
getScopeEnd() {
|
|
897
|
+
return this.scopeEnd;
|
|
898
|
+
}
|
|
899
|
+
setScopeEnd(right) {
|
|
900
|
+
return this.setNode('scopeEnd', right);
|
|
901
|
+
}
|
|
902
|
+
getName() {
|
|
903
|
+
let name = '';
|
|
904
|
+
if (this.scopeStart) {
|
|
905
|
+
name += this.scopeStart.getText();
|
|
906
|
+
}
|
|
907
|
+
if (this.scopeEnd) {
|
|
908
|
+
name += `${this.scopeStart ? ' ' : ''}→ ${this.scopeEnd.getText()}`;
|
|
909
|
+
}
|
|
910
|
+
return name;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
874
913
|
export class Supports extends BodyDeclaration {
|
|
875
914
|
constructor(offset, length) {
|
|
876
915
|
super(offset, length);
|
|
@@ -267,6 +267,7 @@ export class Parser {
|
|
|
267
267
|
_parseStylesheetAtStatement(isNested = false) {
|
|
268
268
|
return this._parseImport()
|
|
269
269
|
|| this._parseMedia(isNested)
|
|
270
|
+
|| this._parseScope()
|
|
270
271
|
|| this._parsePage()
|
|
271
272
|
|| this._parseFontFace()
|
|
272
273
|
|| this._parseKeyframe()
|
|
@@ -309,6 +310,7 @@ export class Parser {
|
|
|
309
310
|
}
|
|
310
311
|
_parseRuleSetDeclarationAtStatement() {
|
|
311
312
|
return this._parseMedia(true)
|
|
313
|
+
|| this._parseScope()
|
|
312
314
|
|| this._parseSupports(true)
|
|
313
315
|
|| this._parseLayer(true)
|
|
314
316
|
|| this._parseContainer(true)
|
|
@@ -339,6 +341,7 @@ export class Parser {
|
|
|
339
341
|
case nodes.NodeType.MixinDeclaration:
|
|
340
342
|
case nodes.NodeType.FunctionDeclaration:
|
|
341
343
|
case nodes.NodeType.MixinContentDeclaration:
|
|
344
|
+
case nodes.NodeType.Scope:
|
|
342
345
|
return false;
|
|
343
346
|
case nodes.NodeType.ExtendsReference:
|
|
344
347
|
case nodes.NodeType.MixinContentReference:
|
|
@@ -1094,6 +1097,57 @@ export class Parser {
|
|
|
1094
1097
|
_parseMediaFeatureValue() {
|
|
1095
1098
|
return this._parseRatio() || this._parseTermExpression();
|
|
1096
1099
|
}
|
|
1100
|
+
_parseScope() {
|
|
1101
|
+
// @scope [<scope-limits>]? { <block-contents> }
|
|
1102
|
+
if (!this.peekKeyword('@scope')) {
|
|
1103
|
+
return null;
|
|
1104
|
+
}
|
|
1105
|
+
const node = this.create(nodes.Scope);
|
|
1106
|
+
// @scope
|
|
1107
|
+
this.consumeToken();
|
|
1108
|
+
node.addChild(this._parseScopeLimits());
|
|
1109
|
+
return this._parseBody(node, this._parseScopeDeclaration.bind(this));
|
|
1110
|
+
}
|
|
1111
|
+
_parseScopeDeclaration() {
|
|
1112
|
+
// Treat as nested as regular declarations are implicity wrapped with :where(:scope)
|
|
1113
|
+
// https://github.com/w3c/csswg-drafts/issues/10389
|
|
1114
|
+
// pseudo-selectors implicitly target :scope
|
|
1115
|
+
// https://drafts.csswg.org/css-cascade-6/#scoped-rules
|
|
1116
|
+
const isNested = true;
|
|
1117
|
+
return this._tryParseRuleset(isNested)
|
|
1118
|
+
|| this._tryToParseDeclaration()
|
|
1119
|
+
|| this._parseStylesheetStatement(isNested);
|
|
1120
|
+
}
|
|
1121
|
+
_parseScopeLimits() {
|
|
1122
|
+
// [(<scope-start>)]? [to (<scope-end>)]?
|
|
1123
|
+
const node = this.create(nodes.ScopeLimits);
|
|
1124
|
+
// [(<scope-start>)]?
|
|
1125
|
+
if (this.accept(TokenType.ParenthesisL)) {
|
|
1126
|
+
// scope-start selector can start with a combinator as it defaults to :scope
|
|
1127
|
+
// Treat as nested
|
|
1128
|
+
if (!node.setScopeStart(this._parseSelector(true))) {
|
|
1129
|
+
return this.finish(node, ParseError.SelectorExpected, [], [TokenType.ParenthesisR]);
|
|
1130
|
+
}
|
|
1131
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
1132
|
+
return this.finish(node, ParseError.RightParenthesisExpected, [], [TokenType.CurlyL]);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
// [to (<scope-end>)]?
|
|
1136
|
+
if (this.acceptIdent('to')) {
|
|
1137
|
+
if (!this.accept(TokenType.ParenthesisL)) {
|
|
1138
|
+
return this.finish(node, ParseError.LeftParenthesisExpected, [], [TokenType.CurlyL]);
|
|
1139
|
+
}
|
|
1140
|
+
// 'to' selector can start with a combinator as it defaults to :scope
|
|
1141
|
+
// Treat as nested
|
|
1142
|
+
if (!node.setScopeEnd(this._parseSelector(true))) {
|
|
1143
|
+
return this.finish(node, ParseError.SelectorExpected, [], [TokenType.ParenthesisR]);
|
|
1144
|
+
}
|
|
1145
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
1146
|
+
return this.finish(node, ParseError.RightParenthesisExpected, [], [TokenType.CurlyL]);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
return this.finish(node);
|
|
1150
|
+
}
|
|
1097
1151
|
_parseMedium() {
|
|
1098
1152
|
const node = this.create(nodes.Node);
|
|
1099
1153
|
if (node.addChild(this._parseIdent())) {
|
|
@@ -29,20 +29,26 @@ export class CSSHover {
|
|
|
29
29
|
* Build up the hover by appending inner node's information
|
|
30
30
|
*/
|
|
31
31
|
let hover = null;
|
|
32
|
-
let
|
|
32
|
+
let selectorContexts = [];
|
|
33
33
|
for (let i = 0; i < nodepath.length; i++) {
|
|
34
34
|
const node = nodepath[i];
|
|
35
|
+
if (node instanceof nodes.Scope) {
|
|
36
|
+
const scopeLimits = node.getChild(0);
|
|
37
|
+
if (scopeLimits instanceof nodes.ScopeLimits) {
|
|
38
|
+
const scopeName = `${scopeLimits.getName()}`;
|
|
39
|
+
selectorContexts.push(`@scope${scopeName ? ` ${scopeName}` : ''}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
35
42
|
if (node instanceof nodes.Media) {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
43
|
+
const mediaList = node.getChild(0);
|
|
44
|
+
if (mediaList instanceof nodes.Medialist) {
|
|
45
|
+
const name = '@media ' + mediaList.getText();
|
|
46
|
+
selectorContexts.push(name);
|
|
47
|
+
}
|
|
42
48
|
}
|
|
43
49
|
if (node instanceof nodes.Selector) {
|
|
44
50
|
hover = {
|
|
45
|
-
contents: this.selectorPrinting.selectorToMarkedString(node,
|
|
51
|
+
contents: this.selectorPrinting.selectorToMarkedString(node, selectorContexts),
|
|
46
52
|
range: getRange(node),
|
|
47
53
|
};
|
|
48
54
|
break;
|
|
@@ -256,6 +256,14 @@ export class CSSNavigation {
|
|
|
256
256
|
collect(name, SymbolKind.Module, node, mediaList, node.getDeclarations());
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
+
else if (node instanceof nodes.Scope) {
|
|
260
|
+
let scopeName = '';
|
|
261
|
+
const scopeLimits = node.getChild(0);
|
|
262
|
+
if (scopeLimits instanceof nodes.ScopeLimits) {
|
|
263
|
+
scopeName = `${scopeLimits.getName()}`;
|
|
264
|
+
}
|
|
265
|
+
collect(`@scope${scopeName ? ` ${scopeName}` : ''}`, SymbolKind.Module, node, scopeLimits ?? undefined, node.getDeclarations());
|
|
266
|
+
}
|
|
259
267
|
return true;
|
|
260
268
|
});
|
|
261
269
|
}
|
|
@@ -112,7 +112,7 @@ class MarkedStringPrinter {
|
|
|
112
112
|
this.result = [];
|
|
113
113
|
// empty
|
|
114
114
|
}
|
|
115
|
-
print(element,
|
|
115
|
+
print(element, selectorContexts) {
|
|
116
116
|
this.result = [];
|
|
117
117
|
if (element instanceof RootElement) {
|
|
118
118
|
if (element.children) {
|
|
@@ -123,8 +123,8 @@ class MarkedStringPrinter {
|
|
|
123
123
|
this.doPrint([element], 0);
|
|
124
124
|
}
|
|
125
125
|
let value;
|
|
126
|
-
if (
|
|
127
|
-
value =
|
|
126
|
+
if (selectorContexts) {
|
|
127
|
+
value = [...selectorContexts, ...this.result].join('\n');
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
130
|
value = this.result.join('\n');
|
|
@@ -304,10 +304,10 @@ export class SelectorPrinting {
|
|
|
304
304
|
constructor(cssDataManager) {
|
|
305
305
|
this.cssDataManager = cssDataManager;
|
|
306
306
|
}
|
|
307
|
-
selectorToMarkedString(node,
|
|
307
|
+
selectorToMarkedString(node, selectorContexts) {
|
|
308
308
|
const root = selectorToElement(node);
|
|
309
309
|
if (root) {
|
|
310
|
-
const markedStrings = new MarkedStringPrinter('"').print(root,
|
|
310
|
+
const markedStrings = new MarkedStringPrinter('"').print(root, selectorContexts);
|
|
311
311
|
markedStrings.push(this.selectorToSpecificityMarkedString(node));
|
|
312
312
|
return markedStrings;
|
|
313
313
|
}
|