Merge #9693
9693: feat: Add the Hover Range capability which enables showing the type of an expression r=matklad a=alexfertel Closes https://github.com/rust-analyzer/rust-analyzer/issues/389 This PR extends the `textDocument/hover` method to allow getting the type of an expression. It looks like this:  Edit: One thing I noticed is that when hovering a selection that includes a macro it doesn't work, so maybe this would need a follow-up issue discussing what problem that may have. (PS: What a great project! I am learning a lot! 🚀) Co-authored-by: Alexander Gonzalez <alexfertel97@gmail.com> Co-authored-by: Alexander González <alexfertel97@gmail.com>
This commit is contained in:
@@ -36,7 +36,10 @@ use crate::{
|
||||
from_proto,
|
||||
global_state::{GlobalState, GlobalStateSnapshot},
|
||||
line_index::LineEndings,
|
||||
lsp_ext::{self, InlayHint, InlayHintsParams, ViewCrateGraphParams, WorkspaceSymbolParams},
|
||||
lsp_ext::{
|
||||
self, InlayHint, InlayHintsParams, PositionOrRange, ViewCrateGraphParams,
|
||||
WorkspaceSymbolParams,
|
||||
},
|
||||
lsp_utils::all_edits_are_disjoint,
|
||||
to_proto, LspError, Result,
|
||||
};
|
||||
@@ -867,15 +870,21 @@ pub(crate) fn handle_signature_help(
|
||||
|
||||
pub(crate) fn handle_hover(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_types::HoverParams,
|
||||
params: lsp_ext::HoverParams,
|
||||
) -> Result<Option<lsp_ext::Hover>> {
|
||||
let _p = profile::span("handle_hover");
|
||||
let position = from_proto::file_position(&snap, params.text_document_position_params)?;
|
||||
let info = match snap.analysis.hover(&snap.config.hover(), position)? {
|
||||
let range = match params.position {
|
||||
PositionOrRange::Position(position) => Range::new(position, position),
|
||||
PositionOrRange::Range(range) => range,
|
||||
};
|
||||
|
||||
let file_range = from_proto::file_range(&snap, params.text_document, range)?;
|
||||
let info = match snap.analysis.hover(&snap.config.hover(), file_range)? {
|
||||
None => return Ok(None),
|
||||
Some(info) => info,
|
||||
};
|
||||
let line_index = snap.file_line_index(position.file_id)?;
|
||||
|
||||
let line_index = snap.file_line_index(file_range.file_id)?;
|
||||
let range = to_proto::range(&line_index, info.range);
|
||||
let hover = lsp_ext::Hover {
|
||||
hover: lsp_types::Hover {
|
||||
|
||||
Reference in New Issue
Block a user