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.
@@ -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["Keyframe"] = 52] = "Keyframe";
66
- NodeType[NodeType["FontFace"] = 53] = "FontFace";
67
- NodeType[NodeType["Import"] = 54] = "Import";
68
- NodeType[NodeType["Namespace"] = 55] = "Namespace";
69
- NodeType[NodeType["Invocation"] = 56] = "Invocation";
70
- NodeType[NodeType["FunctionDeclaration"] = 57] = "FunctionDeclaration";
71
- NodeType[NodeType["ReturnStatement"] = 58] = "ReturnStatement";
72
- NodeType[NodeType["MediaQuery"] = 59] = "MediaQuery";
73
- NodeType[NodeType["MediaCondition"] = 60] = "MediaCondition";
74
- NodeType[NodeType["MediaFeature"] = 61] = "MediaFeature";
75
- NodeType[NodeType["FunctionParameter"] = 62] = "FunctionParameter";
76
- NodeType[NodeType["FunctionArgument"] = 63] = "FunctionArgument";
77
- NodeType[NodeType["KeyframeSelector"] = 64] = "KeyframeSelector";
78
- NodeType[NodeType["ViewPort"] = 65] = "ViewPort";
79
- NodeType[NodeType["Document"] = 66] = "Document";
80
- NodeType[NodeType["AtApplyRule"] = 67] = "AtApplyRule";
81
- NodeType[NodeType["CustomPropertyDeclaration"] = 68] = "CustomPropertyDeclaration";
82
- NodeType[NodeType["CustomPropertySet"] = 69] = "CustomPropertySet";
83
- NodeType[NodeType["ListEntry"] = 70] = "ListEntry";
84
- NodeType[NodeType["Supports"] = 71] = "Supports";
85
- NodeType[NodeType["SupportsCondition"] = 72] = "SupportsCondition";
86
- NodeType[NodeType["NamespacePrefix"] = 73] = "NamespacePrefix";
87
- NodeType[NodeType["GridLine"] = 74] = "GridLine";
88
- NodeType[NodeType["Plugin"] = 75] = "Plugin";
89
- NodeType[NodeType["UnknownAtRule"] = 76] = "UnknownAtRule";
90
- NodeType[NodeType["Use"] = 77] = "Use";
91
- NodeType[NodeType["ModuleConfiguration"] = 78] = "ModuleConfiguration";
92
- NodeType[NodeType["Forward"] = 79] = "Forward";
93
- NodeType[NodeType["ForwardVisibility"] = 80] = "ForwardVisibility";
94
- NodeType[NodeType["Module"] = 81] = "Module";
95
- NodeType[NodeType["UnicodeRange"] = 82] = "UnicodeRange";
96
- NodeType[NodeType["Layer"] = 83] = "Layer";
97
- NodeType[NodeType["LayerNameList"] = 84] = "LayerNameList";
98
- NodeType[NodeType["LayerName"] = 85] = "LayerName";
99
- NodeType[NodeType["PropertyAtRule"] = 86] = "PropertyAtRule";
100
- NodeType[NodeType["Container"] = 87] = "Container";
101
- NodeType[NodeType["ModuleConfig"] = 88] = "ModuleConfig";
102
- NodeType[NodeType["SelectorList"] = 89] = "SelectorList";
103
- NodeType[NodeType["StartingStyleAtRule"] = 90] = "StartingStyleAtRule";
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 flagOpts;
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 regex = /@media[^\{]+/g;
37
- const matches = node.getText().match(regex);
38
- flagOpts = {
39
- isMedia: true,
40
- text: matches?.[0],
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, flagOpts),
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, flagOpts) {
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 (flagOpts) {
127
- value = `${flagOpts.text}\n … ` + this.result.join('\n');
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, flagOpts) {
307
+ selectorToMarkedString(node, selectorContexts) {
308
308
  const root = selectorToElement(node);
309
309
  if (root) {
310
- const markedStrings = new MarkedStringPrinter('"').print(root, flagOpts);
310
+ const markedStrings = new MarkedStringPrinter('"').print(root, selectorContexts);
311
311
  markedStrings.push(this.selectorToSpecificityMarkedString(node));
312
312
  return markedStrings;
313
313
  }