mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Use both type_of and doc_text_for
This commit is contained in:
parent
6ee7788513
commit
341eb4ae87
1 changed files with 25 additions and 14 deletions
|
@ -9,7 +9,7 @@ use languageserver_types::{
|
||||||
Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover,
|
Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover,
|
||||||
HoverContents, DocumentFormattingParams, DocumentHighlight,
|
HoverContents, DocumentFormattingParams, DocumentHighlight,
|
||||||
};
|
};
|
||||||
use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity};
|
use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity, NavigationTarget};
|
||||||
use ra_syntax::{TextUnit, text_utils::intersect};
|
use ra_syntax::{TextUnit, text_utils::intersect};
|
||||||
use ra_text_edit::text_utils::contains_offset_nonstrict;
|
use ra_text_edit::text_utils::contains_offset_nonstrict;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
@ -514,29 +514,26 @@ pub fn handle_hover(
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
};
|
};
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
|
let file_id = params.text_document.try_conv_with(&world)?;
|
||||||
|
let file_range = FileRange {
|
||||||
|
file_id,
|
||||||
|
range: rr.reference_range,
|
||||||
|
};
|
||||||
|
if let Some(type_name) = get_type(&world, file_range) {
|
||||||
|
result.push(type_name);
|
||||||
|
}
|
||||||
for nav in rr.resolves_to {
|
for nav in rr.resolves_to {
|
||||||
if let Some(docs) = world.analysis().doc_text_for(nav)? {
|
if let Some(docs) = get_doc_text(&world, nav) {
|
||||||
result.push(docs);
|
result.push(docs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let range = rr.reference_range.conv_with(&line_index);
|
let range = rr.reference_range.conv_with(&line_index);
|
||||||
if result.len() > 0 {
|
if result.len() > 0 {
|
||||||
return Ok(Some(Hover {
|
return Ok(Some(Hover {
|
||||||
contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))),
|
contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))),
|
||||||
range: Some(range),
|
range: Some(range),
|
||||||
}));
|
}));
|
||||||
} else {
|
|
||||||
let file_id = params.text_document.try_conv_with(&world)?;
|
|
||||||
let file_range = FileRange {
|
|
||||||
file_id,
|
|
||||||
range: rr.reference_range,
|
|
||||||
};
|
|
||||||
if let Some(type_name) = world.analysis().type_of(file_range)? {
|
|
||||||
return Ok(Some(Hover {
|
|
||||||
contents: HoverContents::Scalar(MarkedString::String(type_name)),
|
|
||||||
range: Some(range),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -762,3 +759,17 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity {
|
||||||
WeakWarning => DiagnosticSeverity::Hint,
|
WeakWarning => DiagnosticSeverity::Hint,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_type(world: &ServerWorld, file_range: FileRange) -> Option<String> {
|
||||||
|
match world.analysis().type_of(file_range) {
|
||||||
|
Ok(result) => result,
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_doc_text(world: &ServerWorld, nav: NavigationTarget) -> Option<String> {
|
||||||
|
match world.analysis().doc_text_for(nav) {
|
||||||
|
Ok(result) => result,
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue