diff options
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 013345acb..7d9234045 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -204,7 +204,10 @@ pub fn handle_goto_definition( | |||
204 | ) -> Result<Option<req::GotoDefinitionResponse>> { | 204 | ) -> Result<Option<req::GotoDefinitionResponse>> { |
205 | let position = params.try_conv_with(&world)?; | 205 | let position = params.try_conv_with(&world)?; |
206 | let mut res = Vec::new(); | 206 | let mut res = Vec::new(); |
207 | for (file_id, symbol) in world.analysis().approximately_resolve_symbol(position)? { | 207 | for (file_id, symbol) in match world.analysis().approximately_resolve_symbol(position)? { |
208 | None => return Ok(None), | ||
209 | Some(it) => it.1, | ||
210 | } { | ||
208 | let line_index = world.analysis().file_line_index(file_id); | 211 | let line_index = world.analysis().file_line_index(file_id); |
209 | let location = to_location(file_id, symbol.node_range, &world, &line_index)?; | 212 | let location = to_location(file_id, symbol.node_range, &world, &line_index)?; |
210 | res.push(location) | 213 | res.push(location) |
@@ -504,33 +507,31 @@ pub fn handle_hover( | |||
504 | world: ServerWorld, | 507 | world: ServerWorld, |
505 | params: req::TextDocumentPositionParams, | 508 | params: req::TextDocumentPositionParams, |
506 | ) -> Result<Option<Hover>> { | 509 | ) -> Result<Option<Hover>> { |
510 | // TODO: Cut down on number of allocations | ||
507 | let position = params.try_conv_with(&world)?; | 511 | let position = params.try_conv_with(&world)?; |
508 | let line_index = world.analysis().file_line_index(position.file_id); | 512 | let line_index = world.analysis().file_line_index(position.file_id); |
509 | let file = world.analysis().file_syntax(position.file_id); | 513 | let (range, resolved) = match world.analysis().approximately_resolve_symbol(position)? { |
510 | 514 | None => return Ok(None), | |
511 | for (file_id, symbol) in world.analysis().approximately_resolve_symbol(position)? { | 515 | Some(it) => it, |
512 | let comment = world.analysis.doc_comment_for(file_id, symbol)?; | 516 | }; |
513 | 517 | let mut result = Vec::new(); | |
514 | if comment.is_some() { | 518 | for (file_id, symbol) in resolved { |
515 | let range = match ra_syntax::algo::find_leaf_at_offset(file.syntax(), position.offset) | 519 | if let Some(docs) = world.analysis().doc_text_for(file_id, symbol)? { |
516 | .left_biased() | 520 | result.push(docs); |
517 | { | ||
518 | None => return Ok(None), | ||
519 | Some(it) => it.range(), | ||
520 | }; | ||
521 | let range = range.conv_with(&line_index); | ||
522 | let contents = HoverContents::Scalar(MarkedString::String(comment.unwrap())); | ||
523 | |||
524 | return Ok(Some(Hover { | ||
525 | contents, | ||
526 | range: Some(range), | ||
527 | })); | ||
528 | } | 521 | } |
529 | } | 522 | } |
530 | 523 | let range = range.conv_with(&line_index); | |
524 | if result.len() > 0 { | ||
525 | return Ok(Some(Hover { | ||
526 | contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))), | ||
527 | range: Some(range), | ||
528 | })); | ||
529 | } | ||
531 | Ok(None) | 530 | Ok(None) |
532 | } | 531 | } |
533 | 532 | ||
533 | |||
534 | /// Test doc comment | ||
534 | pub fn handle_prepare_rename( | 535 | pub fn handle_prepare_rename( |
535 | world: ServerWorld, | 536 | world: ServerWorld, |
536 | params: req::TextDocumentPositionParams, | 537 | params: req::TextDocumentPositionParams, |