From 9909875bfe89d2b901c35c0667bed018338b44e1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 22 Aug 2018 10:18:58 +0300 Subject: parent module request --- crates/server/src/main_loop/handlers.rs | 19 ++++++++++++++++++- crates/server/src/main_loop/mod.rs | 4 ++++ crates/server/src/req.rs | 10 +++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) (limited to 'crates/server') 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; use languageserver_types::{ Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, Command, TextDocumentIdentifier, WorkspaceEdit, - SymbolInformation, Position, + SymbolInformation, Position, Location, }; use libanalysis::{Query}; use libeditor::{self, CursorPosition}; @@ -184,6 +184,23 @@ pub fn handle_goto_definition( Ok(Some(req::GotoDefinitionResponse::Array(res))) } +pub fn handle_parent_module( + world: ServerWorld, + params: TextDocumentIdentifier, +) -> Result> { + let file_id = params.try_conv_with(&world)?; + let mut res = Vec::new(); + for (file_id, symbol) in world.analysis().parent_module(file_id) { + let line_index = world.analysis().file_line_index(file_id)?; + let location = to_location( + file_id, symbol.node_range, + &world, &line_index + )?; + res.push(location); + } + Ok(res) +} + pub fn handle_execute_command( world: ServerWorld, 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 { handle_workspace_symbol, handle_goto_definition, handle_find_matching_brace, + handle_parent_module, }, }; @@ -141,6 +142,9 @@ fn on_request( handle_request_on_threadpool::( &mut req, pool, world, sender, handle_goto_definition, )?; + handle_request_on_threadpool::( + &mut req, pool, world, sender, handle_parent_module, + )?; 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 73e82150c..a8aa24629 100644 --- a/crates/server/src/req.rs +++ b/crates/server/src/req.rs @@ -1,5 +1,5 @@ use serde::{ser::Serialize, de::DeserializeOwned}; -use languageserver_types::{TextDocumentIdentifier, Range, Url, Position}; +use languageserver_types::{TextDocumentIdentifier, Range, Url, Position, Location}; use url_serde; pub use languageserver_types::{ @@ -109,3 +109,11 @@ impl Request for MoveCursor { type Result = (); const METHOD: &'static str = "m/moveCursor"; } + +pub enum ParentModule {} + +impl Request for ParentModule { + type Params = TextDocumentIdentifier; + type Result = Vec; + const METHOD: &'static str = "m/parentModule"; +} -- cgit v1.2.3