diff options
author | Aleksey Kladov <[email protected]> | 2018-08-13 13:35:53 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-13 13:35:53 +0100 |
commit | d19f3ac83441420365bff5e4ce21d1d2175bd8c2 (patch) | |
tree | 0523dc698784bb2501998956f8111b31f4e0387b /crates/server/src/main_loop/handlers.rs | |
parent | 133d001d8296e51bcb4d0dc0982671f55c2c77d9 (diff) |
workspace symbols
Diffstat (limited to 'crates/server/src/main_loop/handlers.rs')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index 14dcafc38..bd0e6825b 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -2,9 +2,10 @@ use std::collections::HashMap; | |||
2 | 2 | ||
3 | use languageserver_types::{ | 3 | use languageserver_types::{ |
4 | Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, | 4 | Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, |
5 | Command, TextDocumentIdentifier, WorkspaceEdit | 5 | Command, TextDocumentIdentifier, WorkspaceEdit, |
6 | SymbolInformation, Location, | ||
6 | }; | 7 | }; |
7 | use libanalysis::World; | 8 | use libanalysis::{World}; |
8 | use libeditor; | 9 | use libeditor; |
9 | use libsyntax2::TextUnit; | 10 | use libsyntax2::TextUnit; |
10 | use serde_json::{to_value, from_value}; | 11 | use serde_json::{to_value, from_value}; |
@@ -94,6 +95,30 @@ pub fn handle_code_action( | |||
94 | Ok(ret) | 95 | Ok(ret) |
95 | } | 96 | } |
96 | 97 | ||
98 | pub fn handle_workspace_symbol( | ||
99 | world: World, | ||
100 | params: req::WorkspaceSymbolParams, | ||
101 | ) -> Result<Option<Vec<SymbolInformation>>> { | ||
102 | let mut acc = Vec::new(); | ||
103 | for (path, symbol) in world.world_symbols(¶ms.query).take(128) { | ||
104 | let line_index = world.file_line_index(path)?; | ||
105 | |||
106 | let info = SymbolInformation { | ||
107 | name: symbol.name.to_string(), | ||
108 | kind: symbol.kind.conv(), | ||
109 | location: Location::new( | ||
110 | Url::from_file_path(path) | ||
111 | .map_err(|()| format_err!("invalid url"))?, | ||
112 | symbol.node_range.conv_with(&line_index), | ||
113 | ), | ||
114 | container_name: None, | ||
115 | }; | ||
116 | acc.push(info); | ||
117 | }; | ||
118 | |||
119 | Ok(Some(acc)) | ||
120 | } | ||
121 | |||
97 | pub fn handle_execute_command( | 122 | pub fn handle_execute_command( |
98 | world: World, | 123 | world: World, |
99 | mut params: req::ExecuteCommandParams, | 124 | mut params: req::ExecuteCommandParams, |