aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--code/package.json5
-rw-r--r--code/src/extension.ts16
-rw-r--r--crates/server/src/main_loop/handlers.rs19
-rw-r--r--crates/server/src/main_loop/mod.rs4
-rw-r--r--crates/server/src/req.rs10
5 files changed, 52 insertions, 2 deletions
diff --git a/code/package.json b/code/package.json
index fd3b8e423..042821b1c 100644
--- a/code/package.json
+++ b/code/package.json
@@ -41,6 +41,11 @@
41 "command": "libsyntax-rust.matchingBrace", 41 "command": "libsyntax-rust.matchingBrace",
42 "key": "ctrl+shift+m", 42 "key": "ctrl+shift+m",
43 "title": "Rust Matching Brace" 43 "title": "Rust Matching Brace"
44 },
45 {
46 "command": "libsyntax-rust.parentModule",
47 "key": "ctrl+u",
48 "title": "Rust Parent Module"
44 } 49 }
45 ], 50 ],
46 "keybindings": [ 51 "keybindings": [
diff --git a/code/src/extension.ts b/code/src/extension.ts
index 084a9d769..fb6841fa0 100644
--- a/code/src/extension.ts
+++ b/code/src/extension.ts
@@ -51,6 +51,22 @@ 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.parentModule', async () => {
55 let editor = vscode.window.activeTextEditor
56 if (editor == null || editor.document.languageId != "rust") return
57 let request: lc.TextDocumentIdentifier = {
58 uri: editor.document.uri.toString()
59 }
60 let response = await client.sendRequest<lc.TextDocumentIdentifier>("m/parentModule", request)
61 let loc: lc.Location = response[0]
62 if (loc == null) return
63 let uri = client.protocol2CodeConverter.asUri(loc.uri)
64 let range = client.protocol2CodeConverter.asRange(loc.range)
65
66 let doc = await vscode.workspace.openTextDocument(uri)
67 let e = await vscode.window.showTextDocument(doc)
68 e.revealRange(range, vscode.TextEditorRevealType.InCenter)
69 })
54 70
55 dispose(vscode.workspace.registerTextDocumentContentProvider( 71 dispose(vscode.workspace.registerTextDocumentContentProvider(
56 'libsyntax-rust', 72 'libsyntax-rust',
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs
index 675f69bec..16cc92464 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, 6 SymbolInformation, Position, Location,
7}; 7};
8use libanalysis::{Query}; 8use libanalysis::{Query};
9use libeditor::{self, CursorPosition}; 9use libeditor::{self, CursorPosition};
@@ -184,6 +184,23 @@ pub fn handle_goto_definition(
184 Ok(Some(req::GotoDefinitionResponse::Array(res))) 184 Ok(Some(req::GotoDefinitionResponse::Array(res)))
185} 185}
186 186
187pub fn handle_parent_module(
188 world: ServerWorld,
189 params: TextDocumentIdentifier,
190) -> Result<Vec<Location>> {
191 let file_id = params.try_conv_with(&world)?;
192 let mut res = Vec::new();
193 for (file_id, symbol) in world.analysis().parent_module(file_id) {
194 let line_index = world.analysis().file_line_index(file_id)?;
195 let location = to_location(
196 file_id, symbol.node_range,
197 &world, &line_index
198 )?;
199 res.push(location);
200 }
201 Ok(res)
202}
203
187pub fn handle_execute_command( 204pub fn handle_execute_command(
188 world: ServerWorld, 205 world: ServerWorld,
189 mut params: req::ExecuteCommandParams, 206 mut params: req::ExecuteCommandParams,
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index 752d6ddb2..9499b826c 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -26,6 +26,7 @@ use {
26 handle_workspace_symbol, 26 handle_workspace_symbol,
27 handle_goto_definition, 27 handle_goto_definition,
28 handle_find_matching_brace, 28 handle_find_matching_brace,
29 handle_parent_module,
29 }, 30 },
30}; 31};
31 32
@@ -141,6 +142,9 @@ fn on_request(
141 handle_request_on_threadpool::<req::GotoDefinition>( 142 handle_request_on_threadpool::<req::GotoDefinition>(
142 &mut req, pool, world, sender, handle_goto_definition, 143 &mut req, pool, world, sender, handle_goto_definition,
143 )?; 144 )?;
145 handle_request_on_threadpool::<req::ParentModule>(
146 &mut req, pool, world, sender, handle_parent_module,
147 )?;
144 dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| { 148 dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| {
145 io.send(RawMsg::Response(resp.into_response(Ok(None))?)); 149 io.send(RawMsg::Response(resp.into_response(Ok(None))?));
146 150
diff --git a/crates/server/src/req.rs b/crates/server/src/req.rs
index 73e82150c..a8aa24629 100644
--- a/crates/server/src/req.rs
+++ b/crates/server/src/req.rs
@@ -1,5 +1,5 @@
1use serde::{ser::Serialize, de::DeserializeOwned}; 1use serde::{ser::Serialize, de::DeserializeOwned};
2use languageserver_types::{TextDocumentIdentifier, Range, Url, Position}; 2use languageserver_types::{TextDocumentIdentifier, Range, Url, Position, Location};
3use url_serde; 3use url_serde;
4 4
5pub use languageserver_types::{ 5pub use languageserver_types::{
@@ -109,3 +109,11 @@ impl Request for MoveCursor {
109 type Result = (); 109 type Result = ();
110 const METHOD: &'static str = "m/moveCursor"; 110 const METHOD: &'static str = "m/moveCursor";
111} 111}
112
113pub enum ParentModule {}
114
115impl Request for ParentModule {
116 type Params = TextDocumentIdentifier;
117 type Result = Vec<Location>;
118 const METHOD: &'static str = "m/parentModule";
119}