From 5fd36880181cc8c6ed4bbb8ddaa47a94d5b9cc21 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 31 Jan 2022 13:10:53 +0100 Subject: [PATCH] Fix token ascension single token check being inverted --- crates/hir_expand/src/lib.rs | 14 ++++++++------ crates/ide/src/call_hierarchy.rs | 4 ++-- crates/ide/src/references.rs | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index 51899ca2f65..2750d498573 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs @@ -705,19 +705,21 @@ fn ascend_node_border_tokens( ) -> Option> { let expansion = file_id.expansion_info(db)?; - // the input node has only one token ? - let first = skip_trivia_token(node.first_token()?, Direction::Next)?; - let last = skip_trivia_token(node.last_token()?, Direction::Prev)?; + let first_token = |node: &SyntaxNode| skip_trivia_token(node.first_token()?, Direction::Next); + let last_token = |node: &SyntaxNode| skip_trivia_token(node.last_token()?, Direction::Prev); + + let first = first_token(node)?; + let last = last_token(node)?; let is_single_token = first == last; node.descendants().find_map(|it| { - let first = skip_trivia_token(it.first_token()?, Direction::Next)?; + let first = first_token(&it)?; let first = ascend_call_token(db, &expansion, InFile::new(file_id, first))?; - let last = skip_trivia_token(it.last_token()?, Direction::Prev)?; + let last = last_token(&it)?; let last = ascend_call_token(db, &expansion, InFile::new(file_id, last))?; - if (!is_single_token && first == last) || (first.file_id != last.file_id) { + if (is_single_token && first != last) || (first.file_id != last.file_id) { return None; } diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index b43de6b9e2d..31c83dbc9f9 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs @@ -405,7 +405,7 @@ fn caller() { call!(call$0ee); } "#, - expect![[r#"callee Function FileId(0) 144..159 152..158"#]], + expect![[r#"callee Function FileId(0) 152..158 152..158"#]], expect![[r#"caller Function FileId(0) 160..194 163..169 : [184..190]"#]], expect![[]], ); @@ -426,7 +426,7 @@ fn caller() { call!(callee); } "#, - expect![[r#"callee Function FileId(0) 144..159 152..158"#]], + expect![[r#"callee Function FileId(0) 152..158 152..158"#]], expect![[r#"caller Function FileId(0) 160..194 163..169 : [184..190]"#]], expect![[]], ); diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 5e6f0ef6a57..bfa3f552af4 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -1484,12 +1484,12 @@ fn f() { } "#, expect![[r#" - func Function FileId(0) 137..146 140..144 + func Function FileId(0) 140..144 140..144 FileId(0) 161..165 - func Function FileId(0) 137..146 140..144 + func Function FileId(0) 140..144 140..144 FileId(0) 181..185 "#]],