Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide_completion/src/render/function.rs')
-rw-r--r--crates/ide_completion/src/render/function.rs53
1 files changed, 15 insertions, 38 deletions
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs
index 86dfbf7fc8..918210f2f3 100644
--- a/crates/ide_completion/src/render/function.rs
+++ b/crates/ide_completion/src/render/function.rs
@@ -1,11 +1,9 @@
//! Renderer for function calls.
-use either::Either;
-use hir::{AsAssocItem, HasSource, HirDisplay};
+use hir::{AsAssocItem, HirDisplay};
use ide_db::SymbolKind;
use itertools::Itertools;
use stdx::format_to;
-use syntax::ast;
use crate::{
item::{CompletionItem, CompletionItemKind, CompletionRelevance, ImportEdit},
@@ -42,21 +40,6 @@ struct FunctionRender<'a> {
name: hir::Name,
receiver: Option<hir::Name>,
func: hir::Function,
- /// NB: having `ast::Fn` here might or might not be a good idea. The problem
- /// with it is that, to get an `ast::`, you want to parse the corresponding
- /// source file. So, when flyimport completions suggest a bunch of
- /// functions, we spend quite some time parsing many files.
- ///
- /// We need ast because we want to access parameter names (patterns). We can
- /// add them to the hir of the function itself, but parameter names are not
- /// something hir cares otherwise.
- ///
- /// Alternatively we can reconstruct params from the function body, but that
- /// would require parsing anyway.
- ///
- /// It seems that just using `ast` is the best choice -- most of parses
- /// should be cached anyway.
- ast_node: ast::Fn,
is_method: bool,
}
@@ -69,9 +52,8 @@ impl<'a> FunctionRender<'a> {
is_method: bool,
) -> Option<FunctionRender<'a>> {
let name = local_name.unwrap_or_else(|| fn_.name(ctx.db()));
- let ast_node = fn_.source(ctx.db())?.value;
- Some(FunctionRender { ctx, name, receiver, func: fn_, ast_node, is_method })
+ Some(FunctionRender { ctx, name, receiver, func: fn_, is_method })
}
fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem {
@@ -152,25 +134,20 @@ impl<'a> FunctionRender<'a> {
}
fn params(&self) -> Params {
- let ast_params = match self.ast_node.param_list() {
- Some(it) => it,
- None => return Params::Named(Vec::new()),
- };
- let params = ast_params.params().map(Either::Right);
-
- let params = if self.ctx.completion.has_dot_receiver() || self.receiver.is_some() {
- params.zip(self.func.method_params(self.ctx.db()).unwrap_or_default()).collect()
- } else {
- ast_params
- .self_param()
- .map(Either::Left)
- .into_iter()
- .chain(params)
- .zip(self.func.assoc_fn_params(self.ctx.db()))
- .collect()
- };
+ let (params, self_param) =
+ if self.ctx.completion.has_dot_receiver() || self.receiver.is_some() {
+ (self.func.method_params(self.ctx.db()).unwrap_or_default(), None)
+ } else {
+ let self_param = self.func.self_param(self.ctx.db());
+
+ let mut assoc_params = self.func.assoc_fn_params(self.ctx.db());
+ if self_param.is_some() {
+ assoc_params.remove(0);
+ }
+ (assoc_params, self_param)
+ };
- Params::Named(params)
+ Params::Named(self_param, params)
}
fn kind(&self) -> CompletionItemKind {