diff options
author | Aleksey Kladov <[email protected]> | 2018-08-13 14:35:17 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-13 14:35:17 +0100 |
commit | 8ae56fa6d0e8a03d6ad75919d6be953f5fc27083 (patch) | |
tree | d93a4f3e1d279a27cc851546796bb488edfe2c65 /crates/server/src/main_loop/handlers.rs | |
parent | 7fc91f41d8bd948cef3085d7c0d0ec92d1b2bc53 (diff) |
Stupid goto definition
Diffstat (limited to 'crates/server/src/main_loop/handlers.rs')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 27 |
1 files changed, 19 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, |