mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Skip trival token in original_range
This commit is contained in:
parent
2dee0779e9
commit
553254973e
4 changed files with 54 additions and 23 deletions
|
@ -174,6 +174,10 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||
.ancestors()
|
||||
.find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?;
|
||||
|
||||
// FIXME: Currently `hover::typeof` do not work inside
|
||||
// macro expansion such that if the hover range is pointing to
|
||||
// a string literal, the following type_of will return None.
|
||||
// See also `test_hover_through_literal_string_in_macro`
|
||||
let frange = sema.original_range(&node);
|
||||
res.extend(type_of(db, frange).map(rust_code_markup));
|
||||
if res.is_empty() {
|
||||
|
@ -250,6 +254,11 @@ mod tests {
|
|||
content[hover.range].to_string()
|
||||
}
|
||||
|
||||
fn check_hover_no_result(fixture: &str) {
|
||||
let (analysis, position) = analysis_and_position(fixture);
|
||||
assert!(analysis.hover(position).unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hover_shows_type_of_an_expression() {
|
||||
let (analysis, position) = single_file_with_position(
|
||||
|
@ -774,6 +783,24 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
|||
assert_eq!(hover_on, "bar")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hover_through_literal_string_in_macro() {
|
||||
// FIXME: Currently `hover::type_of` do not work inside
|
||||
// macro expansion
|
||||
check_hover_no_result(
|
||||
r#"
|
||||
//- /lib.rs
|
||||
macro_rules! arr {
|
||||
($($tt:tt)*) => { [$($tt)*)] }
|
||||
}
|
||||
fn foo() {
|
||||
let mastered_for_itunes = "";
|
||||
let _ = arr!("Tr<|>acks", &mastered_for_itunes);
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hover_non_ascii_space_doc() {
|
||||
check_hover_result(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue