File tree Expand file tree Collapse file tree 4 files changed +64
-0
lines changed
sass_language_server/lib/src
sass_language_services/lib/src
features/workspace_symbols Expand file tree Collapse file tree 4 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ class LanguageServer {
173
173
documentLinkProvider: DocumentLinkOptions (resolveProvider: false ),
174
174
documentSymbolProvider: Either2 .t1 (true ),
175
175
textDocumentSync: Either2 .t1 (TextDocumentSyncKind .Incremental ),
176
+ workspaceSymbolProvider: Either2 .t1 (true ),
176
177
);
177
178
178
179
var result = InitializeResult (capabilities: serverCapabilities);
@@ -285,6 +286,22 @@ class LanguageServer {
285
286
_connection.peer
286
287
.registerMethod ('textDocument/documentSymbol' , onDocumentSymbol);
287
288
289
+ // TODO: add this handler upstream
290
+ Future <List <WorkspaceSymbol >> onWorkspaceSymbol (dynamic params) async {
291
+ try {
292
+ var query =
293
+ (params.value as Map <String , Object ?>)['query' ] as String ? ;
294
+
295
+ var result = _ls.findWorkspaceSymbols (query);
296
+ return result;
297
+ } on Exception catch (e) {
298
+ _log.debug (e.toString ());
299
+ return [];
300
+ }
301
+ }
302
+
303
+ _connection.peer.registerMethod ('workspace/symbol' , onWorkspaceSymbol);
304
+
288
305
_connection.onShutdown (() async {
289
306
await _socket? .close ();
290
307
exitCode = 0 ;
Original file line number Diff line number Diff line change @@ -12,14 +12,21 @@ class DocumentLinksConfiguration extends FeatureConfiguration {
12
12
DocumentLinksConfiguration ({required super .enabled});
13
13
}
14
14
15
+ class WorkspaceSymbolsConfiguration extends FeatureConfiguration {
16
+ WorkspaceSymbolsConfiguration ({required super .enabled});
17
+ }
18
+
15
19
class LanguageConfiguration {
16
20
late final DocumentSymbolsConfiguration documentSymbols;
17
21
late final DocumentLinksConfiguration documentLinks;
22
+ late final WorkspaceSymbolsConfiguration workspaceSymbols;
18
23
19
24
LanguageConfiguration .from (dynamic config) {
20
25
documentSymbols = DocumentSymbolsConfiguration (
21
26
enabled: config? ['documentSymbols' ]? ['enabled' ] as bool ? ?? true );
22
27
documentLinks = DocumentLinksConfiguration (
23
28
enabled: config? ['documentLinks' ]? ['enabled' ] as bool ? ?? true );
29
+ workspaceSymbols = WorkspaceSymbolsConfiguration (
30
+ enabled: config? ['workspaceSymbols' ]? ['enabled' ] as bool ? ?? true );
24
31
}
25
32
}
Original file line number Diff line number Diff line change
1
+ import 'package:lsp_server/lsp_server.dart' as lsp;
2
+
3
+ import '../language_feature.dart' ;
4
+
5
+ class WorkspaceSymbolsFeature extends LanguageFeature {
6
+ WorkspaceSymbolsFeature ({required super .ls});
7
+
8
+ List <lsp.WorkspaceSymbol > findWorkspaceSymbols (String ? query) {
9
+ var result = < lsp.WorkspaceSymbol > [];
10
+ for (var document in ls.cache.getDocuments ()) {
11
+ // This is the exception to the rule that this enabled check
12
+ // should happen at the server edge. It's only at this point
13
+ // we know if the document should be included or not.
14
+ var config = getLanguageConfiguration (document);
15
+ if (config.workspaceSymbols.enabled) {
16
+ var symbols = ls.findDocumentSymbols (document);
17
+ for (var symbol in symbols) {
18
+ if (query != null && ! symbol.name.contains (query)) {
19
+ continue ;
20
+ }
21
+
22
+ result.add (lsp.WorkspaceSymbol (
23
+ kind: symbol.kind,
24
+ location: lsp.Either2 .t1 (
25
+ lsp.Location (range: symbol.range, uri: document.uri)),
26
+ name: symbol.name,
27
+ tags: symbol.tags));
28
+ }
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import 'package:sass_language_services/sass_language_services.dart';
4
4
5
5
import 'features/document_links/document_links_feature.dart' ;
6
6
import 'features/document_symbols/document_symbols_feature.dart' ;
7
+ import 'features/workspace_symbols/workspace_symbols_feature.dart' ;
7
8
import 'language_services_cache.dart' ;
8
9
9
10
class LanguageServices {
@@ -16,13 +17,15 @@ class LanguageServices {
16
17
17
18
late final DocumentLinksFeature _documentLinks;
18
19
late final DocumentSymbolsFeature _documentSymbols;
20
+ late final WorkspaceSymbolsFeature _workspaceSymbols;
19
21
20
22
LanguageServices ({
21
23
required this .clientCapabilities,
22
24
required this .fs,
23
25
}) : cache = LanguageServicesCache () {
24
26
_documentLinks = DocumentLinksFeature (ls: this );
25
27
_documentSymbols = DocumentSymbolsFeature (ls: this );
28
+ _workspaceSymbols = WorkspaceSymbolsFeature (ls: this );
26
29
}
27
30
28
31
void configure (LanguageServerConfiguration configuration) {
@@ -38,6 +41,10 @@ class LanguageServices {
38
41
return _documentSymbols.findDocumentSymbols (document);
39
42
}
40
43
44
+ List <lsp.WorkspaceSymbol > findWorkspaceSymbols (String ? query) {
45
+ return _workspaceSymbols.findWorkspaceSymbols (query);
46
+ }
47
+
41
48
sass.Stylesheet parseStylesheet (TextDocument document) {
42
49
return cache.getStylesheet (document);
43
50
}
You can’t perform that action at this time.
0 commit comments