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