mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Document parentModule
experimental LSP request
This commit is contained in:
parent
a30bdd9795
commit
0ebb25b29b
7 changed files with 64 additions and 38 deletions
|
@ -86,6 +86,7 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
|
|||
"joinLines": true,
|
||||
"ssr": true,
|
||||
"onEnter": true,
|
||||
"parentModule": true,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
use lsp_types::request::Request;
|
||||
use lsp_types::{Location, Position, Range, TextDocumentIdentifier};
|
||||
use lsp_types::{Position, Range, TextDocumentIdentifier};
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -79,8 +79,8 @@ pub enum ParentModule {}
|
|||
|
||||
impl Request for ParentModule {
|
||||
type Params = lsp_types::TextDocumentPositionParams;
|
||||
type Result = Vec<Location>;
|
||||
const METHOD: &'static str = "rust-analyzer/parentModule";
|
||||
type Result = Option<lsp_types::GotoDefinitionResponse>;
|
||||
const METHOD: &'static str = "experimental/parentModule";
|
||||
}
|
||||
|
||||
pub enum JoinLines {}
|
||||
|
|
|
@ -344,11 +344,8 @@ pub fn handle_goto_definition(
|
|||
None => return Ok(None),
|
||||
Some(it) => it,
|
||||
};
|
||||
let res = to_proto::goto_definition_response(
|
||||
&world,
|
||||
FileRange { file_id: position.file_id, range: nav_info.range },
|
||||
nav_info.info,
|
||||
)?;
|
||||
let src = FileRange { file_id: position.file_id, range: nav_info.range };
|
||||
let res = to_proto::goto_definition_response(&world, Some(src), nav_info.info)?;
|
||||
Ok(Some(res))
|
||||
}
|
||||
|
||||
|
@ -362,11 +359,8 @@ pub fn handle_goto_implementation(
|
|||
None => return Ok(None),
|
||||
Some(it) => it,
|
||||
};
|
||||
let res = to_proto::goto_definition_response(
|
||||
&world,
|
||||
FileRange { file_id: position.file_id, range: nav_info.range },
|
||||
nav_info.info,
|
||||
)?;
|
||||
let src = FileRange { file_id: position.file_id, range: nav_info.range };
|
||||
let res = to_proto::goto_definition_response(&world, Some(src), nav_info.info)?;
|
||||
Ok(Some(res))
|
||||
}
|
||||
|
||||
|
@ -380,26 +374,20 @@ pub fn handle_goto_type_definition(
|
|||
None => return Ok(None),
|
||||
Some(it) => it,
|
||||
};
|
||||
let res = to_proto::goto_definition_response(
|
||||
&world,
|
||||
FileRange { file_id: position.file_id, range: nav_info.range },
|
||||
nav_info.info,
|
||||
)?;
|
||||
let src = FileRange { file_id: position.file_id, range: nav_info.range };
|
||||
let res = to_proto::goto_definition_response(&world, Some(src), nav_info.info)?;
|
||||
Ok(Some(res))
|
||||
}
|
||||
|
||||
pub fn handle_parent_module(
|
||||
world: WorldSnapshot,
|
||||
params: lsp_types::TextDocumentPositionParams,
|
||||
) -> Result<Vec<Location>> {
|
||||
) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
|
||||
let _p = profile("handle_parent_module");
|
||||
let position = from_proto::file_position(&world, params)?;
|
||||
world
|
||||
.analysis()
|
||||
.parent_module(position)?
|
||||
.into_iter()
|
||||
.map(|it| to_proto::location(&world, it.file_range()))
|
||||
.collect::<Result<Vec<_>>>()
|
||||
let navs = world.analysis().parent_module(position)?;
|
||||
let res = to_proto::goto_definition_response(&world, None, navs)?;
|
||||
Ok(Some(res))
|
||||
}
|
||||
|
||||
pub fn handle_runnables(
|
||||
|
|
|
@ -403,13 +403,20 @@ pub(crate) fn location(world: &WorldSnapshot, frange: FileRange) -> Result<lsp_t
|
|||
|
||||
pub(crate) fn location_link(
|
||||
world: &WorldSnapshot,
|
||||
src: FileRange,
|
||||
src: Option<FileRange>,
|
||||
target: NavigationTarget,
|
||||
) -> Result<lsp_types::LocationLink> {
|
||||
let src_location = location(world, src)?;
|
||||
let origin_selection_range = match src {
|
||||
Some(src) => {
|
||||
let line_index = world.analysis().file_line_index(src.file_id)?;
|
||||
let range = range(&line_index, src.range);
|
||||
Some(range)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let (target_uri, target_range, target_selection_range) = location_info(world, target)?;
|
||||
let res = lsp_types::LocationLink {
|
||||
origin_selection_range: Some(src_location.range),
|
||||
origin_selection_range,
|
||||
target_uri,
|
||||
target_range,
|
||||
target_selection_range,
|
||||
|
@ -432,7 +439,7 @@ fn location_info(
|
|||
|
||||
pub(crate) fn goto_definition_response(
|
||||
world: &WorldSnapshot,
|
||||
src: FileRange,
|
||||
src: Option<FileRange>,
|
||||
targets: Vec<NavigationTarget>,
|
||||
) -> Result<lsp_types::GotoDefinitionResponse> {
|
||||
if world.config.client_caps.location_link {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue