mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-04 07:35:49 +00:00
don't add () in use items
This commit is contained in:
parent
3ee7a95315
commit
c182aab546
3 changed files with 32 additions and 10 deletions
|
@ -113,4 +113,16 @@ mod tests {
|
||||||
"Foo;Bar",
|
"Foo;Bar",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dont_render_function_parens_in_use_item() {
|
||||||
|
check_reference_completion(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
mod m { pub fn foo() {} }
|
||||||
|
use crate::m::f<|>;
|
||||||
|
",
|
||||||
|
"foo",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ pub(super) struct CompletionContext<'a> {
|
||||||
pub(super) module: Option<hir::Module>,
|
pub(super) module: Option<hir::Module>,
|
||||||
pub(super) function: Option<hir::Function>,
|
pub(super) function: Option<hir::Function>,
|
||||||
pub(super) function_syntax: Option<ast::FnDef<'a>>,
|
pub(super) function_syntax: Option<ast::FnDef<'a>>,
|
||||||
|
pub(super) use_item_syntax: Option<ast::UseItem<'a>>,
|
||||||
pub(super) is_param: bool,
|
pub(super) is_param: bool,
|
||||||
/// A single-indent path, like `foo`.
|
/// A single-indent path, like `foo`.
|
||||||
pub(super) is_trivial_path: bool,
|
pub(super) is_trivial_path: bool,
|
||||||
|
@ -55,6 +56,7 @@ impl<'a> CompletionContext<'a> {
|
||||||
module,
|
module,
|
||||||
function: None,
|
function: None,
|
||||||
function_syntax: None,
|
function_syntax: None,
|
||||||
|
use_item_syntax: None,
|
||||||
is_param: false,
|
is_param: false,
|
||||||
is_trivial_path: false,
|
is_trivial_path: false,
|
||||||
path_prefix: None,
|
path_prefix: None,
|
||||||
|
@ -114,6 +116,8 @@ impl<'a> CompletionContext<'a> {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.use_item_syntax = self.leaf.ancestors().find_map(ast::UseItem::cast);
|
||||||
|
|
||||||
self.function_syntax = self
|
self.function_syntax = self
|
||||||
.leaf
|
.leaf
|
||||||
.ancestors()
|
.ancestors()
|
||||||
|
|
|
@ -140,7 +140,16 @@ impl Builder {
|
||||||
PerNs {
|
PerNs {
|
||||||
values: Some(hir::Def::Function(function)),
|
values: Some(hir::Def::Function(function)),
|
||||||
..
|
..
|
||||||
} => {
|
} => return self.from_function(ctx, function),
|
||||||
|
_ => return self,
|
||||||
|
};
|
||||||
|
self.kind = Some(kind);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_function(mut self, ctx: &CompletionContext, function: hir::Function) -> Builder {
|
||||||
|
// If not an import, add parenthesis automatically.
|
||||||
|
if ctx.use_item_syntax.is_none() {
|
||||||
if let Some(sig_info) = function.signature_info(ctx.db) {
|
if let Some(sig_info) = function.signature_info(ctx.db) {
|
||||||
if sig_info.params.is_empty() {
|
if sig_info.params.is_empty() {
|
||||||
self.snippet = Some(format!("{}()$0", self.label));
|
self.snippet = Some(format!("{}()$0", self.label));
|
||||||
|
@ -148,11 +157,8 @@ impl Builder {
|
||||||
self.snippet = Some(format!("{}($0)", self.label));
|
self.snippet = Some(format!("{}($0)", self.label));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CompletionItemKind::Function
|
|
||||||
}
|
}
|
||||||
_ => return self,
|
self.kind = Some(CompletionItemKind::Function);
|
||||||
};
|
|
||||||
self.kind = Some(kind);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue