diff options
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 11 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 37 |
2 files changed, 27 insertions, 21 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 618486250..1107ffc8b 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -2,7 +2,7 @@ use languageserver_types::{ | |||
2 | self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, | 2 | self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, |
3 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat, | 3 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat, |
4 | }; | 4 | }; |
5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition,FileRange, CompletionItem, CompletionItemKind, InsertText}; | 5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition,FileRange, CompletionItem, CompletionItemKind, InsertText, NavigationTarget}; |
6 | use ra_editor::{LineCol, LineIndex, translate_offset_with_edit}; | 6 | use ra_editor::{LineCol, LineIndex, translate_offset_with_edit}; |
7 | use ra_text_edit::{AtomTextEdit, TextEdit}; | 7 | use ra_text_edit::{AtomTextEdit, TextEdit}; |
8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
@@ -322,6 +322,15 @@ impl TryConvWith for FileSystemEdit { | |||
322 | } | 322 | } |
323 | } | 323 | } |
324 | 324 | ||
325 | impl TryConvWith for &NavigationTarget { | ||
326 | type Ctx = ServerWorld; | ||
327 | type Output = Location; | ||
328 | fn try_conv_with(self, world: &ServerWorld) -> Result<Location> { | ||
329 | let line_index = world.analysis().file_line_index(self.file_id()); | ||
330 | to_location(self.file_id(), self.range(), &world, &line_index) | ||
331 | } | ||
332 | } | ||
333 | |||
325 | pub fn to_location( | 334 | pub fn to_location( |
326 | file_id: FileId, | 335 | file_id: FileId, |
327 | range: TextRange, | 336 | range: TextRange, |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 11825d74e..26b6c7d8a 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -188,12 +188,11 @@ pub fn handle_workspace_symbol( | |||
188 | 188 | ||
189 | fn exec_query(world: &ServerWorld, query: Query) -> Result<Vec<SymbolInformation>> { | 189 | fn exec_query(world: &ServerWorld, query: Query) -> Result<Vec<SymbolInformation>> { |
190 | let mut res = Vec::new(); | 190 | let mut res = Vec::new(); |
191 | for (file_id, symbol) in world.analysis().symbol_search(query)? { | 191 | for nav in world.analysis().symbol_search(query)? { |
192 | let line_index = world.analysis().file_line_index(file_id); | ||
193 | let info = SymbolInformation { | 192 | let info = SymbolInformation { |
194 | name: symbol.name.to_string(), | 193 | name: nav.name().into(), |
195 | kind: symbol.kind.conv(), | 194 | kind: nav.kind().conv(), |
196 | location: to_location(file_id, symbol.node_range, world, &line_index)?, | 195 | location: nav.try_conv_with(world)?, |
197 | container_name: None, | 196 | container_name: None, |
198 | deprecated: None, | 197 | deprecated: None, |
199 | }; | 198 | }; |
@@ -212,12 +211,11 @@ pub fn handle_goto_definition( | |||
212 | None => return Ok(None), | 211 | None => return Ok(None), |
213 | Some(it) => it, | 212 | Some(it) => it, |
214 | }; | 213 | }; |
215 | let mut res = Vec::new(); | 214 | let res = rr |
216 | for (file_id, symbol) in rr.resolves_to { | 215 | .resolves_to |
217 | let line_index = world.analysis().file_line_index(file_id); | 216 | .into_iter() |
218 | let location = to_location(file_id, symbol.node_range, &world, &line_index)?; | 217 | .map(|nav| nav.try_conv_with(&world)) |
219 | res.push(location) | 218 | .collect::<Result<Vec<_>>>()?; |
220 | } | ||
221 | Ok(Some(req::GotoDefinitionResponse::Array(res))) | 219 | Ok(Some(req::GotoDefinitionResponse::Array(res))) |
222 | } | 220 | } |
223 | 221 | ||
@@ -226,13 +224,12 @@ pub fn handle_parent_module( | |||
226 | params: req::TextDocumentPositionParams, | 224 | params: req::TextDocumentPositionParams, |
227 | ) -> Result<Vec<Location>> { | 225 | ) -> Result<Vec<Location>> { |
228 | let position = params.try_conv_with(&world)?; | 226 | let position = params.try_conv_with(&world)?; |
229 | let mut res = Vec::new(); | 227 | world |
230 | for (file_id, symbol) in world.analysis().parent_module(position)? { | 228 | .analysis() |
231 | let line_index = world.analysis().file_line_index(file_id); | 229 | .parent_module(position)? |
232 | let location = to_location(file_id, symbol.node_range, &world, &line_index)?; | 230 | .into_iter() |
233 | res.push(location); | 231 | .map(|nav| nav.try_conv_with(&world)) |
234 | } | 232 | .collect::<Result<Vec<_>>>() |
235 | Ok(res) | ||
236 | } | 233 | } |
237 | 234 | ||
238 | pub fn handle_runnables( | 235 | pub fn handle_runnables( |
@@ -517,8 +514,8 @@ pub fn handle_hover( | |||
517 | Some(it) => it, | 514 | Some(it) => it, |
518 | }; | 515 | }; |
519 | let mut result = Vec::new(); | 516 | let mut result = Vec::new(); |
520 | for (file_id, symbol) in rr.resolves_to { | 517 | for nav in rr.resolves_to { |
521 | if let Some(docs) = world.analysis().doc_text_for(file_id, symbol)? { | 518 | if let Some(docs) = world.analysis().doc_text_for(nav)? { |
522 | result.push(docs); | 519 | result.push(docs); |
523 | } | 520 | } |
524 | } | 521 | } |