Skip to content

Commit

Permalink
Docstring formating, Sass built-in hover
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Dec 16, 2024
1 parent 3263abf commit 0eb04d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class GoToDefinitionFeature extends LanguageFeature {
}
} on StateError {
return null;
} on UnsupportedError {
// The target URI scheme may be unsupported.
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,11 @@ $browsers
var range = toRange(node.nameSpan);

var definition = await internalGoToDefinition(document, range.start);
if (definition == null) {
return null;
}

if (definition.location == null) {
if (definition == null || definition.location == null) {
// If we don't have a location we are likely dealing with a built-in.
for (var module in _sassData.modules) {
for (var variable in module.variables) {
if (variable.name == definition.name) {
if ('\$${variable.name}' == name) {
if (_supportsMarkdown()) {
var contents = _asMarkdown('''
${variable.description}
Expand Down Expand Up @@ -298,13 +294,13 @@ ${variable.description}
if (_supportsMarkdown()) {
var contents = _asMarkdown('''
```${document.languageId}
${docComment != null ? '$docComment\n' : ''}$name: ${resolvedValue ?? rawValue}${document.languageId != 'sass' ? ';' : ''}
```
$name: ${resolvedValue ?? rawValue}${document.languageId != 'sass' ? ';' : ''}
```${docComment != null ? '\n____\n${docComment.replaceAll('\n', '\n\n')}\n\n' : ''}
''');
return lsp.Hover(contents: contents, range: range);
} else {
var contents = _asPlaintext('''
${docComment != null ? '$docComment\n' : ''}$name: ${resolvedValue ?? rawValue}${document.languageId != 'sass' ? ';' : ''}
$name: ${resolvedValue ?? rawValue}${document.languageId != 'sass' ? ';' : ''}${docComment != null ? '\n\n$docComment' : ''}
''');
return lsp.Hover(contents: contents, range: range);
}
Expand All @@ -316,15 +312,11 @@ ${docComment != null ? '$docComment\n' : ''}$name: ${resolvedValue ?? rawValue}$
var range = toRange(node.nameSpan);

var definition = await internalGoToDefinition(document, range.start);
if (definition == null) {
return null;
}

if (definition.location == null) {
// If we don't have a location we are likely dealing with a built-in.
if (definition == null || definition.location == null) {
// If we don't have a location we may be dealing with a built-in.
for (var module in _sassData.modules) {
for (var function in module.functions) {
if (function.name == definition.name) {
if (function.name == name) {
if (_supportsMarkdown()) {
var contents = _asMarkdown('''
${function.description}
Expand Down Expand Up @@ -366,14 +358,14 @@ ${function.description}

if (_supportsMarkdown()) {
var contents = _asMarkdown('''
${docComment != null ? '$docComment\n' : ''}```${document.languageId}
```${document.languageId}
@function $name$arguments
```
```${docComment != null ? '\n____\n${docComment.replaceAll('\n', '\n\n')}\n\n' : ''}
''');
return lsp.Hover(contents: contents, range: range);
} else {
var contents = _asPlaintext('''
${docComment != null ? '$docComment\n' : ''}@function $name$arguments
@function $name$arguments${docComment != null ? '\n\n$docComment' : ''}
''');
return lsp.Hover(contents: contents, range: range);
}
Expand Down Expand Up @@ -413,14 +405,14 @@ ${docComment != null ? '$docComment\n' : ''}@function $name$arguments

if (_supportsMarkdown()) {
var contents = _asMarkdown('''
${docComment != null ? '$docComment\n' : ''}```${document.languageId}
```${document.languageId}
@mixin $name$arguments
```
```${docComment != null ? '\n____\n${docComment.replaceAll('\n', '\n\n')}\n\n' : ''}
''');
return lsp.Hover(contents: contents, range: range);
} else {
var contents = _asPlaintext('''
${docComment != null ? '$docComment\n' : ''}@mixin $name$arguments
@mixin $name$arguments${docComment != null ? '\n\n$docComment' : ''}
''');
return lsp.Hover(contents: contents, range: range);
}
Expand Down
22 changes: 18 additions & 4 deletions pkgs/sass_language_services/test/features/hover/hover_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ $border-width: rem(1px);

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

test('math function', () async {
Expand All @@ -426,8 +426,22 @@ $border-width: rem(1px);
var result = await ls.hover(document, at(line: 2, char: 14));
expect(result, isNotNull);
expect(getContents(result),
contains(r'Rounds up to the nearest whole number'));
expect(getContents(result), contains(r'sass-lang.com'));
contains('Rounds up to the nearest whole number'));
expect(getContents(result), contains('sass-lang.com'));
});

test('function as variable expression', () async {
var document = fs.createDocument(r'''
@use "sass:string";
$_id: string.unique-id();
''');

var result = await ls.hover(document, at(line: 2, char: 14));
expect(result, isNotNull);
expect(getContents(result),
contains('Returns a randomly-generated unquoted string'));
expect(getContents(result), contains('sass-lang.com'));
});
});
}

0 comments on commit 0eb04d4

Please sign in to comment.