aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-23 20:14:51 +0100
committerAleksey Kladov <[email protected]>2018-08-23 20:14:51 +0100
commit8ad586a44e2214a11c4e7d27e0d3c2d73e43f39f (patch)
tree70c553dd0231189acf0695b63688f21fb94867dc /crates
parent18918769baf49acc4067eabdc0c3a0a98224d23f (diff)
JoinLines frontend
Diffstat (limited to 'crates')
-rw-r--r--crates/server/src/main_loop/handlers.rs14
-rw-r--r--crates/server/src/main_loop/mod.rs4
-rw-r--r--crates/server/src/req.rs16
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;
3use languageserver_types::{ 3use 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};
8use libanalysis::{Query}; 8use libanalysis::{Query};
9use libeditor; 9use libeditor;
@@ -58,6 +58,18 @@ pub fn handle_find_matching_brace(
58 Ok(res) 58 Ok(res)
59} 59}
60 60
61pub 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
61pub fn handle_document_symbol( 73pub 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
122pub enum JoinLines {}
123
124impl 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")]
132pub struct JoinLinesParams {
133 pub text_document: TextDocumentIdentifier,
134 pub range: Range,
135}