Skip to content

Commit 0eb04d4

Browse files
committed
Docstring formating, Sass built-in hover
1 parent 3263abf commit 0eb04d4

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

pkgs/sass_language_services/lib/src/features/go_to_definition/go_to_definition_feature.dart

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class GoToDefinitionFeature extends LanguageFeature {
105105
}
106106
} on StateError {
107107
return null;
108+
} on UnsupportedError {
109+
// The target URI scheme may be unsupported.
110+
return null;
108111
}
109112
}
110113

pkgs/sass_language_services/lib/src/features/hover/hover_feature.dart

+14-22
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,11 @@ $browsers
239239
var range = toRange(node.nameSpan);
240240

241241
var definition = await internalGoToDefinition(document, range.start);
242-
if (definition == null) {
243-
return null;
244-
}
245-
246-
if (definition.location == null) {
242+
if (definition == null || definition.location == null) {
247243
// If we don't have a location we are likely dealing with a built-in.
248244
for (var module in _sassData.modules) {
249245
for (var variable in module.variables) {
250-
if (variable.name == definition.name) {
246+
if ('\$${variable.name}' == name) {
251247
if (_supportsMarkdown()) {
252248
var contents = _asMarkdown('''
253249
${variable.description}
@@ -298,13 +294,13 @@ ${variable.description}
298294
if (_supportsMarkdown()) {
299295
var contents = _asMarkdown('''
300296
```${document.languageId}
301-
${docComment != null ? '$docComment\n' : ''}$name: ${resolvedValue ?? rawValue}${document.languageId != 'sass' ? ';' : ''}
302-
```
297+
$name: ${resolvedValue ?? rawValue}${document.languageId != 'sass' ? ';' : ''}
298+
```${docComment != null ? '\n____\n${docComment.replaceAll('\n', '\n\n')}\n\n' : ''}
303299
''');
304300
return lsp.Hover(contents: contents, range: range);
305301
} else {
306302
var contents = _asPlaintext('''
307-
${docComment != null ? '$docComment\n' : ''}$name: ${resolvedValue ?? rawValue}${document.languageId != 'sass' ? ';' : ''}
303+
$name: ${resolvedValue ?? rawValue}${document.languageId != 'sass' ? ';' : ''}${docComment != null ? '\n\n$docComment' : ''}
308304
''');
309305
return lsp.Hover(contents: contents, range: range);
310306
}
@@ -316,15 +312,11 @@ ${docComment != null ? '$docComment\n' : ''}$name: ${resolvedValue ?? rawValue}$
316312
var range = toRange(node.nameSpan);
317313

318314
var definition = await internalGoToDefinition(document, range.start);
319-
if (definition == null) {
320-
return null;
321-
}
322-
323-
if (definition.location == null) {
324-
// If we don't have a location we are likely dealing with a built-in.
315+
if (definition == null || definition.location == null) {
316+
// If we don't have a location we may be dealing with a built-in.
325317
for (var module in _sassData.modules) {
326318
for (var function in module.functions) {
327-
if (function.name == definition.name) {
319+
if (function.name == name) {
328320
if (_supportsMarkdown()) {
329321
var contents = _asMarkdown('''
330322
${function.description}
@@ -366,14 +358,14 @@ ${function.description}
366358

367359
if (_supportsMarkdown()) {
368360
var contents = _asMarkdown('''
369-
${docComment != null ? '$docComment\n' : ''}```${document.languageId}
361+
```${document.languageId}
370362
@function $name$arguments
371-
```
363+
```${docComment != null ? '\n____\n${docComment.replaceAll('\n', '\n\n')}\n\n' : ''}
372364
''');
373365
return lsp.Hover(contents: contents, range: range);
374366
} else {
375367
var contents = _asPlaintext('''
376-
${docComment != null ? '$docComment\n' : ''}@function $name$arguments
368+
@function $name$arguments${docComment != null ? '\n\n$docComment' : ''}
377369
''');
378370
return lsp.Hover(contents: contents, range: range);
379371
}
@@ -413,14 +405,14 @@ ${docComment != null ? '$docComment\n' : ''}@function $name$arguments
413405

414406
if (_supportsMarkdown()) {
415407
var contents = _asMarkdown('''
416-
${docComment != null ? '$docComment\n' : ''}```${document.languageId}
408+
```${document.languageId}
417409
@mixin $name$arguments
418-
```
410+
```${docComment != null ? '\n____\n${docComment.replaceAll('\n', '\n\n')}\n\n' : ''}
419411
''');
420412
return lsp.Hover(contents: contents, range: range);
421413
} else {
422414
var contents = _asPlaintext('''
423-
${docComment != null ? '$docComment\n' : ''}@mixin $name$arguments
415+
@mixin $name$arguments${docComment != null ? '\n\n$docComment' : ''}
424416
''');
425417
return lsp.Hover(contents: contents, range: range);
426418
}

pkgs/sass_language_services/test/features/hover/hover_test.dart

+18-4
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ $border-width: rem(1px);
412412

413413
var result = await ls.hover(document, at(line: 2, char: 14));
414414
expect(result, isNotNull);
415-
expect(getContents(result), contains(r'π'));
416-
expect(getContents(result), contains(r'sass-lang.com'));
415+
expect(getContents(result), contains('π'));
416+
expect(getContents(result), contains('sass-lang.com'));
417417
});
418418

419419
test('math function', () async {
@@ -426,8 +426,22 @@ $border-width: rem(1px);
426426
var result = await ls.hover(document, at(line: 2, char: 14));
427427
expect(result, isNotNull);
428428
expect(getContents(result),
429-
contains(r'Rounds up to the nearest whole number'));
430-
expect(getContents(result), contains(r'sass-lang.com'));
429+
contains('Rounds up to the nearest whole number'));
430+
expect(getContents(result), contains('sass-lang.com'));
431+
});
432+
433+
test('function as variable expression', () async {
434+
var document = fs.createDocument(r'''
435+
@use "sass:string";
436+
437+
$_id: string.unique-id();
438+
''');
439+
440+
var result = await ls.hover(document, at(line: 2, char: 14));
441+
expect(result, isNotNull);
442+
expect(getContents(result),
443+
contains('Returns a randomly-generated unquoted string'));
444+
expect(getContents(result), contains('sass-lang.com'));
431445
});
432446
});
433447
}

0 commit comments

Comments
 (0)