diff options
Diffstat (limited to 'crates/server')
-rw-r--r-- | crates/server/src/caps.rs | 6 | ||||
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 19 | ||||
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 4 | ||||
-rw-r--r-- | crates/server/src/req.rs | 1 |
4 files changed, 29 insertions, 1 deletions
diff --git a/crates/server/src/caps.rs b/crates/server/src/caps.rs index 98499bb05..7456aea8a 100644 --- a/crates/server/src/caps.rs +++ b/crates/server/src/caps.rs | |||
@@ -5,6 +5,7 @@ use languageserver_types::{ | |||
5 | TextDocumentSyncKind, | 5 | TextDocumentSyncKind, |
6 | ExecuteCommandOptions, | 6 | ExecuteCommandOptions, |
7 | CompletionOptions, | 7 | CompletionOptions, |
8 | DocumentOnTypeFormattingOptions, | ||
8 | }; | 9 | }; |
9 | 10 | ||
10 | pub fn server_capabilities() -> ServerCapabilities { | 11 | pub fn server_capabilities() -> ServerCapabilities { |
@@ -35,7 +36,10 @@ pub fn server_capabilities() -> ServerCapabilities { | |||
35 | code_lens_provider: None, | 36 | code_lens_provider: None, |
36 | document_formatting_provider: None, | 37 | document_formatting_provider: None, |
37 | document_range_formatting_provider: None, | 38 | document_range_formatting_provider: None, |
38 | document_on_type_formatting_provider: None, | 39 | document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions { |
40 | first_trigger_character: "=".to_string(), | ||
41 | more_trigger_character: None, | ||
42 | }), | ||
39 | rename_provider: None, | 43 | rename_provider: None, |
40 | color_provider: None, | 44 | color_provider: None, |
41 | execute_command_provider: Some(ExecuteCommandOptions { | 45 | execute_command_provider: Some(ExecuteCommandOptions { |
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 | ||
diff --git a/crates/server/src/req.rs b/crates/server/src/req.rs index 999fdb7c2..881069b1f 100644 --- a/crates/server/src/req.rs +++ b/crates/server/src/req.rs | |||
@@ -14,6 +14,7 @@ pub use languageserver_types::{ | |||
14 | TextDocumentPositionParams, | 14 | TextDocumentPositionParams, |
15 | TextEdit, | 15 | TextEdit, |
16 | CompletionParams, CompletionResponse, | 16 | CompletionParams, CompletionResponse, |
17 | DocumentOnTypeFormattingParams, | ||
17 | }; | 18 | }; |
18 | 19 | ||
19 | 20 | ||