vscode-css-languageservice 5.3.0 → 6.0.0

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +1 -0
  3. package/lib/esm/beautify/beautify-css.js +57 -15
  4. package/lib/esm/cssLanguageService.d.ts +37 -37
  5. package/lib/esm/cssLanguageService.js +72 -75
  6. package/lib/esm/cssLanguageTypes.d.ts +238 -228
  7. package/lib/esm/cssLanguageTypes.js +42 -42
  8. package/lib/esm/data/webCustomData.js +21965 -21959
  9. package/lib/esm/languageFacts/builtinData.js +142 -142
  10. package/lib/esm/languageFacts/colors.js +469 -472
  11. package/lib/esm/languageFacts/dataManager.js +88 -92
  12. package/lib/esm/languageFacts/dataProvider.js +73 -79
  13. package/lib/esm/languageFacts/entry.js +137 -138
  14. package/lib/esm/languageFacts/facts.js +8 -8
  15. package/lib/esm/parser/cssErrors.js +48 -50
  16. package/lib/esm/parser/cssNodes.js +1502 -2019
  17. package/lib/esm/parser/cssParser.js +1534 -1566
  18. package/lib/esm/parser/cssScanner.js +592 -599
  19. package/lib/esm/parser/cssSymbolScope.js +311 -341
  20. package/lib/esm/parser/lessParser.js +714 -740
  21. package/lib/esm/parser/lessScanner.js +57 -78
  22. package/lib/esm/parser/scssErrors.js +18 -20
  23. package/lib/esm/parser/scssParser.js +796 -818
  24. package/lib/esm/parser/scssScanner.js +95 -116
  25. package/lib/esm/services/cssCodeActions.js +77 -81
  26. package/lib/esm/services/cssCompletion.js +1054 -1149
  27. package/lib/esm/services/cssFolding.js +190 -193
  28. package/lib/esm/services/cssFormatter.js +136 -117
  29. package/lib/esm/services/cssHover.js +148 -151
  30. package/lib/esm/services/cssNavigation.js +378 -470
  31. package/lib/esm/services/cssSelectionRange.js +47 -47
  32. package/lib/esm/services/cssValidation.js +41 -44
  33. package/lib/esm/services/lessCompletion.js +378 -397
  34. package/lib/esm/services/lint.js +518 -532
  35. package/lib/esm/services/lintRules.js +76 -83
  36. package/lib/esm/services/lintUtil.js +196 -205
  37. package/lib/esm/services/pathCompletion.js +157 -231
  38. package/lib/esm/services/scssCompletion.js +354 -378
  39. package/lib/esm/services/scssNavigation.js +82 -154
  40. package/lib/esm/services/selectorPrinting.js +492 -536
  41. package/lib/esm/utils/arrays.js +40 -46
  42. package/lib/esm/utils/objects.js +11 -11
  43. package/lib/esm/utils/resources.js +11 -24
  44. package/lib/esm/utils/strings.js +102 -104
  45. package/lib/umd/beautify/beautify-css.js +57 -15
  46. package/lib/umd/cssLanguageService.d.ts +37 -37
  47. package/lib/umd/cssLanguageService.js +99 -102
  48. package/lib/umd/cssLanguageTypes.d.ts +238 -228
  49. package/lib/umd/cssLanguageTypes.js +89 -88
  50. package/lib/umd/data/webCustomData.js +21978 -21972
  51. package/lib/umd/languageFacts/builtinData.js +154 -154
  52. package/lib/umd/languageFacts/colors.js +492 -495
  53. package/lib/umd/languageFacts/dataManager.js +101 -104
  54. package/lib/umd/languageFacts/dataProvider.js +86 -91
  55. package/lib/umd/languageFacts/entry.js +152 -153
  56. package/lib/umd/languageFacts/facts.js +29 -29
  57. package/lib/umd/parser/cssErrors.js +61 -62
  58. package/lib/umd/parser/cssNodes.js +1587 -2034
  59. package/lib/umd/parser/cssParser.js +1547 -1578
  60. package/lib/umd/parser/cssScanner.js +606 -611
  61. package/lib/umd/parser/cssSymbolScope.js +328 -353
  62. package/lib/umd/parser/lessParser.js +727 -752
  63. package/lib/umd/parser/lessScanner.js +70 -90
  64. package/lib/umd/parser/scssErrors.js +31 -32
  65. package/lib/umd/parser/scssParser.js +809 -830
  66. package/lib/umd/parser/scssScanner.js +108 -128
  67. package/lib/umd/services/cssCodeActions.js +90 -93
  68. package/lib/umd/services/cssCompletion.js +1067 -1161
  69. package/lib/umd/services/cssFolding.js +203 -206
  70. package/lib/umd/services/cssFormatter.js +150 -131
  71. package/lib/umd/services/cssHover.js +161 -163
  72. package/lib/umd/services/cssNavigation.js +391 -482
  73. package/lib/umd/services/cssSelectionRange.js +60 -60
  74. package/lib/umd/services/cssValidation.js +54 -56
  75. package/lib/umd/services/lessCompletion.js +391 -409
  76. package/lib/umd/services/lint.js +531 -544
  77. package/lib/umd/services/lintRules.js +91 -95
  78. package/lib/umd/services/lintUtil.js +210 -218
  79. package/lib/umd/services/pathCompletion.js +171 -244
  80. package/lib/umd/services/scssCompletion.js +367 -390
  81. package/lib/umd/services/scssNavigation.js +95 -166
  82. package/lib/umd/services/selectorPrinting.js +510 -550
  83. package/lib/umd/utils/arrays.js +55 -61
  84. package/lib/umd/utils/objects.js +25 -25
  85. package/lib/umd/utils/resources.js +26 -39
  86. package/lib/umd/utils/strings.js +120 -122
  87. package/package.json +11 -11
