From 2b956fd3a83313cee37ff179eae843bc88dd572a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Oct 2018 16:00:20 +0300 Subject: Add on-enter handler Now, typing doc comments is much more pleasant --- crates/ra_lsp_server/src/main_loop/handlers.rs | 14 ++++++++++++++ crates/ra_lsp_server/src/main_loop/mod.rs | 1 + 2 files changed, 15 insertions(+) (limited to 'crates/ra_lsp_server/src/main_loop') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 79a54183e..725036cc7 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -77,6 +77,20 @@ pub fn handle_join_lines( .try_conv_with(&world) } +pub fn handle_on_enter( + world: ServerWorld, + params: req::TextDocumentPositionParams, + _token: JobToken, +) -> Result> { + 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); + match world.analysis().on_enter(file_id, offset) { + None => Ok(None), + Some(edit) => Ok(Some(edit.try_conv_with(&world)?)) + } +} + pub fn handle_on_type_formatting( world: ServerWorld, params: req::DocumentOnTypeFormattingParams, diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 47a9b202e..53c6f1dff 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs @@ -244,6 +244,7 @@ fn on_request( .on::(handlers::handle_extend_selection)? .on::(handlers::handle_find_matching_brace)? .on::(handlers::handle_join_lines)? + .on::(handlers::handle_on_enter)? .on::(handlers::handle_on_type_formatting)? .on::(handlers::handle_document_symbol)? .on::(handlers::handle_workspace_symbol)? -- cgit v1.2.3