mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Fix the range of a hover request to be more in line with prior art
This commit is contained in:
parent
66f656134f
commit
3d3026dc60
1 changed files with 8 additions and 1 deletions
|
@ -506,12 +506,19 @@ pub fn handle_hover(
|
||||||
) -> Result<Option<Hover>> {
|
) -> Result<Option<Hover>> {
|
||||||
let position = params.try_conv_with(&world)?;
|
let position = params.try_conv_with(&world)?;
|
||||||
let line_index = world.analysis().file_line_index(position.file_id);
|
let line_index = world.analysis().file_line_index(position.file_id);
|
||||||
|
let file = world.analysis().file_syntax(position.file_id);
|
||||||
|
|
||||||
for (file_id, symbol) in world.analysis().approximately_resolve_symbol(position)? {
|
for (file_id, symbol) in world.analysis().approximately_resolve_symbol(position)? {
|
||||||
let range = symbol.node_range.conv_with(&line_index);
|
|
||||||
let comment = world.analysis.doc_comment_for(file_id, symbol)?;
|
let comment = world.analysis.doc_comment_for(file_id, symbol)?;
|
||||||
|
|
||||||
if comment.is_some() {
|
if comment.is_some() {
|
||||||
|
let range = match ra_syntax::algo::find_leaf_at_offset(file.syntax(), position.offset)
|
||||||
|
.left_biased()
|
||||||
|
{
|
||||||
|
None => return Ok(None),
|
||||||
|
Some(it) => it.range(),
|
||||||
|
};
|
||||||
|
let range = range.conv_with(&line_index);
|
||||||
let contents = HoverContents::Scalar(MarkedString::String(comment.unwrap()));
|
let contents = HoverContents::Scalar(MarkedString::String(comment.unwrap()));
|
||||||
|
|
||||||
return Ok(Some(Hover {
|
return Ok(Some(Hover {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue