From 2fa90e736b026ee979d9eb59178dc1f792228250 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 Aug 2018 11:12:42 +0300 Subject: better recovery for exprs --- crates/server/src/main_loop/handlers.rs | 19 +++++++++++++++++++ crates/server/src/main_loop/mod.rs | 4 ++++ 2 files changed, 23 insertions(+) (limited to 'crates/server/src/main_loop') 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( Ok(Some(req::CompletionResponse::Array(items))) } +pub fn handle_on_type_formatting( + world: ServerWorld, + params: req::DocumentOnTypeFormattingParams, +) -> Result>> { + if params.ch != "=" { + return Ok(None); + } + + let file_id = params.text_document.try_conv_with(&world)?; + let line_index = world.analysis().file_line_index(file_id)?; + let offset = params.position.conv_with(&line_index); + let file = world.analysis().file_syntax(file_id)?; + let action = match libeditor::on_eq_typed(&file, offset) { + None => return Ok(None), + Some(action) => action, + }; + Ok(Some(action.edit.conv_with(&line_index))) +} + pub fn handle_execute_command( world: ServerWorld, 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 { handle_completion, handle_runnables, handle_decorations, + handle_on_type_formatting, }, }; @@ -161,6 +162,9 @@ fn on_request( handle_request_on_threadpool::( &mut req, pool, world, sender, handle_decorations, )?; + handle_request_on_threadpool::( + &mut req, pool, world, sender, handle_on_type_formatting, + )?; dispatch::handle_request::(&mut req, |params, resp| { io.send(RawMsg::Response(resp.into_response(Ok(None))?)); -- cgit v1.2.3