aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--code/package.json9
-rw-r--r--code/src/extension.ts18
-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
5 files changed, 60 insertions, 1 deletions
diff --git a/code/package.json b/code/package.json
index 35367edb6..20a6ceee7 100644
--- a/code/package.json
+++ b/code/package.json
@@ -44,6 +44,10 @@
44 { 44 {
45 "command": "libsyntax-rust.parentModule", 45 "command": "libsyntax-rust.parentModule",
46 "title": "Rust Parent Module" 46 "title": "Rust Parent Module"
47 },
48 {
49 "command": "libsyntax-rust.joinLines",
50 "title": "Rust Join Lines"
47 } 51 }
48 ], 52 ],
49 "keybindings": [ 53 "keybindings": [
@@ -61,6 +65,11 @@
61 "command": "libsyntax-rust.extendSelection", 65 "command": "libsyntax-rust.extendSelection",
62 "key": "ctrl+w", 66 "key": "ctrl+w",
63 "when": "editorTextFocus && editorLangId == rust" 67 "when": "editorTextFocus && editorLangId == rust"
68 },
69 {
70 "command": "libsyntax-rust.joinLines",
71 "key": "ctrl+shift+j",
72 "when": "editorTextFocus && editorLangId == rust"
64 } 73 }
65 ], 74 ],
66 "problemMatchers": [ 75 "problemMatchers": [
diff --git a/code/src/extension.ts b/code/src/extension.ts
index fb6841fa0..134459f30 100644
--- a/code/src/extension.ts
+++ b/code/src/extension.ts
@@ -51,6 +51,19 @@ export function activate(context: vscode.ExtensionContext) {
51 return new vscode.Selection(anchor, active) 51 return new vscode.Selection(anchor, active)
52 }) 52 })
53 }) 53 })
54 registerCommand('libsyntax-rust.joinLines', async () => {
55 let editor = vscode.window.activeTextEditor
56 if (editor == null || editor.document.languageId != "rust") return
57 let request: JoinLinesParams = {
58 textDocument: { uri: editor.document.uri.toString() },
59 range: client.code2ProtocolConverter.asRange(editor.selection),
60 }
61 let response = await client.sendRequest<lc.TextEdit[]>("m/joinLines", request)
62 let edits = client.protocol2CodeConverter.asTextEdits(response)
63 let wsEdit = new vscode.WorkspaceEdit()
64 wsEdit.set(editor.document.uri, edits)
65 return vscode.workspace.applyEdit(wsEdit)
66 })
54 registerCommand('libsyntax-rust.parentModule', async () => { 67 registerCommand('libsyntax-rust.parentModule', async () => {
55 let editor = vscode.window.activeTextEditor 68 let editor = vscode.window.activeTextEditor
56 if (editor == null || editor.document.languageId != "rust") return 69 if (editor == null || editor.document.languageId != "rust") return
@@ -237,6 +250,11 @@ interface FindMatchingBraceParams {
237 offsets: lc.Position[]; 250 offsets: lc.Position[];
238} 251}
239 252
253interface JoinLinesParams {
254 textDocument: lc.TextDocumentIdentifier;
255 range: lc.Range;
256}
257
240interface PublishDecorationsParams { 258interface PublishDecorationsParams {
241 uri: string, 259 uri: string,
242 decorations: Decoration[], 260 decorations: Decoration[],
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}