@@ -20,7 +20,7 @@ class DocumentSymbolsVisitor with sass.RecursiveStatementVisitor {
20
20
/// other symbols, and if so adds them as children.
21
21
void _collect (
22
22
{required String name,
23
- required lsp. SymbolKind kind ,
23
+ required ReferenceKind referenceKind ,
24
24
required lsp.Range symbolRange,
25
25
lsp.Range ? nameRange,
26
26
String ? docComment,
@@ -33,15 +33,16 @@ class DocumentSymbolsVisitor with sass.RecursiveStatementVisitor {
33
33
}
34
34
35
35
var symbol = StylesheetDocumentSymbol (
36
- name: name,
37
- kind: kind,
38
- range: range,
39
- children: [],
40
- selectionRange: selectionRange,
41
- docComment: docComment,
42
- detail: detail,
43
- tags: tags,
44
- deprecated: _isDeprecated (docComment));
36
+ name: name,
37
+ referenceKind: referenceKind,
38
+ range: range,
39
+ children: [],
40
+ selectionRange: selectionRange,
41
+ docComment: docComment,
42
+ detail: detail,
43
+ tags: tags,
44
+ deprecated: _isDeprecated (docComment),
45
+ );
45
46
46
47
// Look to see if this symbol contains other symbols.
47
48
@@ -105,40 +106,47 @@ class DocumentSymbolsVisitor with sass.RecursiveStatementVisitor {
105
106
106
107
if (node.name.asPlain == 'font-face' ) {
107
108
_collect (
108
- name: node.name.span.text,
109
- kind: lsp.SymbolKind .Class ,
110
- symbolRange: toRange (node.span),
111
- nameRange: toRange (node.name.span));
109
+ name: node.name.span.text,
110
+ referenceKind: ReferenceKind .fontFace,
111
+ symbolRange: toRange (node.span),
112
+ nameRange: toRange (node.name.span),
113
+ );
112
114
} else if (node.name.asPlain! .startsWith ('keyframes' )) {
113
115
var keyframesName = node.span.context.split (' ' ).elementAtOrNull (1 );
114
116
if (keyframesName != null ) {
115
117
var keyframesNameRange = lsp.Range (
116
- start: lsp.Position (
117
- line: node.name.span.start.line,
118
- character: node.name.span.end.column + 1 ),
119
- end: lsp.Position (
120
- line: node.name.span.end.line,
121
- character:
122
- node.name.span.end.column + 1 + keyframesName.length));
118
+ start: lsp.Position (
119
+ line: node.name.span.start.line,
120
+ character: node.name.span.end.column + 1 ,
121
+ ),
122
+ end: lsp.Position (
123
+ line: node.name.span.end.line,
124
+ character: node.name.span.end.column + 1 + keyframesName.length,
125
+ ),
126
+ );
123
127
124
128
_collect (
125
- name: keyframesName,
126
- kind: lsp.SymbolKind .Class ,
127
- symbolRange: toRange (node.span),
128
- nameRange: keyframesNameRange);
129
+ name: keyframesName,
130
+ referenceKind: ReferenceKind .keyframe,
131
+ symbolRange: toRange (node.span),
132
+ nameRange: keyframesNameRange,
133
+ );
129
134
}
130
135
}
131
136
}
132
137
133
138
@override
134
139
void visitDeclaration (node) {
135
140
super .visitDeclaration (node);
136
- if (node.name.isPlain && node.name.asPlain! .startsWith ("--" )) {
141
+ var isCustomProperty =
142
+ node.name.isPlain && node.name.asPlain! .startsWith ("--" );
143
+ if (isCustomProperty) {
137
144
_collect (
138
- name: node.name.span.text,
139
- kind: lsp.SymbolKind .Variable ,
140
- symbolRange: toRange (node.span),
141
- nameRange: toRange (node.name.span));
145
+ name: node.name.span.text,
146
+ referenceKind: ReferenceKind .customProperty,
147
+ symbolRange: toRange (node.span),
148
+ nameRange: toRange (node.name.span),
149
+ );
142
150
}
143
151
}
144
152
@@ -147,12 +155,13 @@ class DocumentSymbolsVisitor with sass.RecursiveStatementVisitor {
147
155
super .visitFunctionRule (node);
148
156
149
157
_collect (
150
- name: node.name,
151
- detail: _detail (node),
152
- kind: lsp.SymbolKind .Function ,
153
- docComment: node.comment? .docComment,
154
- symbolRange: toRange (node.span),
155
- nameRange: toRange (node.nameSpan));
158
+ name: node.name,
159
+ detail: _detail (node),
160
+ referenceKind: ReferenceKind .function,
161
+ docComment: node.comment? .docComment,
162
+ symbolRange: toRange (node.span),
163
+ nameRange: toRange (node.nameSpan),
164
+ );
156
165
}
157
166
158
167
@override
@@ -164,33 +173,38 @@ class DocumentSymbolsVisitor with sass.RecursiveStatementVisitor {
164
173
165
174
// node.query.span includes whitespace, so the range doesn't match node.query.asPlain
166
175
var nameRange = lsp.Range (
167
- start: lsp.Position (
168
- line: node.span.start.line + node.query.span.start.line,
169
- character: node.span.start.column + node.query.span.start.column),
170
- end: lsp.Position (
171
- line: node.span.start.line + node.query.span.end.line,
172
- character: node.span.start.column +
173
- node.query.span.start.column +
174
- node.query.asPlain! .length));
176
+ start: lsp.Position (
177
+ line: node.span.start.line + node.query.span.start.line,
178
+ character: node.span.start.column + node.query.span.start.column,
179
+ ),
180
+ end: lsp.Position (
181
+ line: node.span.start.line + node.query.span.end.line,
182
+ character: node.span.start.column +
183
+ node.query.span.start.column +
184
+ node.query.asPlain! .length,
185
+ ),
186
+ );
175
187
176
188
_collect (
177
- name: '@media ${node .query .asPlain }' ,
178
- kind: lsp.SymbolKind .Module ,
179
- symbolRange: toRange (node.span),
180
- nameRange: nameRange);
189
+ name: '@media ${node .query .asPlain }' ,
190
+ referenceKind: ReferenceKind .media,
191
+ symbolRange: toRange (node.span),
192
+ nameRange: nameRange,
193
+ );
181
194
}
182
195
183
196
@override
184
197
void visitMixinRule (node) {
185
198
super .visitMixinRule (node);
186
199
187
200
_collect (
188
- name: node.name,
189
- detail: _detail (node),
190
- kind: lsp.SymbolKind .Method ,
191
- docComment: node.comment? .docComment,
192
- symbolRange: toRange (node.span),
193
- nameRange: toRange (node.nameSpan));
201
+ name: node.name,
202
+ detail: _detail (node),
203
+ referenceKind: ReferenceKind .mixin ,
204
+ docComment: node.comment? .docComment,
205
+ symbolRange: toRange (node.span),
206
+ nameRange: toRange (node.nameSpan),
207
+ );
194
208
}
195
209
196
210
@override
@@ -221,38 +235,45 @@ class DocumentSymbolsVisitor with sass.RecursiveStatementVisitor {
221
235
if (nameRange == null ) {
222
236
// The selector span seems to be relative to node, not to the file.
223
237
nameRange = lsp.Range (
224
- start: lsp.Position (
225
- line: node.span.start.line + selector.span.start.line,
226
- character:
227
- node.span.start.column + selector.span.start.column),
228
- end: lsp.Position (
229
- line: node.span.start.line + selector.span.end.line,
230
- character:
231
- node.span.start.column + selector.span.end.column));
238
+ start: lsp.Position (
239
+ line: node.span.start.line + selector.span.start.line,
240
+ character: node.span.start.column + selector.span.start.column,
241
+ ),
242
+ end: lsp.Position (
243
+ line: node.span.start.line + selector.span.end.line,
244
+ character: node.span.start.column + selector.span.end.column,
245
+ ),
246
+ );
232
247
233
248
// symbolRange: start position of selector's nameRange, end of stylerule (node.span.end).
234
249
symbolRange = lsp.Range (
235
- start: lsp.Position (
236
- line: nameRange.start.line,
237
- character: nameRange.start.character),
238
- end: lsp.Position (
239
- line: node.span.end.line, character: node.span.end.column));
250
+ start: lsp.Position (
251
+ line: nameRange.start.line,
252
+ character: nameRange.start.character,
253
+ ),
254
+ end: lsp.Position (
255
+ line: node.span.end.line,
256
+ character: node.span.end.column,
257
+ ),
258
+ );
240
259
} else {
241
260
// Move the end of the name range down to include this selector component
242
261
nameRange = lsp.Range (
243
- start: nameRange.start,
244
- end: lsp.Position (
245
- line: node.span.start.line + selector.span.end.line,
246
- character:
247
- node.span.start.column + selector.span.end.column));
262
+ start: nameRange.start,
263
+ end: lsp.Position (
264
+ line: node.span.start.line + selector.span.end.line,
265
+ character: node.span.start.column + selector.span.end.column,
266
+ ),
267
+ );
248
268
}
249
269
}
250
270
251
271
_collect (
252
- name: name! ,
253
- kind: lsp.SymbolKind .Class ,
254
- symbolRange: symbolRange! ,
255
- nameRange: nameRange);
272
+ name: name! ,
273
+ referenceKind: ReferenceKind .selector,
274
+ symbolRange: symbolRange! ,
275
+ nameRange: nameRange,
276
+ );
256
277
}
257
278
} on sass.SassFormatException catch (_) {
258
279
// Do nothing.
@@ -263,17 +284,21 @@ class DocumentSymbolsVisitor with sass.RecursiveStatementVisitor {
263
284
void visitVariableDeclaration (node) {
264
285
super .visitVariableDeclaration (node);
265
286
_collect (
266
- name: node.nameSpan.text,
267
- kind: lsp.SymbolKind .Variable ,
268
- docComment: node.comment? .docComment,
269
- symbolRange: toRange (node.span),
270
- nameRange: lsp.Range (
271
- start: lsp.Position (
272
- line: node.nameSpan.start.line,
273
- // the span includes $
274
- character: node.nameSpan.start.column),
275
- end: lsp.Position (
276
- line: node.nameSpan.end.line,
277
- character: node.nameSpan.end.column)));
287
+ name: node.nameSpan.text,
288
+ referenceKind: ReferenceKind .variable,
289
+ docComment: node.comment? .docComment,
290
+ symbolRange: toRange (node.span),
291
+ nameRange: lsp.Range (
292
+ start: lsp.Position (
293
+ line: node.nameSpan.start.line,
294
+ // the span includes $
295
+ character: node.nameSpan.start.column,
296
+ ),
297
+ end: lsp.Position (
298
+ line: node.nameSpan.end.line,
299
+ character: node.nameSpan.end.column,
300
+ ),
301
+ ),
302
+ );
278
303
}
279
304
}
0 commit comments