diff options
author | Aleksey Kladov <[email protected]> | 2018-08-16 11:46:31 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-16 11:46:31 +0100 |
commit | e0a43a159d03a91d8cce07003d427df4f3d6966d (patch) | |
tree | df27d9ea58452d447ad6614134f91fad9a583e8d /crates/server/src/main_loop/handlers.rs | |
parent | eda52cbc348f37c1ae4391da901b2d605e161716 (diff) |
vscode moves cursor
Diffstat (limited to 'crates/server/src/main_loop/handlers.rs')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index d7b78b4fa..f25c64c97 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -6,7 +6,7 @@ use languageserver_types::{ | |||
6 | SymbolInformation, Position, | 6 | SymbolInformation, Position, |
7 | }; | 7 | }; |
8 | use libanalysis::{World, Query}; | 8 | use libanalysis::{World, Query}; |
9 | use libeditor; | 9 | use libeditor::{self, CursorPosition}; |
10 | use libsyntax2::TextUnit; | 10 | use libsyntax2::TextUnit; |
11 | use serde_json::{to_value, from_value}; | 11 | use serde_json::{to_value, from_value}; |
12 | 12 | ||
@@ -195,7 +195,7 @@ pub fn handle_execute_command( | |||
195 | world: World, | 195 | world: World, |
196 | path_map: PathMap, | 196 | path_map: PathMap, |
197 | mut params: req::ExecuteCommandParams, | 197 | mut params: req::ExecuteCommandParams, |
198 | ) -> Result<req::ApplyWorkspaceEditParams> { | 198 | ) -> Result<(req::ApplyWorkspaceEditParams, Option<Position>)> { |
199 | if params.command.as_str() != "apply_code_action" { | 199 | if params.command.as_str() != "apply_code_action" { |
200 | bail!("unknown cmd: {:?}", params.command); | 200 | bail!("unknown cmd: {:?}", params.command); |
201 | } | 201 | } |
@@ -209,23 +209,24 @@ pub fn handle_execute_command( | |||
209 | let action_result = match arg.id { | 209 | let action_result = match arg.id { |
210 | ActionId::FlipComma => libeditor::flip_comma(&file, arg.offset).map(|f| f()), | 210 | ActionId::FlipComma => libeditor::flip_comma(&file, arg.offset).map(|f| f()), |
211 | ActionId::AddDerive => libeditor::add_derive(&file, arg.offset).map(|f| f()), | 211 | ActionId::AddDerive => libeditor::add_derive(&file, arg.offset).map(|f| f()), |
212 | }; | 212 | }.ok_or_else(|| format_err!("command not applicable"))?; |
213 | let edit = match action_result { | ||
214 | Some(action_result) => action_result.edit, | ||
215 | None => bail!("command not applicable"), | ||
216 | }; | ||
217 | let line_index = world.file_line_index(file_id)?; | 213 | let line_index = world.file_line_index(file_id)?; |
218 | let mut changes = HashMap::new(); | 214 | let mut changes = HashMap::new(); |
219 | changes.insert( | 215 | changes.insert( |
220 | arg.text_document.uri, | 216 | arg.text_document.uri, |
221 | edit.conv_with(&line_index), | 217 | action_result.edit.conv_with(&line_index), |
222 | ); | 218 | ); |
223 | let edit = WorkspaceEdit { | 219 | let edit = WorkspaceEdit { |
224 | changes: Some(changes), | 220 | changes: Some(changes), |
225 | document_changes: None, | 221 | document_changes: None, |
226 | }; | 222 | }; |
223 | let edit = req::ApplyWorkspaceEditParams { edit }; | ||
224 | let cursor_pos = match action_result.cursor_position { | ||
225 | CursorPosition::Same => None, | ||
226 | CursorPosition::Offset(offset) => Some(offset.conv_with(&line_index)), | ||
227 | }; | ||
227 | 228 | ||
228 | Ok(req::ApplyWorkspaceEditParams { edit }) | 229 | Ok((edit, cursor_pos)) |
229 | } | 230 | } |
230 | 231 | ||
231 | #[derive(Serialize, Deserialize)] | 232 | #[derive(Serialize, Deserialize)] |