mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Merge #10240
10240: internal: Revert attributed items inlay hints r=Veykril a=Veykril Reverts #10231 as the implementation there is actually wrong bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
726a2aa211
@ -184,14 +184,6 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||
self.imp.descend_into_macros(token)
|
||||
}
|
||||
|
||||
pub fn descend_node_at_offset<N: ast::AstNode>(
|
||||
&self,
|
||||
node: &SyntaxNode,
|
||||
offset: TextSize,
|
||||
) -> Option<N> {
|
||||
self.imp.descend_node_at_offset(node, offset).flatten().find_map(N::cast)
|
||||
}
|
||||
|
||||
pub fn hir_file_for(&self, syntax_node: &SyntaxNode) -> HirFileId {
|
||||
self.imp.find_file(syntax_node.clone()).file_id
|
||||
}
|
||||
|
@ -62,38 +62,24 @@ pub(crate) fn inlay_hints(
|
||||
let _p = profile::span("inlay_hints");
|
||||
let sema = Semantics::new(db);
|
||||
let file = sema.parse(file_id);
|
||||
let file = file.syntax();
|
||||
|
||||
let mut res = Vec::new();
|
||||
let mut queue = vec![file.syntax().preorder()];
|
||||
|
||||
while let Some(mut preorder) = queue.pop() {
|
||||
while let Some(event) = preorder.next() {
|
||||
let node = match event {
|
||||
syntax::WalkEvent::Enter(node) => node,
|
||||
syntax::WalkEvent::Leave(_) => continue,
|
||||
};
|
||||
if let Some(node) =
|
||||
ast::Item::cast(node.clone()).and_then(|item| sema.expand_attr_macro(&item))
|
||||
{
|
||||
preorder.skip_subtree();
|
||||
queue.push(node.preorder());
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(expr) = ast::Expr::cast(node.clone()) {
|
||||
get_chaining_hints(&mut res, &sema, config, &expr);
|
||||
match expr {
|
||||
ast::Expr::CallExpr(it) => {
|
||||
get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it));
|
||||
}
|
||||
ast::Expr::MethodCallExpr(it) => {
|
||||
get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it));
|
||||
}
|
||||
_ => (),
|
||||
for node in file.descendants() {
|
||||
if let Some(expr) = ast::Expr::cast(node.clone()) {
|
||||
get_chaining_hints(&mut res, &sema, config, &expr);
|
||||
match expr {
|
||||
ast::Expr::CallExpr(it) => {
|
||||
get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it));
|
||||
}
|
||||
} else if let Some(it) = ast::IdentPat::cast(node.clone()) {
|
||||
get_bind_pat_hints(&mut res, &sema, config, it);
|
||||
ast::Expr::MethodCallExpr(it) => {
|
||||
get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
} else if let Some(it) = ast::IdentPat::cast(node.clone()) {
|
||||
get_bind_pat_hints(&mut res, &sema, config, it);
|
||||
}
|
||||
}
|
||||
res
|
||||
@ -1485,67 +1471,4 @@ fn main() {
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hints_in_attr_call() {
|
||||
// chaining hints do not currently work as macros lose all whitespace information
|
||||
check_expect(
|
||||
TEST_CONFIG,
|
||||
r#"
|
||||
//- proc_macros: identity, input_replace
|
||||
struct Struct;
|
||||
impl Struct {
|
||||
fn chain(self) -> Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[proc_macros::identity]
|
||||
fn main() {
|
||||
let strukt = Struct;
|
||||
strukt
|
||||
.chain()
|
||||
.chain()
|
||||
.chain();
|
||||
Struct::chain(strukt);
|
||||
}
|
||||
|
||||
#[proc_macros::input_replace(
|
||||
fn not_main() {
|
||||
let strukt = Struct;
|
||||
strukt
|
||||
.chain()
|
||||
.chain()
|
||||
.chain();
|
||||
Struct::chain(strukt);
|
||||
}
|
||||
)]
|
||||
fn main() {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
[
|
||||
InlayHint {
|
||||
range: 297..303,
|
||||
kind: TypeHint,
|
||||
label: "Struct",
|
||||
},
|
||||
InlayHint {
|
||||
range: 415..421,
|
||||
kind: ParameterHint,
|
||||
label: "self",
|
||||
},
|
||||
InlayHint {
|
||||
range: 125..131,
|
||||
kind: TypeHint,
|
||||
label: "Struct",
|
||||
},
|
||||
InlayHint {
|
||||
range: 223..229,
|
||||
kind: ParameterHint,
|
||||
label: "self",
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user