diff options
author | Simon Vandel Sillesen <[email protected]> | 2019-01-06 08:41:11 +0000 |
---|---|---|
committer | Simon Vandel Sillesen <[email protected]> | 2019-01-06 08:41:11 +0000 |
commit | 2e52b27e7139095393c7e4eebd7da0c6c26b053e (patch) | |
tree | 12fdc917449058fde414dcab0f1d5ae1c5737289 /crates/ra_lsp_server/src/main_loop | |
parent | bb8624dff65dca10997e3eec62df975e6e347558 (diff) |
refactor
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 2ec9073e4..51f134e8a 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -93,36 +93,31 @@ pub fn handle_on_type_formatting( | |||
93 | world: ServerWorld, | 93 | world: ServerWorld, |
94 | params: req::DocumentOnTypeFormattingParams, | 94 | params: req::DocumentOnTypeFormattingParams, |
95 | ) -> Result<Option<Vec<TextEdit>>> { | 95 | ) -> Result<Option<Vec<TextEdit>>> { |
96 | if params.ch != "=" || params.ch != "." { | 96 | let analysis: Option<Box<Fn(FilePosition) -> Option<SourceChange>>> = match params.ch.as_str() { |
97 | return Ok(None); | 97 | "=" => Some(Box::new(|pos| world.analysis().on_eq_typed(pos))), |
98 | } | 98 | "." => Some(Box::new(|pos| world.analysis().on_dot_typed(pos))), |
99 | 99 | _ => None, | |
100 | let file_id = params.text_document.try_conv_with(&world)?; | ||
101 | let line_index = world.analysis().file_line_index(file_id); | ||
102 | let position = FilePosition { | ||
103 | file_id, | ||
104 | offset: params.position.conv_with(&line_index), | ||
105 | }; | 100 | }; |
106 | 101 | ||
107 | let analysis: Vec<Box<Fn(FilePosition) -> Option<SourceChange>>> = vec![ | 102 | if let Some(ana) = analysis { |
108 | Box::new(|pos| world.analysis().on_eq_typed(pos)), | 103 | let file_id = params.text_document.try_conv_with(&world)?; |
109 | Box::new(|pos| world.analysis().on_dot_typed(pos)), | 104 | let line_index = world.analysis().file_line_index(file_id); |
110 | ]; | 105 | let position = FilePosition { |
106 | file_id, | ||
107 | offset: params.position.conv_with(&line_index), | ||
108 | }; | ||
111 | 109 | ||
112 | // try all analysis until one succeeds | ||
113 | for ana in analysis { | ||
114 | if let Some(mut action) = ana(position) { | 110 | if let Some(mut action) = ana(position) { |
115 | return Ok(Some( | 111 | let change: Vec<TextEdit> = action |
116 | action | 112 | .source_file_edits |
117 | .source_file_edits | 113 | .pop() |
118 | .pop() | 114 | .unwrap() |
119 | .unwrap() | 115 | .edit |
120 | .edit | 116 | .as_atoms() |
121 | .as_atoms() | 117 | .iter() |
122 | .iter() | 118 | .map_conv_with(&line_index) |
123 | .map_conv_with(&line_index) | 119 | .collect(); |
124 | .collect(), | 120 | return Ok(Some(change)); |
125 | )); | ||
126 | } | 121 | } |
127 | } | 122 | } |
128 | 123 | ||