vscode-css-languageservice 6.0.1 → 6.1.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 +3 -1
  2. package/SECURITY.md +41 -0
  3. package/lib/esm/beautify/beautify-css.js +11 -4
  4. package/lib/esm/cssLanguageService.d.ts +38 -37
  5. package/lib/esm/cssLanguageService.js +73 -72
  6. package/lib/esm/cssLanguageTypes.d.ts +238 -238
  7. package/lib/esm/cssLanguageTypes.js +42 -42
  8. package/lib/esm/data/webCustomData.js +22089 -21959
  9. package/lib/esm/languageFacts/builtinData.js +142 -142
  10. package/lib/esm/languageFacts/colors.js +469 -469
  11. package/lib/esm/languageFacts/dataManager.js +88 -88
  12. package/lib/esm/languageFacts/dataProvider.js +73 -73
  13. package/lib/esm/languageFacts/entry.js +137 -137
  14. package/lib/esm/languageFacts/facts.js +8 -8
  15. package/lib/esm/parser/cssErrors.js +48 -48
  16. package/lib/esm/parser/cssNodes.js +1511 -1502
  17. package/lib/esm/parser/cssParser.js +1606 -1534
  18. package/lib/esm/parser/cssScanner.js +592 -592
  19. package/lib/esm/parser/cssSymbolScope.js +311 -311
  20. package/lib/esm/parser/lessParser.js +715 -714
  21. package/lib/esm/parser/lessScanner.js +57 -57
  22. package/lib/esm/parser/scssErrors.js +18 -18
  23. package/lib/esm/parser/scssParser.js +806 -796
  24. package/lib/esm/parser/scssScanner.js +95 -95
  25. package/lib/esm/services/cssCodeActions.js +77 -77
  26. package/lib/esm/services/cssCompletion.js +1054 -1054
  27. package/lib/esm/services/cssFolding.js +190 -190
  28. package/lib/esm/services/cssFormatter.js +136 -136
  29. package/lib/esm/services/cssHover.js +148 -148
  30. package/lib/esm/services/cssNavigation.js +441 -378
  31. package/lib/esm/services/cssSelectionRange.js +47 -47
  32. package/lib/esm/services/cssValidation.js +41 -41
  33. package/lib/esm/services/lessCompletion.js +378 -378
  34. package/lib/esm/services/lint.js +518 -518
  35. package/lib/esm/services/lintRules.js +76 -76
  36. package/lib/esm/services/lintUtil.js +196 -196
  37. package/lib/esm/services/pathCompletion.js +157 -157
  38. package/lib/esm/services/scssCompletion.js +354 -354
  39. package/lib/esm/services/scssNavigation.js +82 -82
  40. package/lib/esm/services/selectorPrinting.js +492 -492
  41. package/lib/esm/utils/arrays.js +40 -40
  42. package/lib/esm/utils/objects.js +11 -11
  43. package/lib/esm/utils/resources.js +11 -11
  44. package/lib/esm/utils/strings.js +102 -102
  45. package/lib/umd/beautify/beautify-css.js +11 -4
  46. package/lib/umd/cssLanguageService.d.ts +38 -37
  47. package/lib/umd/cssLanguageService.js +104 -99
  48. package/lib/umd/cssLanguageTypes.d.ts +238 -238
  49. package/lib/umd/cssLanguageTypes.js +89 -89
  50. package/lib/umd/data/webCustomData.js +22102 -21972
  51. package/lib/umd/languageFacts/builtinData.js +154 -154
  52. package/lib/umd/languageFacts/colors.js +492 -492
  53. package/lib/umd/languageFacts/dataManager.js +101 -101
  54. package/lib/umd/languageFacts/dataProvider.js +86 -86
  55. package/lib/umd/languageFacts/entry.js +152 -152
  56. package/lib/umd/languageFacts/facts.js +33 -29
  57. package/lib/umd/parser/cssErrors.js +61 -61
  58. package/lib/umd/parser/cssNodes.js +1597 -1587
  59. package/lib/umd/parser/cssParser.js +1619 -1547
  60. package/lib/umd/parser/cssScanner.js +606 -606
  61. package/lib/umd/parser/cssSymbolScope.js +328 -328
  62. package/lib/umd/parser/lessParser.js +728 -727
  63. package/lib/umd/parser/lessScanner.js +70 -70
  64. package/lib/umd/parser/scssErrors.js +31 -31
  65. package/lib/umd/parser/scssParser.js +819 -809
  66. package/lib/umd/parser/scssScanner.js +108 -108
  67. package/lib/umd/services/cssCodeActions.js +90 -90
  68. package/lib/umd/services/cssCompletion.js +1067 -1067
  69. package/lib/umd/services/cssFolding.js +203 -203
  70. package/lib/umd/services/cssFormatter.js +150 -150
  71. package/lib/umd/services/cssHover.js +161 -161
  72. package/lib/umd/services/cssNavigation.js +454 -391
  73. package/lib/umd/services/cssSelectionRange.js +60 -60
  74. package/lib/umd/services/cssValidation.js +54 -54
  75. package/lib/umd/services/lessCompletion.js +391 -391
  76. package/lib/umd/services/lint.js +531 -531
  77. package/lib/umd/services/lintRules.js +91 -91
  78. package/lib/umd/services/lintUtil.js +210 -210
  79. package/lib/umd/services/pathCompletion.js +171 -171
  80. package/lib/umd/services/scssCompletion.js +367 -367
  81. package/lib/umd/services/scssNavigation.js +95 -95
  82. package/lib/umd/services/selectorPrinting.js +510 -510
  83. package/lib/umd/utils/arrays.js +55 -55
  84. package/lib/umd/utils/objects.js +25 -25
  85. package/lib/umd/utils/resources.js +26 -26
  86. package/lib/umd/utils/strings.js +120 -120
  87. package/package.json +13 -12
@@ -1,311 +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
- 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
- }
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
+ }