@@ -53,23 +53,6 @@ class ScopeVisitor with sass.RecursiveStatementVisitor {
53
53
return null ;
54
54
}
55
55
56
- ({int offset, int length})? _scopeRange (
57
- sass.ParentStatement <List <sass.Statement >?> node) {
58
- if (node.children case var children? ) {
59
- if (children.isEmpty) {
60
- return null ;
61
- }
62
-
63
- var totalLength = node.children!
64
- .map <int >((n) => n.span.length)
65
- .reduce ((value, element) => value + element);
66
-
67
- return (offset: children.first.span.start.offset, length: totalLength);
68
- }
69
-
70
- return null ;
71
- }
72
-
73
56
@override
74
57
void visitAtRule (node) {
75
58
if (node.name.isPlain) {
@@ -131,54 +114,14 @@ class ScopeVisitor with sass.RecursiveStatementVisitor {
131
114
132
115
@override
133
116
void visitEachRule (sass.EachRule node) {
134
- var scopeRange = _scopeRange (node);
135
- if (scopeRange != null ) {
136
- var scope = _addScope (
137
- offset: scopeRange.offset,
138
- length: scopeRange.length,
139
- );
140
-
141
- if (scope != null ) {
142
- for (var variable in node.variables) {
143
- var variableIndex = node.span.text.indexOf (variable);
144
-
145
- var range = toRange (node.span);
146
- var selectionRange = lsp.Range (
147
- start: lsp.Position (
148
- line: node.span.start.line,
149
- character: node.span.start.column + variableIndex),
150
- end: lsp.Position (
151
- line: node.span.start.line,
152
- character: node.span.start.column + variable.length,
153
- ),
154
- );
155
-
156
- var symbol = StylesheetDocumentSymbol (
157
- name: variable,
158
- referenceKind: ReferenceKind .variable,
159
- range: range,
160
- children: [],
161
- selectionRange: selectionRange,
162
- );
163
- scope.addSymbol (symbol);
164
- }
165
- }
166
- }
167
-
168
- super .visitEachRule (node);
169
- }
170
-
171
- @override
172
- void visitForRule (sass.ForRule node) {
173
- var scopeRange = _scopeRange (node);
174
- if (scopeRange != null ) {
175
- var scope = _addScope (
176
- offset: scopeRange.offset,
177
- length: scopeRange.length,
178
- );
117
+ var scope = _addScope (
118
+ offset: node.span.start.offset,
119
+ length: node.span.length,
120
+ );
179
121
180
- if (scope != null ) {
181
- var variableIndex = node.span.text.indexOf (node.variable);
122
+ if (scope != null ) {
123
+ for (var variable in node.variables) {
124
+ var variableIndex = node.span.text.indexOf (variable);
182
125
183
126
var range = toRange (node.span);
184
127
var selectionRange = lsp.Range (
@@ -187,12 +130,12 @@ class ScopeVisitor with sass.RecursiveStatementVisitor {
187
130
character: node.span.start.column + variableIndex),
188
131
end: lsp.Position (
189
132
line: node.span.start.line,
190
- character: node.span.start.column + node. variable.length,
133
+ character: node.span.start.column + variable.length,
191
134
),
192
135
);
193
136
194
137
var symbol = StylesheetDocumentSymbol (
195
- name: node. variable,
138
+ name: variable,
196
139
referenceKind: ReferenceKind .variable,
197
140
range: range,
198
141
children: [],
@@ -202,6 +145,40 @@ class ScopeVisitor with sass.RecursiveStatementVisitor {
202
145
}
203
146
}
204
147
148
+ super .visitEachRule (node);
149
+ }
150
+
151
+ @override
152
+ void visitForRule (sass.ForRule node) {
153
+ var scope = _addScope (
154
+ offset: node.span.start.offset,
155
+ length: node.span.length,
156
+ );
157
+
158
+ if (scope != null ) {
159
+ var variableIndex = node.span.text.indexOf (node.variable);
160
+
161
+ var range = toRange (node.span);
162
+ var selectionRange = lsp.Range (
163
+ start: lsp.Position (
164
+ line: node.span.start.line,
165
+ character: node.span.start.column + variableIndex),
166
+ end: lsp.Position (
167
+ line: node.span.start.line,
168
+ character: node.span.start.column + node.variable.length,
169
+ ),
170
+ );
171
+
172
+ var symbol = StylesheetDocumentSymbol (
173
+ name: node.variable,
174
+ referenceKind: ReferenceKind .variable,
175
+ range: range,
176
+ children: [],
177
+ selectionRange: selectionRange,
178
+ );
179
+ scope.addSymbol (symbol);
180
+ }
181
+
205
182
super .visitForRule (node);
206
183
}
207
184
@@ -216,26 +193,23 @@ class ScopeVisitor with sass.RecursiveStatementVisitor {
216
193
length: node.span.length,
217
194
);
218
195
219
- var scopeRange = _scopeRange (node);
220
- if (scopeRange != null ) {
221
- var scope = _addScope (
222
- offset: scopeRange.offset,
223
- length: scopeRange.length,
224
- );
196
+ var scope = _addScope (
197
+ offset: node.span.start.offset,
198
+ length: node.span.length,
199
+ );
225
200
226
- if (scope != null ) {
227
- for (var arg in node.arguments.arguments) {
228
- var range = toRange (arg.span);
229
- var selectionRange = toRange (arg.nameSpan);
230
- var symbol = StylesheetDocumentSymbol (
231
- name: arg.name,
232
- referenceKind: ReferenceKind .variable,
233
- range: range,
234
- children: [],
235
- selectionRange: selectionRange,
236
- );
237
- scope.addSymbol (symbol);
238
- }
201
+ if (scope != null ) {
202
+ for (var arg in node.arguments.arguments) {
203
+ var range = toRange (arg.span);
204
+ var selectionRange = toRange (arg.nameSpan);
205
+ var symbol = StylesheetDocumentSymbol (
206
+ name: arg.name,
207
+ referenceKind: ReferenceKind .variable,
208
+ range: range,
209
+ children: [],
210
+ selectionRange: selectionRange,
211
+ );
212
+ scope.addSymbol (symbol);
239
213
}
240
214
}
241
215
@@ -262,26 +236,22 @@ class ScopeVisitor with sass.RecursiveStatementVisitor {
262
236
length: node.span.length,
263
237
);
264
238
265
- var scopeRange = _scopeRange (node);
266
- if (scopeRange != null ) {
267
- var scope = _addScope (
268
- offset: scopeRange.offset,
269
- length: scopeRange.length,
270
- );
271
-
272
- if (scope != null ) {
273
- for (var arg in node.arguments.arguments) {
274
- var range = toRange (arg.span);
275
- var selectionRange = toRange (arg.nameSpan);
276
- var symbol = StylesheetDocumentSymbol (
277
- name: arg.name,
278
- referenceKind: ReferenceKind .variable,
279
- range: range,
280
- children: [],
281
- selectionRange: selectionRange,
282
- );
283
- scope.addSymbol (symbol);
284
- }
239
+ var scope = _addScope (
240
+ offset: node.span.start.offset,
241
+ length: node.span.length,
242
+ );
243
+ if (scope != null ) {
244
+ for (var arg in node.arguments.arguments) {
245
+ var range = toRange (arg.span);
246
+ var selectionRange = toRange (arg.nameSpan);
247
+ var symbol = StylesheetDocumentSymbol (
248
+ name: arg.name,
249
+ referenceKind: ReferenceKind .variable,
250
+ range: range,
251
+ children: [],
252
+ selectionRange: selectionRange,
253
+ );
254
+ scope.addSymbol (symbol);
285
255
}
286
256
}
287
257
@@ -333,13 +303,10 @@ class ScopeVisitor with sass.RecursiveStatementVisitor {
333
303
}
334
304
}
335
305
336
- var scopeRange = _scopeRange (node);
337
- if (scopeRange != null ) {
338
- _addScope (
339
- offset: scopeRange.offset,
340
- length: scopeRange.length,
341
- );
342
- }
306
+ _addScope (
307
+ offset: node.span.start.offset + node.selector.span.length,
308
+ length: node.span.length - node.selector.span.length,
309
+ );
343
310
} on sass.SassFormatException catch (_) {
344
311
// Do nothing.
345
312
}
@@ -374,13 +341,10 @@ class ScopeVisitor with sass.RecursiveStatementVisitor {
374
341
375
342
@override
376
343
void visitWhileRule (sass.WhileRule node) {
377
- var scopeRange = _scopeRange (node);
378
- if (scopeRange != null ) {
379
- _addScope (
380
- offset: scopeRange.offset,
381
- length: scopeRange.length,
382
- );
383
- }
344
+ _addScope (
345
+ offset: node.span.start.offset,
346
+ length: node.span.length,
347
+ );
384
348
385
349
super .visitWhileRule (node);
386
350
}
0 commit comments