mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-23 09:19:39 +00:00
[ty] Only suggest completions based on text before the cursor
Previously we extracted the entire token as the query independently of the cursor position. By not doing that you avoid having to do special range handling to figure out the start position of the current token. It's likely also more intuitive from a user perspective to only consider characters left of the cursor when suggesting autocompletions.
This commit is contained in:
parent
209ea06592
commit
de32247f30
1 changed files with 17 additions and 1 deletions
|
|
@ -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 = foo<CURSOR>bad
|
||||
",
|
||||
);
|
||||
|
||||
assert_snapshot!(
|
||||
test.skip_builtins().build().snapshot(),
|
||||
@"foo_bar_baz",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_keyword_dedup() {
|
||||
let test = completion_test_builder(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue