diff options
Diffstat (limited to 'crates/server')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 14 | ||||
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 4 | ||||
-rw-r--r-- | crates/server/src/req.rs | 16 |
3 files changed, 33 insertions, 1 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index b47cbc0fc..ae362ddaa 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -3,7 +3,7 @@ use std::collections::HashMap; | |||
3 | use languageserver_types::{ | 3 | use languageserver_types::{ |
4 | Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, | 4 | Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, |
5 | Command, TextDocumentIdentifier, WorkspaceEdit, | 5 | Command, TextDocumentIdentifier, WorkspaceEdit, |
6 | SymbolInformation, Position, Location, | 6 | SymbolInformation, Position, Location, TextEdit, |
7 | }; | 7 | }; |
8 | use libanalysis::{Query}; | 8 | use libanalysis::{Query}; |
9 | use libeditor; | 9 | use libeditor; |
@@ -58,6 +58,18 @@ pub fn handle_find_matching_brace( | |||
58 | Ok(res) | 58 | Ok(res) |
59 | } | 59 | } |
60 | 60 | ||
61 | pub fn handle_join_lines( | ||
62 | world: ServerWorld, | ||
63 | params: req::JoinLinesParams, | ||
64 | ) -> Result<Vec<TextEdit>> { | ||
65 | let file_id = params.text_document.try_conv_with(&world)?; | ||
66 | let file = world.analysis().file_syntax(file_id)?; | ||
67 | let line_index = world.analysis().file_line_index(file_id)?; | ||
68 | let range = params.range.conv_with(&line_index); | ||
69 | let res = libeditor::join_lines(&file, range); | ||
70 | Ok(res.edit.conv_with(&line_index)) | ||
71 | } | ||
72 | |||
61 | pub fn handle_document_symbol( | 73 | pub fn handle_document_symbol( |
62 | world: ServerWorld, | 74 | world: ServerWorld, |
63 | params: req::DocumentSymbolParams, | 75 | params: req::DocumentSymbolParams, |
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index 9499b826c..1e65041e2 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -27,6 +27,7 @@ use { | |||
27 | handle_goto_definition, | 27 | handle_goto_definition, |
28 | handle_find_matching_brace, | 28 | handle_find_matching_brace, |
29 | handle_parent_module, | 29 | handle_parent_module, |
30 | handle_join_lines, | ||
30 | }, | 31 | }, |
31 | }; | 32 | }; |
32 | 33 | ||
@@ -145,6 +146,9 @@ fn on_request( | |||
145 | handle_request_on_threadpool::<req::ParentModule>( | 146 | handle_request_on_threadpool::<req::ParentModule>( |
146 | &mut req, pool, world, sender, handle_parent_module, | 147 | &mut req, pool, world, sender, handle_parent_module, |
147 | )?; | 148 | )?; |
149 | handle_request_on_threadpool::<req::JoinLines>( | ||
150 | &mut req, pool, world, sender, handle_join_lines, | ||
151 | )?; | ||
148 | dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { | 152 | dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { |
149 | io.send(RawMsg::Response(resp.into_response(Ok(None))?)); | 153 | io.send(RawMsg::Response(resp.into_response(Ok(None))?)); |
150 | 154 | ||
diff --git a/crates/server/src/req.rs b/crates/server/src/req.rs index a8aa24629..c431deeb4 100644 --- a/crates/server/src/req.rs +++ b/crates/server/src/req.rs | |||
@@ -10,6 +10,7 @@ pub use languageserver_types::{ | |||
10 | ExecuteCommandParams, | 10 | ExecuteCommandParams, |
11 | WorkspaceSymbolParams, | 11 | WorkspaceSymbolParams, |
12 | TextDocumentPositionParams, | 12 | TextDocumentPositionParams, |
13 | TextEdit, | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | 16 | ||
@@ -117,3 +118,18 @@ impl Request for ParentModule { | |||
117 | type Result = Vec<Location>; | 118 | type Result = Vec<Location>; |
118 | const METHOD: &'static str = "m/parentModule"; | 119 | const METHOD: &'static str = "m/parentModule"; |
119 | } | 120 | } |
121 | |||
122 | pub enum JoinLines {} | ||
123 | |||
124 | impl Request for JoinLines { | ||
125 | type Params = JoinLinesParams; | ||
126 | type Result = Vec<TextEdit>; | ||
127 | const METHOD: &'static str = "m/joinLines"; | ||
128 | } | ||
129 | |||
130 | #[derive(Deserialize, Debug)] | ||
131 | #[serde(rename_all = "camelCase")] | ||
132 | pub struct JoinLinesParams { | ||
133 | pub text_document: TextDocumentIdentifier, | ||
134 | pub range: Range, | ||
135 | } | ||