From 8ad586a44e2214a11c4e7d27e0d3c2d73e43f39f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 23 Aug 2018 22:14:51 +0300 Subject: JoinLines frontend --- crates/server/src/main_loop/handlers.rs | 14 +++++++++++++- crates/server/src/main_loop/mod.rs | 4 ++++ crates/server/src/req.rs | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) (limited to 'crates') 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; use languageserver_types::{ Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, Command, TextDocumentIdentifier, WorkspaceEdit, - SymbolInformation, Position, Location, + SymbolInformation, Position, Location, TextEdit, }; use libanalysis::{Query}; use libeditor; @@ -58,6 +58,18 @@ pub fn handle_find_matching_brace( Ok(res) } +pub fn handle_join_lines( + world: ServerWorld, + params: req::JoinLinesParams, +) -> Result> { + let file_id = params.text_document.try_conv_with(&world)?; + let file = world.analysis().file_syntax(file_id)?; + let line_index = world.analysis().file_line_index(file_id)?; + let range = params.range.conv_with(&line_index); + let res = libeditor::join_lines(&file, range); + Ok(res.edit.conv_with(&line_index)) +} + pub fn handle_document_symbol( world: ServerWorld, 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 { handle_goto_definition, handle_find_matching_brace, handle_parent_module, + handle_join_lines, }, }; @@ -145,6 +146,9 @@ fn on_request( handle_request_on_threadpool::( &mut req, pool, world, sender, handle_parent_module, )?; + handle_request_on_threadpool::( + &mut req, pool, world, sender, handle_join_lines, + )?; dispatch::handle_request::(&mut req, |params, resp| { io.send(RawMsg::Response(resp.into_response(Ok(None))?)); 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::{ ExecuteCommandParams, WorkspaceSymbolParams, TextDocumentPositionParams, + TextEdit, }; @@ -117,3 +118,18 @@ impl Request for ParentModule { type Result = Vec; const METHOD: &'static str = "m/parentModule"; } + +pub enum JoinLines {} + +impl Request for JoinLines { + type Params = JoinLinesParams; + type Result = Vec; + const METHOD: &'static str = "m/joinLines"; +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct JoinLinesParams { + pub text_document: TextDocumentIdentifier, + pub range: Range, +} -- cgit v1.2.3