Merge #9812
9812: fix: add `!` to macro completions with existing arg r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
f0d32591a6
@ -49,15 +49,19 @@ fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> {
|
||||
.add_import(import_to_add)
|
||||
.set_detail(self.detail());
|
||||
|
||||
let needs_bang = self.needs_bang();
|
||||
let needs_bang = !(self.ctx.completion.in_use_tree()
|
||||
|| matches!(self.ctx.completion.path_call_kind(), Some(CallKind::Mac)));
|
||||
let has_parens = self.ctx.completion.path_call_kind().is_some();
|
||||
|
||||
match self.ctx.snippet_cap() {
|
||||
Some(cap) if needs_bang => {
|
||||
let snippet = self.snippet();
|
||||
let lookup = self.lookup();
|
||||
Some(cap) if needs_bang && !has_parens => {
|
||||
let snippet = format!("{}!{}$0{}", self.name, self.bra, self.ket);
|
||||
let lookup = self.banged_name();
|
||||
item.insert_snippet(cap, snippet).lookup_by(lookup);
|
||||
}
|
||||
None if needs_bang => {
|
||||
item.insert_text(self.banged_name());
|
||||
_ if needs_bang => {
|
||||
let lookup = self.banged_name();
|
||||
item.insert_text(self.banged_name()).lookup_by(lookup);
|
||||
}
|
||||
_ => {
|
||||
cov_mark::hit!(dont_insert_macro_call_parens_unncessary);
|
||||
@ -83,14 +87,6 @@ fn label(&self) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn snippet(&self) -> String {
|
||||
format!("{}!{}$0{}", self.name, self.bra, self.ket)
|
||||
}
|
||||
|
||||
fn lookup(&self) -> String {
|
||||
self.banged_name()
|
||||
}
|
||||
|
||||
fn banged_name(&self) -> String {
|
||||
format!("{}!", self.name)
|
||||
}
|
||||
@ -163,6 +159,25 @@ macro_rules! frobnicate { () => () }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_bang_to_parens() {
|
||||
check_edit(
|
||||
"frobnicate!",
|
||||
r#"
|
||||
macro_rules! frobnicate { () => () }
|
||||
fn main() {
|
||||
frob$0()
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
macro_rules! frobnicate { () => () }
|
||||
fn main() {
|
||||
frobnicate!()
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guesses_macro_braces() {
|
||||
check_edit(
|
||||
|
Loading…
Reference in New Issue
Block a user