Don't insert !() if there's already some
This commit is contained in:
parent
73ccf7f495
commit
5540193fc8
@ -50,6 +50,8 @@ pub(crate) struct CompletionContext<'a> {
|
||||
pub(super) dot_receiver_is_ambiguous_float_literal: bool,
|
||||
/// If this is a call (method or function) in particular, i.e. the () are already there.
|
||||
pub(super) is_call: bool,
|
||||
/// If this is a macro call, i.e. the () are already there.
|
||||
pub(super) is_macro_call: bool,
|
||||
pub(super) is_path_type: bool,
|
||||
pub(super) has_type_args: bool,
|
||||
}
|
||||
@ -102,6 +104,7 @@ impl<'a> CompletionContext<'a> {
|
||||
is_new_item: false,
|
||||
dot_receiver: None,
|
||||
is_call: false,
|
||||
is_macro_call: false,
|
||||
is_path_type: false,
|
||||
has_type_args: false,
|
||||
dot_receiver_is_ambiguous_float_literal: false,
|
||||
@ -269,6 +272,7 @@ impl<'a> CompletionContext<'a> {
|
||||
.and_then(ast::PathExpr::cast)
|
||||
.and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
|
||||
.is_some();
|
||||
self.is_macro_call = path.syntax().parent().and_then(ast::MacroCall::cast).is_some();
|
||||
|
||||
self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some();
|
||||
self.has_type_args = segment.type_arg_list().is_some();
|
||||
|
@ -174,7 +174,8 @@ impl Completions {
|
||||
.set_deprecated(is_deprecated(macro_, ctx.db))
|
||||
.detail(detail);
|
||||
|
||||
builder = if ctx.use_item_syntax.is_some() {
|
||||
builder = if ctx.use_item_syntax.is_some() || ctx.is_macro_call {
|
||||
tested_by!(dont_insert_macro_call_parens_unncessary);
|
||||
builder.insert_text(name)
|
||||
} else {
|
||||
let macro_braces_to_insert =
|
||||
@ -960,7 +961,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dont_insert_macro_call_braces_in_use() {
|
||||
fn dont_insert_macro_call_parens_unncessary() {
|
||||
covers!(dont_insert_macro_call_parens_unncessary);
|
||||
assert_debug_snapshot!(
|
||||
do_reference_completion(
|
||||
r"
|
||||
@ -986,6 +988,41 @@ mod tests {
|
||||
},
|
||||
]
|
||||
"###
|
||||
)
|
||||
);
|
||||
|
||||
assert_debug_snapshot!(
|
||||
do_reference_completion(
|
||||
r"
|
||||
//- /main.rs
|
||||
macro_rules frobnicate {
|
||||
() => ()
|
||||
}
|
||||
fn main() {
|
||||
frob<|>!();
|
||||
}
|
||||
"
|
||||
),
|
||||
@r###"
|
||||
[
|
||||
CompletionItem {
|
||||
label: "frobnicate!",
|
||||
source_range: [56; 60),
|
||||
delete: [56; 60),
|
||||
insert: "frobnicate",
|
||||
kind: Macro,
|
||||
detail: "macro_rules! frobnicate",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "main()",
|
||||
source_range: [56; 60),
|
||||
delete: [56; 60),
|
||||
insert: "main()$0",
|
||||
kind: Function,
|
||||
lookup: "main",
|
||||
detail: "fn main()",
|
||||
},
|
||||
]
|
||||
"###
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -7,4 +7,5 @@ test_utils::marks!(
|
||||
dont_complete_current_use
|
||||
test_resolve_parent_module_on_module_decl
|
||||
search_filters_by_range
|
||||
dont_insert_macro_call_parens_unncessary
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user