-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing details about hide/show and prefix
Make the LSP internal data type match better the one from sass_api
- Loading branch information
Showing
7 changed files
with
145 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
pkgs/sass_language_services/test/features/document_links/document_links_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import 'package:sass_language_services/sass_language_services.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../../memory_file_system.dart'; | ||
import '../../test_client_capabilities.dart'; | ||
|
||
final fs = MemoryFileSystem(); | ||
final ls = LanguageServices(fs: fs, clientCapabilities: getCapabilities()); | ||
|
||
void main() { | ||
group('Document links', () { | ||
test('should resolve valid links', () async { | ||
fs.createDocument('\$var: 1px;', uri: 'variables.scss'); | ||
fs.createDocument('\$tr: 2px;', uri: 'corners.scss'); | ||
fs.createDocument('\$b: #000;', uri: 'colors.scss'); | ||
|
||
var document = fs.createDocument(''' | ||
@use "corners" as *; | ||
@use "variables" as vars; | ||
@forward "colors" as color-* hide \$foo, barfunc; | ||
@forward "./does-not-exist" as foo-* show \$public; | ||
'''); | ||
|
||
var links = await ls.findDocumentLinks(document); | ||
expect(links.length, 4); | ||
|
||
var use = links.where((link) => link.type == LinkType.use); | ||
var forward = links.where((link) => link.type == LinkType.forward); | ||
|
||
expect(use.length, 2); | ||
expect(forward.length, 2); | ||
|
||
expect(use.last.namespace, 'vars'); | ||
expect(use.first.namespace, null, | ||
reason: 'Expected wildcard @use not to have a namespace'); | ||
|
||
expect(forward.last.shownVariables, {'public'}); | ||
expect(forward.first.hiddenVariables, {'foo'}); | ||
expect(forward.first.hiddenMixinsAndFunctions, {'barfunc'}); | ||
expect(forward.first.prefix, 'color-'); | ||
expect(forward.last.prefix, 'foo-'); | ||
|
||
expect(use.first.target != null, true); | ||
expect(use.last.target != null, true); | ||
expect(forward.first.target != null, true); | ||
|
||
expect(forward.last.target != null, true, | ||
reason: | ||
'Expected to have a target even though the file does not exist in our file system.'); | ||
}); | ||
|
||
test('should resolve various relative links', () async { | ||
fs.createDocument('\$var: 1px;', uri: 'upper.scss'); | ||
fs.createDocument('\$tr: 2px;', uri: 'middle/middle.scss'); | ||
fs.createDocument('\$b: #000;', uri: 'middle/lower/lower.scss'); | ||
|
||
var document = fs.createDocument(''' | ||
@use "../upper"; | ||
@use "./middle"; | ||
@use "./lower/lower"; | ||
''', uri: 'middle/main.scss'); | ||
|
||
var links = await ls.findDocumentLinks(document); | ||
|
||
equals(links.length, 3); | ||
}); | ||
|
||
test('should not break on circular references', () async { | ||
fs.createDocument(''' | ||
@use "./pong" | ||
\$var: ping | ||
''', uri: 'ping.sass'); | ||
|
||
var document = fs.createDocument(''' | ||
@use "./pong" | ||
\$var: ping | ||
''', uri: 'ping.sass'); | ||
|
||
var links = await ls.findDocumentLinks(document); | ||
|
||
expect(links.length, 1); | ||
}); | ||
|
||
// TODO: tests for partials | ||
// TODO: test for CSS imports (@import 'foo.css') | ||
// TODO: test for Sass imports (with and without string quotes) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
pkgs/sass_language_services/test/test_client_capabilities.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:lsp_server/lsp_server.dart'; | ||
|
||
/// Get a reasonable default for client capabilities for tests. | ||
ClientCapabilities getCapabilities() { | ||
return ClientCapabilities( | ||
textDocument: TextDocumentClientCapabilities( | ||
completion: CompletionClientCapabilities( | ||
completionItem: CompletionClientCapabilitiesCompletionItem( | ||
snippetSupport: true, | ||
documentationFormat: [MarkupKind.Markdown, MarkupKind.PlainText], | ||
), | ||
), | ||
hover: HoverClientCapabilities( | ||
contentFormat: [MarkupKind.Markdown, MarkupKind.PlainText]))); | ||
} |