diff options
Diffstat (limited to 'crates/server/src/main_loop')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 27 | ||||
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 4 |
2 files changed, 23 insertions, 8 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index f51909280..e9dc78420 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -3,7 +3,7 @@ use std::collections::HashMap; | |||
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 | SymbolInformation, |
7 | }; | 7 | }; |
8 | use libanalysis::{World, Query}; | 8 | use libanalysis::{World, Query}; |
9 | use libeditor; | 9 | use libeditor; |
@@ -13,7 +13,7 @@ use serde_json::{to_value, from_value}; | |||
13 | use ::{ | 13 | use ::{ |
14 | req::{self, Decoration}, Result, | 14 | req::{self, Decoration}, Result, |
15 | util::FilePath, | 15 | util::FilePath, |
16 | conv::{Conv, ConvWith, MapConvWith}, | 16 | conv::{Conv, ConvWith, TryConvWith, MapConvWith}, |
17 | }; | 17 | }; |
18 | 18 | ||
19 | pub fn handle_syntax_tree( | 19 | pub fn handle_syntax_tree( |
@@ -115,15 +115,10 @@ pub fn handle_workspace_symbol( | |||
115 | 115 | ||
116 | for (path, symbol) in world.world_symbols(query).take(128) { | 116 | for (path, symbol) in world.world_symbols(query).take(128) { |
117 | let line_index = world.file_line_index(path)?; | 117 | let line_index = world.file_line_index(path)?; |
118 | |||
119 | let info = SymbolInformation { | 118 | let info = SymbolInformation { |
120 | name: symbol.name.to_string(), | 119 | name: symbol.name.to_string(), |
121 | kind: symbol.kind.conv(), | 120 | kind: symbol.kind.conv(), |
122 | location: Location::new( | 121 | location: (path, symbol.node_range).try_conv_with(&line_index)?, |
123 | Url::from_file_path(path) | ||
124 | .map_err(|()| format_err!("invalid url"))?, | ||
125 | symbol.node_range.conv_with(&line_index), | ||
126 | ), | ||
127 | container_name: None, | 122 | container_name: None, |
128 | }; | 123 | }; |
129 | acc.push(info); | 124 | acc.push(info); |
@@ -132,6 +127,22 @@ pub fn handle_workspace_symbol( | |||
132 | Ok(Some(acc)) | 127 | Ok(Some(acc)) |
133 | } | 128 | } |
134 | 129 | ||
130 | pub fn handle_goto_definition( | ||
131 | world: World, | ||
132 | params: req::TextDocumentPositionParams, | ||
133 | ) -> Result<Option<req::GotoDefinitionResponse>> { | ||
134 | let path = params.text_document.file_path()?; | ||
135 | let line_index = world.file_line_index(&path)?; | ||
136 | let offset = params.position.conv_with(&line_index); | ||
137 | let mut res = Vec::new(); | ||
138 | for (path, symbol) in world.approximately_resolve_symbol(&path, offset)? { | ||
139 | let line_index = world.file_line_index(path)?; | ||
140 | let location = (path, symbol.node_range).try_conv_with(&line_index)?; | ||
141 | res.push(location) | ||
142 | } | ||
143 | Ok(Some(req::GotoDefinitionResponse::Array(res))) | ||
144 | } | ||
145 | |||
135 | pub fn handle_execute_command( | 146 | pub fn handle_execute_command( |
136 | world: World, | 147 | world: World, |
137 | mut params: req::ExecuteCommandParams, | 148 | mut params: req::ExecuteCommandParams, |
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index e8b24355c..bc898c17b 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -26,6 +26,7 @@ use { | |||
26 | handle_code_action, | 26 | handle_code_action, |
27 | handle_execute_command, | 27 | handle_execute_command, |
28 | handle_workspace_symbol, | 28 | handle_workspace_symbol, |
29 | handle_goto_definition, | ||
29 | }, | 30 | }, |
30 | }; | 31 | }; |
31 | 32 | ||
@@ -152,6 +153,9 @@ fn on_request( | |||
152 | handle_request_on_threadpool::<req::WorkspaceSymbol>( | 153 | handle_request_on_threadpool::<req::WorkspaceSymbol>( |
153 | &mut req, pool, world, sender, handle_workspace_symbol, | 154 | &mut req, pool, world, sender, handle_workspace_symbol, |
154 | )?; | 155 | )?; |
156 | handle_request_on_threadpool::<req::GotoDefinition>( | ||
157 | &mut req, pool, world, sender, handle_goto_definition, | ||
158 | )?; | ||
155 | dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { | 159 | dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { |
156 | io.send(RawMsg::Response(resp.into_response(Ok(None))?)); | 160 | io.send(RawMsg::Response(resp.into_response(Ok(None))?)); |
157 | 161 | ||