mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
fix textedit range returned for completion when left token is a keyword #4545
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
parent
f4f5fca101
commit
0e814a3b5f
3 changed files with 46 additions and 1 deletions
|
@ -1363,6 +1363,7 @@ impl HirDisplay for Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For IDE only
|
/// For IDE only
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum ScopeDef {
|
pub enum ScopeDef {
|
||||||
ModuleDef(ModuleDef),
|
ModuleDef(ModuleDef),
|
||||||
MacroDef(MacroDef),
|
MacroDef(MacroDef),
|
||||||
|
|
|
@ -297,6 +297,41 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn completes_bindings_from_for_with_in_prefix() {
|
||||||
|
assert_debug_snapshot!(
|
||||||
|
do_reference_completion(
|
||||||
|
r"
|
||||||
|
fn test() {
|
||||||
|
for index in &[1, 2, 3] {
|
||||||
|
let t = in<|>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
[
|
||||||
|
CompletionItem {
|
||||||
|
label: "index",
|
||||||
|
source_range: 107..107,
|
||||||
|
delete: 107..107,
|
||||||
|
insert: "index",
|
||||||
|
kind: Binding,
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "test()",
|
||||||
|
source_range: 107..107,
|
||||||
|
delete: 107..107,
|
||||||
|
insert: "test()$0",
|
||||||
|
kind: Function,
|
||||||
|
lookup: "test",
|
||||||
|
detail: "fn test()",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_generic_params() {
|
fn completes_generic_params() {
|
||||||
assert_debug_snapshot!(
|
assert_debug_snapshot!(
|
||||||
|
|
|
@ -169,7 +169,16 @@ impl<'a> CompletionContext<'a> {
|
||||||
match self.token.kind() {
|
match self.token.kind() {
|
||||||
// workaroud when completion is triggered by trigger characters.
|
// workaroud when completion is triggered by trigger characters.
|
||||||
IDENT => self.original_token.text_range(),
|
IDENT => self.original_token.text_range(),
|
||||||
_ => TextRange::empty(self.offset),
|
_ => {
|
||||||
|
// If we haven't characters between keyword and our cursor we take the keyword start range to edit
|
||||||
|
if self.token.kind().is_keyword()
|
||||||
|
&& self.offset == self.original_token.text_range().end()
|
||||||
|
{
|
||||||
|
TextRange::empty(self.original_token.text_range().start())
|
||||||
|
} else {
|
||||||
|
TextRange::empty(self.offset)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue