diff --git a/crates/ty_ide/src/completion.rs b/crates/ty_ide/src/completion.rs index 26175462a3..29f4992c05 100644 --- a/crates/ty_ide/src/completion.rs +++ b/crates/ty_ide/src/completion.rs @@ -1315,7 +1315,8 @@ fn find_typed_text( if last.end() < offset || last.range().is_empty() { return None; } - Some(source[last.range()].to_string()) + let range = TextRange::new(last.start(), offset); + Some(source[range].to_string()) } /// Whether the last token is in a place where we should not provide completions. @@ -1633,6 +1634,21 @@ mod tests { ); } + #[test] + fn inside_token() { + let test = completion_test_builder( + "\ +foo_bar_baz = 1 +x = foobad +", + ); + + assert_snapshot!( + test.skip_builtins().build().snapshot(), + @"foo_bar_baz", + ); + } + #[test] fn type_keyword_dedup() { let test = completion_test_builder(