Skip to content

Commit 0c77bce

Browse files
Fix actual token lookup in completion's expand()
It should be left biased, not right biased, because when e.g. the use has typed `h` then requested completion, the `h` is what we want to find, not the next token (which might indeed be inside a macro call). I'm not sure why I wrote `right_biased()` to begin with (I remember I had a reason and not just "both should work"), I might've copied the code in `expand_and_analyze()` (which is wrong, because there it lookups on the speculative file, where right biased will always find the correct token and left biased not). This is still not perfect, because there might not be an identifier already typed then we might still end up in a macro call, but this is the best we can do.
1 parent 32b86a8 commit 0c77bce

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crates/ide-completion/src/context/analysis.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ fn expand(
123123
) -> Option<ExpansionResult> {
124124
let _p = tracing::info_span!("CompletionContext::expand").entered();
125125

126+
// Left biased since there may already be an identifier token there, and we appended to it.
126127
if !sema.might_be_inside_macro_call(&fake_ident_token)
127128
&& original_file
128129
.token_at_offset(original_offset + relative_offset)
129-
.right_biased()
130+
.left_biased()
130131
.is_some_and(|original_token| !sema.might_be_inside_macro_call(&original_token))
131132
{
132133
// Recursion base case.

0 commit comments

Comments
 (0)