@@ -1,341 +1,311 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License. See License.txt in the project root for license information.
4
- *--------------------------------------------------------------------------------------------*/
5
- 'use strict';
6
- var __extends = (this && this.__extends) || (function () {
7
- var extendStatics = function (d, b) {
8
- extendStatics = Object.setPrototypeOf ||
9
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
11
- return extendStatics(d, b);
12
- };
13
- return function (d, b) {
14
- if (typeof b !== "function" && b !== null)
15
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
16
- extendStatics(d, b);
17
- function __() { this.constructor = d; }
18
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19
- };
20
- })();
21
- import * as nodes from './cssNodes';
22
- import { findFirst } from '../utils/arrays';
23
- var Scope = /** @class */ (function () {
24
- function Scope(offset, length) {
25
- this.offset = offset;
26
- this.length = length;
27
- this.symbols = [];
28
- this.parent = null;
29
- this.children = [];
30
- }
31
- Scope.prototype.addChild = function (scope) {
32
- this.children.push(scope);
33
- scope.setParent(this);
34
- };
35
- Scope.prototype.setParent = function (scope) {
36
- this.parent = scope;
37
- };
38
- Scope.prototype.findScope = function (offset, length) {
39
- if (length === void 0) { length = 0; }
40
- if (this.offset <= offset && this.offset + this.length > offset + length || this.offset === offset && this.length === length) {
41
- return this.findInScope(offset, length);
42
- }
43
- return null;
44
- };
45
- Scope.prototype.findInScope = function (offset, length) {
46
- if (length === void 0) { length = 0; }
47
- // find the first scope child that has an offset larger than offset + length
48
- var end = offset + length;
49
- var idx = findFirst(this.children, function (s) { return s.offset > end; });
50
- if (idx === 0) {
51
- // all scopes have offsets larger than our end
52
- return this;
53
- }
54
- var res = this.children[idx - 1];
55
- if (res.offset <= offset && res.offset + res.length >= offset + length) {
56
- return res.findInScope(offset, length);
57
- }
58
- return this;
59
- };
60
- Scope.prototype.addSymbol = function (symbol) {
61
- this.symbols.push(symbol);
62
- };
63
- Scope.prototype.getSymbol = function (name, type) {
64
- for (var index = 0; index < this.symbols.length; index++) {
65
- var symbol = this.symbols[index];
66
- if (symbol.name === name && symbol.type === type) {
67
- return symbol;
68
- }
69
- }
70
- return null;
71
- };
72
- Scope.prototype.getSymbols = function () {
73
- return this.symbols;
74
- };
75
- return Scope;
76
- }());
77
- export { Scope };
78
- var GlobalScope = /** @class */ (function (_super) {
79
- __extends(GlobalScope, _super);
80
- function GlobalScope() {
81
- return _super.call(this, 0, Number.MAX_VALUE) || this;
82
- }
83
- return GlobalScope;
84
- }(Scope));
85
- export { GlobalScope };
86
- var Symbol = /** @class */ (function () {
87
- function Symbol(name, value, node, type) {
88
- this.name = name;
89
- this.value = value;
90
- this.node = node;
91
- this.type = type;
92
- }
93
- return Symbol;
94
- }());
95
- export { Symbol };
96
- var ScopeBuilder = /** @class */ (function () {
97
- function ScopeBuilder(scope) {
98
- this.scope = scope;
99
- }
100
- ScopeBuilder.prototype.addSymbol = function (node, name, value, type) {
101
- if (node.offset !== -1) {
102
- var current = this.scope.findScope(node.offset, node.length);
103
- if (current) {
104
- current.addSymbol(new Symbol(name, value, node, type));
105
- }
106
- }
107
- };
108
- ScopeBuilder.prototype.addScope = function (node) {
109
- if (node.offset !== -1) {
110
- var current = this.scope.findScope(node.offset, node.length);
111
- if (current && (current.offset !== node.offset || current.length !== node.length)) { // scope already known?
112
- var newScope = new Scope(node.offset, node.length);
113
- current.addChild(newScope);
114
- return newScope;
115
- }
116
- return current;
117
- }
118
- return null;
119
- };
120
- ScopeBuilder.prototype.addSymbolToChildScope = function (scopeNode, node, name, value, type) {
121
- if (scopeNode && scopeNode.offset !== -1) {
122
- var current = this.addScope(scopeNode); // create the scope or gets the existing one
123
- if (current) {
124
- current.addSymbol(new Symbol(name, value, node, type));
125
- }
126
- }
127
- };
128
- ScopeBuilder.prototype.visitNode = function (node) {
129
- switch (node.type) {
130
- case nodes.NodeType.Keyframe:
131
- this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Keyframe);
132
- return true;
133
- case nodes.NodeType.CustomPropertyDeclaration:
134
- return this.visitCustomPropertyDeclarationNode(node);
135
- case nodes.NodeType.VariableDeclaration:
136
- return this.visitVariableDeclarationNode(node);
137
- case nodes.NodeType.Ruleset:
138
- return this.visitRuleSet(node);
139
- case nodes.NodeType.MixinDeclaration:
140
- this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Mixin);
141
- return true;
142
- case nodes.NodeType.FunctionDeclaration:
143
- this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Function);
144
- return true;
145
- case nodes.NodeType.FunctionParameter: {
146
- return this.visitFunctionParameterNode(node);
147
- }
148
- case nodes.NodeType.Declarations:
149
- this.addScope(node);
150
- return true;
151
- case nodes.NodeType.For:
152
- var forNode = node;
153
- var scopeNode = forNode.getDeclarations();
154
- if (scopeNode && forNode.variable) {
155
- this.addSymbolToChildScope(scopeNode, forNode.variable, forNode.variable.getName(), void 0, nodes.ReferenceType.Variable);
156
- }
157
- return true;
158
- case nodes.NodeType.Each: {
159
- var eachNode = node;
160
- var scopeNode_1 = eachNode.getDeclarations();
161
- if (scopeNode_1) {
162
- var variables = eachNode.getVariables().getChildren();
163
- for (var _i = 0, variables_1 = variables; _i < variables_1.length; _i++) {
164
- var variable = variables_1[_i];
165
- this.addSymbolToChildScope(scopeNode_1, variable, variable.getName(), void 0, nodes.ReferenceType.Variable);
166
- }
167
- }
168
- return true;
169
- }
170
- }
171
- return true;
172
- };
173
- ScopeBuilder.prototype.visitRuleSet = function (node) {
174
- var current = this.scope.findScope(node.offset, node.length);
175
- if (current) {
176
- for (var _i = 0, _a = node.getSelectors().getChildren(); _i < _a.length; _i++) {
177
- var child = _a[_i];
178
- if (child instanceof nodes.Selector) {
179
- if (child.getChildren().length === 1) { // only selectors with a single element can be extended
180
- current.addSymbol(new Symbol(child.getChild(0).getText(), void 0, child, nodes.ReferenceType.Rule));
181
- }
182
- }
183
- }
184
- }
185
- return true;
186
- };
187
- ScopeBuilder.prototype.visitVariableDeclarationNode = function (node) {
188
- var value = node.getValue() ? node.getValue().getText() : void 0;
189
- this.addSymbol(node, node.getName(), value, nodes.ReferenceType.Variable);
190
- return true;
191
- };
192
- ScopeBuilder.prototype.visitFunctionParameterNode = function (node) {
193
- // parameters are part of the body scope
194
- var scopeNode = node.getParent().getDeclarations();
195
- if (scopeNode) {
196
- var valueNode = node.getDefaultValue();
197
- var value = valueNode ? valueNode.getText() : void 0;
198
- this.addSymbolToChildScope(scopeNode, node, node.getName(), value, nodes.ReferenceType.Variable);
199
- }
200
- return true;
201
- };
202
- ScopeBuilder.prototype.visitCustomPropertyDeclarationNode = function (node) {
203
- var value = node.getValue() ? node.getValue().getText() : '';
204
- this.addCSSVariable(node.getProperty(), node.getProperty().getName(), value, nodes.ReferenceType.Variable);
205
- return true;
206
- };
207
- ScopeBuilder.prototype.addCSSVariable = function (node, name, value, type) {
208
- if (node.offset !== -1) {
209
- this.scope.addSymbol(new Symbol(name, value, node, type));
210
- }
211
- };
212
- return ScopeBuilder;
213
- }());
214
- export { ScopeBuilder };
215
- var Symbols = /** @class */ (function () {
216
- function Symbols(node) {
217
- this.global = new GlobalScope();
218
- node.acceptVisitor(new ScopeBuilder(this.global));
219
- }
220
- Symbols.prototype.findSymbolsAtOffset = function (offset, referenceType) {
221
- var scope = this.global.findScope(offset, 0);
222
- var result = [];
223
- var names = {};
224
- while (scope) {
225
- var symbols = scope.getSymbols();
226
- for (var i = 0; i < symbols.length; i++) {
227
- var symbol = symbols[i];
228
- if (symbol.type === referenceType && !names[symbol.name]) {
229
- result.push(symbol);
230
- names[symbol.name] = true;
231
- }
232
- }
233
- scope = scope.parent;
234
- }
235
- return result;
236
- };
237
- Symbols.prototype.internalFindSymbol = function (node, referenceTypes) {
238
- var scopeNode = node;
239
- if (node.parent instanceof nodes.FunctionParameter && node.parent.getParent() instanceof nodes.BodyDeclaration) {
240
- scopeNode = node.parent.getParent().getDeclarations();
241
- }
242
- if (node.parent instanceof nodes.FunctionArgument && node.parent.getParent() instanceof nodes.Function) {
243
- var funcId = node.parent.getParent().getIdentifier();
244
- if (funcId) {
245
- var functionSymbol = this.internalFindSymbol(funcId, [nodes.ReferenceType.Function]);
246
- if (functionSymbol) {
247
- scopeNode = functionSymbol.node.getDeclarations();
248
- }
249
- }
250
- }
251
- if (!scopeNode) {
252
- return null;
253
- }
254
- var name = node.getText();
255
- var scope = this.global.findScope(scopeNode.offset, scopeNode.length);
256
- while (scope) {
257
- for (var index = 0; index < referenceTypes.length; index++) {
258
- var type = referenceTypes[index];
259
- var symbol = scope.getSymbol(name, type);
260
- if (symbol) {
261
- return symbol;
262
- }
263
- }
264
- scope = scope.parent;
265
- }
266
- return null;
267
- };
268
- Symbols.prototype.evaluateReferenceTypes = function (node) {
269
- if (node instanceof nodes.Identifier) {
270
- var referenceTypes = node.referenceTypes;
271
- if (referenceTypes) {
272
- return referenceTypes;
273
- }
274
- else {
275
- if (node.isCustomProperty) {
276
- return [nodes.ReferenceType.Variable];
277
- }
278
- // are a reference to a keyframe?
279
- var decl = nodes.getParentDeclaration(node);
280
- if (decl) {
281
- var propertyName = decl.getNonPrefixedPropertyName();
282
- if ((propertyName === 'animation' || propertyName === 'animation-name')
283
- && decl.getValue() && decl.getValue().offset === node.offset) {
284
- return [nodes.ReferenceType.Keyframe];
285
- }
286
- }
287
- }
288
- }
289
- else if (node instanceof nodes.Variable) {
290
- return [nodes.ReferenceType.Variable];
291
- }
292
- var selector = node.findAParent(nodes.NodeType.Selector, nodes.NodeType.ExtendsReference);
293
- if (selector) {
294
- return [nodes.ReferenceType.Rule];
295
- }
296
- return null;
297
- };
298
- Symbols.prototype.findSymbolFromNode = function (node) {
299
- if (!node) {
300
- return null;
301
- }
302
- while (node.type === nodes.NodeType.Interpolation) {
303
- node = node.getParent();
304
- }
305
- var referenceTypes = this.evaluateReferenceTypes(node);
306
- if (referenceTypes) {
307
- return this.internalFindSymbol(node, referenceTypes);
308
- }
309
- return null;
310
- };
311
- Symbols.prototype.matchesSymbol = function (node, symbol) {
312
- if (!node) {
313
- return false;
314
- }
315
- while (node.type === nodes.NodeType.Interpolation) {
316
- node = node.getParent();
317
- }
318
- if (!node.matches(symbol.name)) {
319
- return false;
320
- }
321
- var referenceTypes = this.evaluateReferenceTypes(node);
322
- if (!referenceTypes || referenceTypes.indexOf(symbol.type) === -1) {
323
- return false;
324
- }
325
- var nodeSymbol = this.internalFindSymbol(node, referenceTypes);
326
- return nodeSymbol === symbol;
327
- };
328
- Symbols.prototype.findSymbol = function (name, type, offset) {
329
- var scope = this.global.findScope(offset);
330
- while (scope) {
331
- var symbol = scope.getSymbol(name, type);
332
- if (symbol) {
333
- return symbol;
334
- }
335
- scope = scope.parent;
336
- }
337
- return null;
338
- };
339
- return Symbols;
340
- }());
341
- export { Symbols };
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ 'use strict';
6
+ import * as nodes from './cssNodes';
7
+ import { findFirst } from '../utils/arrays';
8
+ export class Scope {
9
+ constructor(offset, length) {
10
+ this.offset = offset;
11
+ this.length = length;
12
+ this.symbols = [];
13
+ this.parent = null;
14
+ this.children = [];
15
+ }
16
+ addChild(scope) {
17
+ this.children.push(scope);
18
+ scope.setParent(this);
19
+ }
20
+ setParent(scope) {
21
+ this.parent = scope;
22
+ }
23
+ findScope(offset, length = 0) {
24
+ if (this.offset <= offset && this.offset + this.length > offset + length || this.offset === offset && this.length === length) {
25
+ return this.findInScope(offset, length);
26
+ }
27
+ return null;
28
+ }
29
+ findInScope(offset, length = 0) {
30
+ // find the first scope child that has an offset larger than offset + length
31
+ const end = offset + length;
32
+ const idx = findFirst(this.children, s => s.offset > end);
33
+ if (idx === 0) {
34
+ // all scopes have offsets larger than our end
35
+ return this;
36
+ }
37
+ const res = this.children[idx - 1];
38
+ if (res.offset <= offset && res.offset + res.length >= offset + length) {
39
+ return res.findInScope(offset, length);
40
+ }
41
+ return this;
42
+ }
43
+ addSymbol(symbol) {
44
+ this.symbols.push(symbol);
45
+ }
46
+ getSymbol(name, type) {
47
+ for (let index = 0; index < this.symbols.length; index++) {
48
+ const symbol = this.symbols[index];
49
+ if (symbol.name === name && symbol.type === type) {
50
+ return symbol;
51
+ }
52
+ }
53
+ return null;
54
+ }
55
+ getSymbols() {
56
+ return this.symbols;
57
+ }
58
+ }
59
+ export class GlobalScope extends Scope {
60
+ constructor() {
61
+ super(0, Number.MAX_VALUE);
62
+ }
63
+ }
64
+ export class Symbol {
65
+ constructor(name, value, node, type) {
66
+ this.name = name;
67
+ this.value = value;
68
+ this.node = node;
69
+ this.type = type;
70
+ }
71
+ }
72
+ export class ScopeBuilder {
73
+ constructor(scope) {
74
+ this.scope = scope;
75
+ }
76
+ addSymbol(node, name, value, type) {
77
+ if (node.offset !== -1) {
78
+ const current = this.scope.findScope(node.offset, node.length);
79
+ if (current) {
80
+ current.addSymbol(new Symbol(name, value, node, type));
81
+ }
82
+ }
83
+ }
84
+ addScope(node) {
85
+ if (node.offset !== -1) {
86
+ const current = this.scope.findScope(node.offset, node.length);
87
+ if (current && (current.offset !== node.offset || current.length !== node.length)) { // scope already known?
88
+ const newScope = new Scope(node.offset, node.length);
89
+ current.addChild(newScope);
90
+ return newScope;
91
+ }
92
+ return current;
93
+ }
94
+ return null;
95
+ }
96
+ addSymbolToChildScope(scopeNode, node, name, value, type) {
97
+ if (scopeNode && scopeNode.offset !== -1) {
98
+ const current = this.addScope(scopeNode); // create the scope or gets the existing one
99
+ if (current) {
100
+ current.addSymbol(new Symbol(name, value, node, type));
101
+ }
102
+ }
103
+ }
104
+ visitNode(node) {
105
+ switch (node.type) {
106
+ case nodes.NodeType.Keyframe:
107
+ this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Keyframe);
108
+ return true;
109
+ case nodes.NodeType.CustomPropertyDeclaration:
110
+ return this.visitCustomPropertyDeclarationNode(node);
111
+ case nodes.NodeType.VariableDeclaration:
112
+ return this.visitVariableDeclarationNode(node);
113
+ case nodes.NodeType.Ruleset:
114
+ return this.visitRuleSet(node);
115
+ case nodes.NodeType.MixinDeclaration:
116
+ this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Mixin);
117
+ return true;
118
+ case nodes.NodeType.FunctionDeclaration:
119
+ this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Function);
120
+ return true;
121
+ case nodes.NodeType.FunctionParameter: {
122
+ return this.visitFunctionParameterNode(node);
123
+ }
124
+ case nodes.NodeType.Declarations:
125
+ this.addScope(node);
126
+ return true;
127
+ case nodes.NodeType.For:
128
+ const forNode = node;
129
+ const scopeNode = forNode.getDeclarations();
130
+ if (scopeNode && forNode.variable) {
131
+ this.addSymbolToChildScope(scopeNode, forNode.variable, forNode.variable.getName(), void 0, nodes.ReferenceType.Variable);
132
+ }
133
+ return true;
134
+ case nodes.NodeType.Each: {
135
+ const eachNode = node;
136
+ const scopeNode = eachNode.getDeclarations();
137
+ if (scopeNode) {
138
+ const variables = eachNode.getVariables().getChildren();
139
+ for (const variable of variables) {
140
+ this.addSymbolToChildScope(scopeNode, variable, variable.getName(), void 0, nodes.ReferenceType.Variable);
141
+ }
142
+ }
143
+ return true;
144
+ }
145
+ }
146
+ return true;
147
+ }
148
+ visitRuleSet(node) {
149
+ const current = this.scope.findScope(node.offset, node.length);
150
+ if (current) {
151
+ for (const child of node.getSelectors().getChildren()) {
152
+ if (child instanceof nodes.Selector) {
153
+ if (child.getChildren().length === 1) { // only selectors with a single element can be extended
154
+ current.addSymbol(new Symbol(child.getChild(0).getText(), void 0, child, nodes.ReferenceType.Rule));
155
+ }
156
+ }
157
+ }
158
+ }
159
+ return true;
160
+ }
161
+ visitVariableDeclarationNode(node) {
162
+ const value = node.getValue() ? node.getValue().getText() : void 0;
163
+ this.addSymbol(node, node.getName(), value, nodes.ReferenceType.Variable);
164
+ return true;
165
+ }
166
+ visitFunctionParameterNode(node) {
167
+ // parameters are part of the body scope
168
+ const scopeNode = node.getParent().getDeclarations();
169
+ if (scopeNode) {
170
+ const valueNode = node.getDefaultValue();
171
+ const value = valueNode ? valueNode.getText() : void 0;
172
+ this.addSymbolToChildScope(scopeNode, node, node.getName(), value, nodes.ReferenceType.Variable);
173
+ }
174
+ return true;
175
+ }
176
+ visitCustomPropertyDeclarationNode(node) {
177
+ const value = node.getValue() ? node.getValue().getText() : '';
178
+ this.addCSSVariable(node.getProperty(), node.getProperty().getName(), value, nodes.ReferenceType.Variable);
179
+ return true;
180
+ }
181
+ addCSSVariable(node, name, value, type) {
182
+ if (node.offset !== -1) {
183
+ this.scope.addSymbol(new Symbol(name, value, node, type));
184
+ }
185
+ }
186
+ }
187
+ export class Symbols {
188
+ constructor(node) {
189
+ this.global = new GlobalScope();
190
+ node.acceptVisitor(new ScopeBuilder(this.global));
191
+ }
192
+ findSymbolsAtOffset(offset, referenceType) {
193
+ let scope = this.global.findScope(offset, 0);
194
+ const result = [];
195
+ const names = {};
196
+ while (scope) {
197
+ const symbols = scope.getSymbols();
198
+ for (let i = 0; i < symbols.length; i++) {
199
+ const symbol = symbols[i];
200
+ if (symbol.type === referenceType && !names[symbol.name]) {
201
+ result.push(symbol);
202
+ names[symbol.name] = true;
203
+ }
204
+ }
205
+ scope = scope.parent;
206
+ }
207
+ return result;
208
+ }
209
+ internalFindSymbol(node, referenceTypes) {
210
+ let scopeNode = node;
211
+ if (node.parent instanceof nodes.FunctionParameter && node.parent.getParent() instanceof nodes.BodyDeclaration) {
212
+ scopeNode = node.parent.getParent().getDeclarations();
213
+ }
214
+ if (node.parent instanceof nodes.FunctionArgument && node.parent.getParent() instanceof nodes.Function) {
215
+ const funcId = node.parent.getParent().getIdentifier();
216
+ if (funcId) {
217
+ const functionSymbol = this.internalFindSymbol(funcId, [nodes.ReferenceType.Function]);
218
+ if (functionSymbol) {
219
+ scopeNode = functionSymbol.node.getDeclarations();
220
+ }
221
+ }
222
+ }
223
+ if (!scopeNode) {
224
+ return null;
225
+ }
226
+ const name = node.getText();
227
+ let scope = this.global.findScope(scopeNode.offset, scopeNode.length);
228
+ while (scope) {
229
+ for (let index = 0; index < referenceTypes.length; index++) {
230
+ const type = referenceTypes[index];
231
+ const symbol = scope.getSymbol(name, type);
232
+ if (symbol) {
233
+ return symbol;
234
+ }
235
+ }
236
+ scope = scope.parent;
237
+ }
238
+ return null;
239
+ }
240
+ evaluateReferenceTypes(node) {
241
+ if (node instanceof nodes.Identifier) {
242
+ const referenceTypes = node.referenceTypes;
243
+ if (referenceTypes) {
244
+ return referenceTypes;
245
+ }
246
+ else {
247
+ if (node.isCustomProperty) {
248
+ return [nodes.ReferenceType.Variable];
249
+ }
250
+ // are a reference to a keyframe?
251
+ const decl = nodes.getParentDeclaration(node);
252
+ if (decl) {
253
+ const propertyName = decl.getNonPrefixedPropertyName();
254
+ if ((propertyName === 'animation' || propertyName === 'animation-name')
255
+ && decl.getValue() && decl.getValue().offset === node.offset) {
256
+ return [nodes.ReferenceType.Keyframe];
257
+ }
258
+ }
259
+ }
260
+ }
261
+ else if (node instanceof nodes.Variable) {
262
+ return [nodes.ReferenceType.Variable];
263
+ }
264
+ const selector = node.findAParent(nodes.NodeType.Selector, nodes.NodeType.ExtendsReference);
265
+ if (selector) {
266
+ return [nodes.ReferenceType.Rule];
267
+ }
268
+ return null;
269
+ }
270
+ findSymbolFromNode(node) {
271
+ if (!node) {
272
+ return null;
273
+ }
274
+ while (node.type === nodes.NodeType.Interpolation) {
275
+ node = node.getParent();
276
+ }
277
+ const referenceTypes = this.evaluateReferenceTypes(node);
278
+ if (referenceTypes) {
279
+ return this.internalFindSymbol(node, referenceTypes);
280
+ }
281
+ return null;
282
+ }
283
+ matchesSymbol(node, symbol) {
284
+ if (!node) {
285
+ return false;
286
+ }
287
+ while (node.type === nodes.NodeType.Interpolation) {
288
+ node = node.getParent();
289
+ }
290
+ if (!node.matches(symbol.name)) {
291
+ return false;
292
+ }
293
+ const referenceTypes = this.evaluateReferenceTypes(node);
294
+ if (!referenceTypes || referenceTypes.indexOf(symbol.type) === -1) {
295
+ return false;
296
+ }
297
+ const nodeSymbol = this.internalFindSymbol(node, referenceTypes);
298
+ return nodeSymbol === symbol;
299
+ }
300
+ findSymbol(name, type, offset) {
301
+ let scope = this.global.findScope(offset);
302
+ while (scope) {
303
+ const symbol = scope.getSymbol(name, type);
304
+ if (symbol) {
305
+ return symbol;
306
+ }
307
+ scope = scope.parent;
308
+ }
309
+ return null;
310
+ }
311
+ }