mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
parent module request
This commit is contained in:
parent
ecc9df5f00
commit
9909875bfe
5 changed files with 52 additions and 2 deletions
|
@ -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<Vec<Location>> {
|
||||
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,
|
||||
|
|
|
@ -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::<req::GotoDefinition>(
|
||||
&mut req, pool, world, sender, handle_goto_definition,
|
||||
)?;
|
||||
handle_request_on_threadpool::<req::ParentModule>(
|
||||
&mut req, pool, world, sender, handle_parent_module,
|
||||
)?;
|
||||
dispatch::handle_request::<req::ExecuteCommand, _>(&mut req, |params, resp| {
|
||||
io.send(RawMsg::Response(resp.into_response(Ok(None))?));
|
||||
|
||||
|
|
|
@ -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<Location>;
|
||||
const METHOD: &'static str = "m/parentModule";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue