diff options
Diffstat (limited to 'crates/server/src/main_loop')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 19 | ||||
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 4 |
2 files changed, 23 insertions, 0 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index ec5421f06..ca5cd5ab1 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -314,6 +314,25 @@ pub fn handle_completion( | |||
314 | Ok(Some(req::CompletionResponse::Array(items))) | 314 | Ok(Some(req::CompletionResponse::Array(items))) |
315 | } | 315 | } |
316 | 316 | ||
317 | pub fn handle_on_type_formatting( | ||
318 | world: ServerWorld, | ||
319 | params: req::DocumentOnTypeFormattingParams, | ||
320 | ) -> Result<Option<Vec<TextEdit>>> { | ||
321 | if params.ch != "=" { | ||
322 | return Ok(None); | ||
323 | } | ||
324 | |||
325 | let file_id = params.text_document.try_conv_with(&world)?; | ||
326 | let line_index = world.analysis().file_line_index(file_id)?; | ||
327 | let offset = params.position.conv_with(&line_index); | ||
328 | let file = world.analysis().file_syntax(file_id)?; | ||
329 | let action = match libeditor::on_eq_typed(&file, offset) { | ||
330 | None => return Ok(None), | ||
331 | Some(action) => action, | ||
332 | }; | ||
333 | Ok(Some(action.edit.conv_with(&line_index))) | ||
334 | } | ||
335 | |||
317 | pub fn handle_execute_command( | 336 | pub fn handle_execute_command( |
318 | world: ServerWorld, | 337 | world: ServerWorld, |
319 | mut params: req::ExecuteCommandParams, | 338 | mut params: req::ExecuteCommandParams, |
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index da1121cb4..accb13878 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -31,6 +31,7 @@ use { | |||
31 | handle_completion, | 31 | handle_completion, |
32 | handle_runnables, | 32 | handle_runnables, |
33 | handle_decorations, | 33 | handle_decorations, |
34 | handle_on_type_formatting, | ||
34 | }, | 35 | }, |
35 | }; | 36 | }; |
36 | 37 | ||
@@ -161,6 +162,9 @@ fn on_request( | |||
161 | handle_request_on_threadpool::<req::DecorationsRequest>( | 162 | handle_request_on_threadpool::<req::DecorationsRequest>( |
162 | &mut req, pool, world, sender, handle_decorations, | 163 | &mut req, pool, world, sender, handle_decorations, |
163 | )?; | 164 | )?; |
165 | handle_request_on_threadpool::<req::OnTypeFormatting>( | ||
166 | &mut req, pool, world, sender, handle_on_type_formatting, | ||
167 | )?; | ||
164 | dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { | 168 | dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { |
165 | io.send(RawMsg::Response(resp.into_response(Ok(None))?)); | 169 | io.send(RawMsg::Response(resp.into_response(Ok(None))?)); |
166 | 170 | ||