diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-15 15:53:15 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-15 15:53:15 +0000 |
commit | eec64ec01b0553aca855df8146965ed6c6746e7d (patch) | |
tree | 40e81ae73928c85bbd6ab452fd317383cf5322d8 /crates/ide_completion/src/render | |
parent | b8a85e960398ebab4624574f9c2ed9c655612d56 (diff) | |
parent | db8bcf132c901cc9b9f993b17b1e648f55c35e78 (diff) |
Merge #7992
7992: improved completion sorting for functions and methods r=JoshMcguigan a=JoshMcguigan
This PR improves completion sorting for functions and methods. Related to #7935.
### Before
The methods are being sorted by `coc` by closeness in file.
![pre-fn-relevance](https://user-images.githubusercontent.com/22216761/111018669-fe3d3f00-836e-11eb-9607-cc05af080a6a.png)
### After
Notice `bbb()` on top (type + name match), followed by `ddd()` (type match).
![image](https://user-images.githubusercontent.com/22216761/111018680-0e551e80-836f-11eb-94b1-c88336ecbc6e.png)
Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/render')
-rw-r--r-- | crates/ide_completion/src/render/function.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index f4dabe3d1..47e26a5d8 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs | |||
@@ -5,7 +5,7 @@ use ide_db::SymbolKind; | |||
5 | use syntax::ast::Fn; | 5 | use syntax::ast::Fn; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | item::{CompletionItem, CompletionItemKind, CompletionKind, ImportEdit}, | 8 | item::{CompletionItem, CompletionItemKind, CompletionKind, CompletionRelevance, ImportEdit}, |
9 | render::{builder_ext::Params, RenderContext}, | 9 | render::{builder_ext::Params, RenderContext}, |
10 | }; | 10 | }; |
11 | 11 | ||
@@ -55,6 +55,21 @@ impl<'a> FunctionRender<'a> { | |||
55 | .add_call_parens(self.ctx.completion, self.name, params) | 55 | .add_call_parens(self.ctx.completion, self.name, params) |
56 | .add_import(import_to_add); | 56 | .add_import(import_to_add); |
57 | 57 | ||
58 | let mut relevance = CompletionRelevance::default(); | ||
59 | if let Some(expected_type) = &self.ctx.completion.expected_type { | ||
60 | let ret_ty = self.func.ret_type(self.ctx.db()); | ||
61 | |||
62 | // We don't ever consider a function which returns unit type to be an | ||
63 | // exact type match, since nearly always this is not meaningful to the | ||
64 | // user. | ||
65 | relevance.exact_type_match = &ret_ty == expected_type && !ret_ty.is_unit(); | ||
66 | } | ||
67 | if let Some(expected_name) = &self.ctx.completion.expected_name { | ||
68 | relevance.exact_name_match = | ||
69 | expected_name == &self.func.name(self.ctx.db()).to_string(); | ||
70 | } | ||
71 | item.set_relevance(relevance); | ||
72 | |||
58 | item.build() | 73 | item.build() |
59 | } | 74 | } |
60 | 75 | ||