Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
103 changes: 13 additions & 90 deletions crates/ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
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);
_ => (),
}
} else if let Some(it) = ast::IdentPat::cast(node.clone()) {
get_bind_pat_hints(&mut res, &sema, config, it);
}
}
res
Expand Down Expand Up @@ -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",
},
]
"#]],
);
}
}