From 3f44aaf363be0669e618a8340fd91b47ae6344c4 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sun, 7 Jul 2019 14:13:13 -0400 Subject: use flatten branch of lsp-types --- crates/ra_lsp_server/src/main_loop/handlers.rs | 35 +++++++++----------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'crates/ra_lsp_server/src/main_loop') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a8d6f7c23..6b407cb0c 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -153,14 +153,12 @@ pub fn handle_on_type_formatting( params: req::DocumentOnTypeFormattingParams, ) -> Result>> { let _p = profile("handle_on_type_formatting"); - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let position = FilePosition { - file_id, - /// in `ra_ide_api`, the `on_type` invariant is that - /// `text.char_at(position) == typed_char`. - offset: params.position.conv_with(&line_index) - TextUnit::of_char('.'), - }; + let mut position = params.text_document_position.try_conv_with(&world)?; + let line_index = world.analysis().file_line_index(position.file_id); + + // in `ra_ide_api`, the `on_type` invariant is that + // `text.char_at(position) == typed_char`. + position.offset = position.offset - TextUnit::of_char('.'); let edit = match params.ch.as_str() { "=" => world.analysis().on_eq_typed(position), @@ -407,12 +405,7 @@ pub fn handle_completion( params: req::CompletionParams, ) -> Result> { let _p = profile("handle_completion"); - let position = { - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let offset = params.position.conv_with(&line_index); - FilePosition { file_id, offset } - }; + let position = params.text_document_position.try_conv_with(&world)?; let completion_triggered_after_single_colon = { let mut res = false; if let Some(ctx) = params.context { @@ -543,9 +536,7 @@ pub fn handle_prepare_rename( } pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result> { - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let offset = params.position.conv_with(&line_index); + let position = params.text_document_position.try_conv_with(&world)?; if params.new_name.is_empty() { return Err(LspError::new( @@ -555,8 +546,7 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result return Ok(None), Some(it) => it, @@ -571,11 +561,10 @@ pub fn handle_references( world: WorldSnapshot, params: req::ReferenceParams, ) -> Result>> { - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let offset = params.position.conv_with(&line_index); + let position = params.text_document_position.try_conv_with(&world)?; + let line_index = world.analysis().file_line_index(position.file_id); - let refs = match world.analysis().find_all_refs(FilePosition { file_id, offset })? { + let refs = match world.analysis().find_all_refs(position)? { None => return Ok(None), Some(refs) => refs, }; -- cgit v1.2.3