diff options
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a29971d10..16fb07266 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -132,6 +132,7 @@ pub fn handle_on_enter( | |||
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | // Don't forget to add new trigger characters to `ServerCapabilities` in `caps.rs`. | ||
135 | pub fn handle_on_type_formatting( | 136 | pub fn handle_on_type_formatting( |
136 | world: WorldSnapshot, | 137 | world: WorldSnapshot, |
137 | params: req::DocumentOnTypeFormattingParams, | 138 | params: req::DocumentOnTypeFormattingParams, |
@@ -144,12 +145,17 @@ pub fn handle_on_type_formatting( | |||
144 | // in `ra_ide_api`, the `on_type` invariant is that | 145 | // in `ra_ide_api`, the `on_type` invariant is that |
145 | // `text.char_at(position) == typed_char`. | 146 | // `text.char_at(position) == typed_char`. |
146 | position.offset = position.offset - TextUnit::of_char('.'); | 147 | position.offset = position.offset - TextUnit::of_char('.'); |
148 | let char_typed = params.ch.chars().next().unwrap_or('\0'); | ||
147 | 149 | ||
148 | let edit = match params.ch.as_str() { | 150 | // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`, |
149 | "=" => world.analysis().on_eq_typed(position), | 151 | // but it requires precise cursor positioning to work, and one can't |
150 | "." => world.analysis().on_dot_typed(position), | 152 | // position the cursor with on_type formatting. So, let's just toggle this |
151 | _ => return Ok(None), | 153 | // feature off here, hoping that we'll enable it one day, 😿. |
152 | }?; | 154 | if char_typed == '>' { |
155 | return Ok(None); | ||
156 | } | ||
157 | |||
158 | let edit = world.analysis().on_char_typed(position, char_typed)?; | ||
153 | let mut edit = match edit { | 159 | let mut edit = match edit { |
154 | Some(it) => it, | 160 | Some(it) => it, |
155 | None => return Ok(None), | 161 | None => return Ok(None), |