From 7fd6a41127dc9a60efe703f7d588f8555b8bffc6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Dec 2018 21:18:29 +0300 Subject: Refactor symbol resolve API Introduce ReferenceResolution to avoid nesting to many non-nominal types. --- crates/ra_lsp_server/src/main_loop/handlers.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index f18a1305d..92e92f836 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -203,11 +203,12 @@ pub fn handle_goto_definition( params: req::TextDocumentPositionParams, ) -> Result> { let position = params.try_conv_with(&world)?; - let mut res = Vec::new(); - for (file_id, symbol) in match world.analysis().approximately_resolve_symbol(position)? { + let rr = match world.analysis().approximately_resolve_symbol(position)? { None => return Ok(None), - Some(it) => it.1, - } { + Some(it) => it, + }; + let mut res = Vec::new(); + for (file_id, symbol) in rr.resolves_to { let line_index = world.analysis().file_line_index(file_id); let location = to_location(file_id, symbol.node_range, &world, &line_index)?; res.push(location) @@ -510,17 +511,17 @@ pub fn handle_hover( // TODO: Cut down on number of allocations let position = params.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(position.file_id); - let (range, resolved) = match world.analysis().approximately_resolve_symbol(position)? { + let rr = match world.analysis().approximately_resolve_symbol(position)? { None => return Ok(None), Some(it) => it, }; let mut result = Vec::new(); - for (file_id, symbol) in resolved { + for (file_id, symbol) in rr.resolves_to { if let Some(docs) = world.analysis().doc_text_for(file_id, symbol)? { result.push(docs); } } - let range = range.conv_with(&line_index); + let range = rr.reference_range.conv_with(&line_index); if result.len() > 0 { return Ok(Some(Hover { contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))), -- cgit v1.2.3