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 From 9c6e93cd6c108536015272b6a363ed5cc1d4fb44 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sun, 7 Jul 2019 17:28:21 -0400 Subject: Simplify responses by using into() --- crates/ra_lsp_server/src/main_loop/handlers.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 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 6b407cb0c..62c8cbf71 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -2,11 +2,11 @@ use std::{fmt::Write as _, io::Write as _}; use gen_lsp_server::ErrorCode; use lsp_types::{ - CodeAction, CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, - DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeKind, - FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, Position, - PrepareRenameResponse, Range, RenameParams, SymbolInformation, TextDocumentIdentifier, - TextEdit, WorkspaceEdit, + CodeAction, CodeActionResponse, CodeLens, Command, CompletionItem, Diagnostic, + DiagnosticSeverity, DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, + FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, + MarkupKind, Position, PrepareRenameResponse, Range, RenameParams, SymbolInformation, + TextDocumentIdentifier, TextEdit, WorkspaceEdit, }; use ra_ide_api::{ AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, @@ -212,7 +212,7 @@ pub fn handle_document_symbol( } } - Ok(Some(req::DocumentSymbolResponse::Nested(res))) + Ok(Some(res.into())) } pub fn handle_workspace_symbol( @@ -275,7 +275,7 @@ pub fn handle_goto_definition( .map(|nav| RangeInfo::new(nav_range, nav)) .map(|nav| to_location_link(&nav, &world, &line_index)) .collect::>>()?; - Ok(Some(req::GotoDefinitionResponse::Link(res))) + Ok(Some(res.into())) } pub fn handle_goto_implementation( @@ -295,7 +295,7 @@ pub fn handle_goto_implementation( .map(|nav| RangeInfo::new(nav_range, nav)) .map(|nav| to_location_link(&nav, &world, &line_index)) .collect::>>()?; - Ok(Some(req::GotoDefinitionResponse::Link(res))) + Ok(Some(res.into())) } pub fn handle_goto_type_definition( @@ -315,7 +315,7 @@ pub fn handle_goto_type_definition( .map(|nav| RangeInfo::new(nav_range, nav)) .map(|nav| to_location_link(&nav, &world, &line_index)) .collect::>>()?; - Ok(Some(req::GotoDefinitionResponse::Link(res))) + Ok(Some(res.into())) } pub fn handle_parent_module( @@ -433,9 +433,10 @@ pub fn handle_completion( Some(items) => items, }; let line_index = world.analysis().file_line_index(position.file_id); - let items = items.into_iter().map(|item| item.conv_with(&line_index)).collect(); + let items: Vec = + items.into_iter().map(|item| item.conv_with(&line_index)).collect(); - Ok(Some(req::CompletionResponse::Array(items))) + Ok(Some(items.into())) } pub fn handle_folding_range( -- cgit v1.2.3