mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
134701885d
commit
31519bb394
83 changed files with 2092 additions and 626 deletions
|
@ -1664,6 +1664,40 @@ fn f() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn goto_await_into_future_poll() {
|
||||
check(
|
||||
r#"
|
||||
//- minicore: future
|
||||
|
||||
struct Futurable;
|
||||
|
||||
impl core::future::IntoFuture for Futurable {
|
||||
type IntoFuture = MyFut;
|
||||
}
|
||||
|
||||
struct MyFut;
|
||||
|
||||
impl core::future::Future for MyFut {
|
||||
type Output = ();
|
||||
|
||||
fn poll(
|
||||
//^^^^
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>
|
||||
) -> std::task::Poll<Self::Output>
|
||||
{
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
fn f() {
|
||||
Futurable.await$0;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn goto_try_op() {
|
||||
check(
|
||||
|
|
|
@ -27,6 +27,7 @@ use crate::{
|
|||
pub struct HoverConfig {
|
||||
pub links_in_hover: bool,
|
||||
pub documentation: Option<HoverDocFormat>,
|
||||
pub keywords: bool,
|
||||
}
|
||||
|
||||
impl HoverConfig {
|
||||
|
@ -119,6 +120,8 @@ pub(crate) fn hover(
|
|||
}
|
||||
|
||||
let in_attr = matches!(original_token.parent().and_then(ast::TokenTree::cast), Some(tt) if tt.syntax().ancestors().any(|it| ast::Meta::can_cast(it.kind())));
|
||||
// prefer descending the same token kind in attribute expansions, in normal macros text
|
||||
// equivalency is more important
|
||||
let descended = if in_attr {
|
||||
[sema.descend_into_macros_with_kind_preference(original_token.clone())].into()
|
||||
} else {
|
||||
|
|
|
@ -230,7 +230,7 @@ pub(super) fn keyword(
|
|||
config: &HoverConfig,
|
||||
token: &SyntaxToken,
|
||||
) -> Option<HoverResult> {
|
||||
if !token.kind().is_keyword() || !config.documentation.is_some() {
|
||||
if !token.kind().is_keyword() || !config.documentation.is_some() || !config.keywords {
|
||||
return None;
|
||||
}
|
||||
let parent = token.parent()?;
|
||||
|
|
|
@ -8,7 +8,11 @@ fn check_hover_no_result(ra_fixture: &str) {
|
|||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
|
||||
&HoverConfig {
|
||||
links_in_hover: true,
|
||||
documentation: Some(HoverDocFormat::Markdown),
|
||||
keywords: true,
|
||||
},
|
||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -20,7 +24,11 @@ fn check(ra_fixture: &str, expect: Expect) {
|
|||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
|
||||
&HoverConfig {
|
||||
links_in_hover: true,
|
||||
documentation: Some(HoverDocFormat::Markdown),
|
||||
keywords: true,
|
||||
},
|
||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||
)
|
||||
.unwrap()
|
||||
|
@ -37,7 +45,11 @@ fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
|
|||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
|
||||
&HoverConfig {
|
||||
links_in_hover: false,
|
||||
documentation: Some(HoverDocFormat::Markdown),
|
||||
keywords: true,
|
||||
},
|
||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||
)
|
||||
.unwrap()
|
||||
|
@ -54,7 +66,11 @@ fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
|
|||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::PlainText) },
|
||||
&HoverConfig {
|
||||
links_in_hover: true,
|
||||
documentation: Some(HoverDocFormat::PlainText),
|
||||
keywords: true,
|
||||
},
|
||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||
)
|
||||
.unwrap()
|
||||
|
@ -71,7 +87,11 @@ fn check_actions(ra_fixture: &str, expect: Expect) {
|
|||
let (analysis, file_id, position) = fixture::range_or_position(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
|
||||
&HoverConfig {
|
||||
links_in_hover: true,
|
||||
documentation: Some(HoverDocFormat::Markdown),
|
||||
keywords: true,
|
||||
},
|
||||
FileRange { file_id, range: position.range_or_empty() },
|
||||
)
|
||||
.unwrap()
|
||||
|
@ -83,7 +103,11 @@ fn check_hover_range(ra_fixture: &str, expect: Expect) {
|
|||
let (analysis, range) = fixture::range(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
|
||||
&HoverConfig {
|
||||
links_in_hover: false,
|
||||
documentation: Some(HoverDocFormat::Markdown),
|
||||
keywords: true,
|
||||
},
|
||||
range,
|
||||
)
|
||||
.unwrap()
|
||||
|
@ -95,7 +119,11 @@ fn check_hover_range_no_results(ra_fixture: &str) {
|
|||
let (analysis, range) = fixture::range(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
|
||||
&HoverConfig {
|
||||
links_in_hover: false,
|
||||
documentation: Some(HoverDocFormat::Markdown),
|
||||
keywords: true,
|
||||
},
|
||||
range,
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -130,8 +130,11 @@ impl StaticIndex<'_> {
|
|||
syntax::NodeOrToken::Node(_) => None,
|
||||
syntax::NodeOrToken::Token(x) => Some(x),
|
||||
});
|
||||
let hover_config =
|
||||
HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) };
|
||||
let hover_config = HoverConfig {
|
||||
links_in_hover: true,
|
||||
documentation: Some(HoverDocFormat::Markdown),
|
||||
keywords: true,
|
||||
};
|
||||
let tokens = tokens.filter(|token| {
|
||||
matches!(
|
||||
token.kind(),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use hir::{Function, Semantics};
|
||||
use hir::{DefWithBody, Semantics};
|
||||
use ide_db::base_db::FilePosition;
|
||||
use ide_db::RootDatabase;
|
||||
use syntax::{algo::find_node_at_offset, ast, AstNode};
|
||||
|
@ -19,8 +19,12 @@ fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {
|
|||
let sema = Semantics::new(db);
|
||||
let source_file = sema.parse(position.file_id);
|
||||
|
||||
let function = find_node_at_offset::<ast::Fn>(source_file.syntax(), position.offset)?;
|
||||
|
||||
let function: Function = sema.to_def(&function)?;
|
||||
Some(function.debug_hir(db))
|
||||
let item = find_node_at_offset::<ast::Item>(source_file.syntax(), position.offset)?;
|
||||
let def: DefWithBody = match item {
|
||||
ast::Item::Fn(it) => sema.to_def(&it)?.into(),
|
||||
ast::Item::Const(it) => sema.to_def(&it)?.into(),
|
||||
ast::Item::Static(it) => sema.to_def(&it)?.into(),
|
||||
_ => return None,
|
||||
};
|
||||
Some(def.debug_hir(db))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue