From e8dfb92641f64b772204d7670c7286cb9b8b398b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 22 Aug 2018 12:58:34 +0300 Subject: Simplify --- crates/libeditor/src/code_actions.rs | 11 +++-------- crates/libeditor/src/lib.rs | 2 +- crates/libeditor/tests/test.rs | 6 +++--- crates/server/src/main_loop/handlers.rs | 9 +++------ 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index 80c396337..500d52c2a 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs @@ -11,12 +11,7 @@ use libsyntax2::{ pub struct ActionResult { pub edit: Edit, - pub cursor_position: CursorPosition, -} - -pub enum CursorPosition { - Same, - Offset(TextUnit), + pub cursor_position: Option, } pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option ActionResult + 'a> { @@ -31,7 +26,7 @@ pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option(file: &'a ParsedFile, offset: TextUnit) -> Option Option>( let result = f(&file, before_cursor_pos).expect("code action is not applicable"); let actual = result.edit.apply(&before); let actual_cursor_pos = match result.cursor_position { - CursorPosition::Same => result.edit.apply_to_offset(before_cursor_pos).unwrap(), - CursorPosition::Offset(off) => off, + None => result.edit.apply_to_offset(before_cursor_pos).unwrap(), + Some(off) => off, }; let actual = add_cursor(&actual, actual_cursor_pos); assert_eq_text!(after, &actual); diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index 16cc92464..9ff821a8b 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs @@ -6,7 +6,7 @@ use languageserver_types::{ SymbolInformation, Position, Location, }; use libanalysis::{Query}; -use libeditor::{self, CursorPosition}; +use libeditor; use libsyntax2::TextUnit; use serde_json::{to_value, from_value}; @@ -230,11 +230,8 @@ pub fn handle_execute_command( document_changes: None, }; let edit = req::ApplyWorkspaceEditParams { edit }; - let cursor_pos = match action_result.cursor_position { - CursorPosition::Same => None, - CursorPosition::Offset(offset) => Some(offset.conv_with(&line_index)), - }; - + let cursor_pos = action_result.cursor_position + .map(|off| off.conv_with(&line_index)); Ok((edit, cursor_pos)) } -- cgit v1.2.3