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 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'crates/server/src/main_loop') 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))?)); -- cgit v1.2.3