diff options
Diffstat (limited to 'crates/ide_completion/src/render')
-rw-r--r-- | crates/ide_completion/src/render/builder_ext.rs | 15 | ||||
-rw-r--r-- | crates/ide_completion/src/render/const_.rs | 10 | ||||
-rw-r--r-- | crates/ide_completion/src/render/enum_variant.rs | 28 | ||||
-rw-r--r-- | crates/ide_completion/src/render/function.rs | 24 | ||||
-rw-r--r-- | crates/ide_completion/src/render/macro_.rs | 33 | ||||
-rw-r--r-- | crates/ide_completion/src/render/pattern.rs | 18 | ||||
-rw-r--r-- | crates/ide_completion/src/render/type_alias.rs | 10 |
7 files changed, 67 insertions, 71 deletions
diff --git a/crates/ide_completion/src/render/builder_ext.rs b/crates/ide_completion/src/render/builder_ext.rs index d053a988b..6d062b3b9 100644 --- a/crates/ide_completion/src/render/builder_ext.rs +++ b/crates/ide_completion/src/render/builder_ext.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! Extensions for `Builder` structure required for item rendering. | 1 | //! Extensions for `Builder` structure required for item rendering. |
2 | 2 | ||
3 | use itertools::Itertools; | 3 | use itertools::Itertools; |
4 | use test_utils::mark; | ||
5 | 4 | ||
6 | use crate::{item::Builder, CompletionContext}; | 5 | use crate::{item::Builder, CompletionContext}; |
7 | 6 | ||
@@ -30,7 +29,7 @@ impl Builder { | |||
30 | return false; | 29 | return false; |
31 | } | 30 | } |
32 | if ctx.use_item_syntax.is_some() { | 31 | if ctx.use_item_syntax.is_some() { |
33 | mark::hit!(no_parens_in_use_item); | 32 | cov_mark::hit!(no_parens_in_use_item); |
34 | return false; | 33 | return false; |
35 | } | 34 | } |
36 | if ctx.is_pattern_call { | 35 | if ctx.is_pattern_call { |
@@ -43,7 +42,7 @@ impl Builder { | |||
43 | // Don't add parentheses if the expected type is some function reference. | 42 | // Don't add parentheses if the expected type is some function reference. |
44 | if let Some(ty) = &ctx.expected_type { | 43 | if let Some(ty) = &ctx.expected_type { |
45 | if ty.is_fn() { | 44 | if ty.is_fn() { |
46 | mark::hit!(no_call_parens_if_fn_ptr_needed); | 45 | cov_mark::hit!(no_call_parens_if_fn_ptr_needed); |
47 | return false; | 46 | return false; |
48 | } | 47 | } |
49 | } | 48 | } |
@@ -53,11 +52,11 @@ impl Builder { | |||
53 | } | 52 | } |
54 | 53 | ||
55 | pub(super) fn add_call_parens( | 54 | pub(super) fn add_call_parens( |
56 | mut self, | 55 | &mut self, |
57 | ctx: &CompletionContext, | 56 | ctx: &CompletionContext, |
58 | name: String, | 57 | name: String, |
59 | params: Params, | 58 | params: Params, |
60 | ) -> Builder { | 59 | ) -> &mut Builder { |
61 | if !self.should_add_parens(ctx) { | 60 | if !self.should_add_parens(ctx) { |
62 | return self; | 61 | return self; |
63 | } | 62 | } |
@@ -67,12 +66,12 @@ impl Builder { | |||
67 | None => return self, | 66 | None => return self, |
68 | }; | 67 | }; |
69 | // If not an import, add parenthesis automatically. | 68 | // If not an import, add parenthesis automatically. |
70 | mark::hit!(inserts_parens_for_function_calls); | 69 | cov_mark::hit!(inserts_parens_for_function_calls); |
71 | 70 | ||
72 | let (snippet, label) = if params.is_empty() { | 71 | let (snippet, label) = if params.is_empty() { |
73 | (format!("{}()$0", name), format!("{}()", name)) | 72 | (format!("{}()$0", name), format!("{}()", name)) |
74 | } else { | 73 | } else { |
75 | self = self.trigger_call_info(); | 74 | self.trigger_call_info(); |
76 | let snippet = match (ctx.config.add_call_argument_snippets, params) { | 75 | let snippet = match (ctx.config.add_call_argument_snippets, params) { |
77 | (true, Params::Named(params)) => { | 76 | (true, Params::Named(params)) => { |
78 | let function_params_snippet = | 77 | let function_params_snippet = |
@@ -82,7 +81,7 @@ impl Builder { | |||
82 | format!("{}({})$0", name, function_params_snippet) | 81 | format!("{}({})$0", name, function_params_snippet) |
83 | } | 82 | } |
84 | _ => { | 83 | _ => { |
85 | mark::hit!(suppress_arg_snippets); | 84 | cov_mark::hit!(suppress_arg_snippets); |
86 | format!("{}($0)", name) | 85 | format!("{}($0)", name) |
87 | } | 86 | } |
88 | }; | 87 | }; |
diff --git a/crates/ide_completion/src/render/const_.rs b/crates/ide_completion/src/render/const_.rs index 5010b642a..8add369e4 100644 --- a/crates/ide_completion/src/render/const_.rs +++ b/crates/ide_completion/src/render/const_.rs | |||
@@ -36,17 +36,17 @@ impl<'a> ConstRender<'a> { | |||
36 | let name = self.name()?; | 36 | let name = self.name()?; |
37 | let detail = self.detail(); | 37 | let detail = self.detail(); |
38 | 38 | ||
39 | let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name) | 39 | let mut item = |
40 | .kind(SymbolKind::Const) | 40 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name); |
41 | item.kind(SymbolKind::Const) | ||
41 | .set_documentation(self.ctx.docs(self.const_)) | 42 | .set_documentation(self.ctx.docs(self.const_)) |
42 | .set_deprecated( | 43 | .set_deprecated( |
43 | self.ctx.is_deprecated(self.const_) | 44 | self.ctx.is_deprecated(self.const_) |
44 | || self.ctx.is_deprecated_assoc_item(self.const_), | 45 | || self.ctx.is_deprecated_assoc_item(self.const_), |
45 | ) | 46 | ) |
46 | .detail(detail) | 47 | .detail(detail); |
47 | .build(); | ||
48 | 48 | ||
49 | Some(item) | 49 | Some(item.build()) |
50 | } | 50 | } |
51 | 51 | ||
52 | fn name(&self) -> Option<String> { | 52 | fn name(&self) -> Option<String> { |
diff --git a/crates/ide_completion/src/render/enum_variant.rs b/crates/ide_completion/src/render/enum_variant.rs index 9214193b4..e8cfcc0c7 100644 --- a/crates/ide_completion/src/render/enum_variant.rs +++ b/crates/ide_completion/src/render/enum_variant.rs | |||
@@ -3,7 +3,6 @@ | |||
3 | use hir::{HasAttrs, HirDisplay, ModPath, StructKind}; | 3 | use hir::{HasAttrs, HirDisplay, ModPath, StructKind}; |
4 | use ide_db::SymbolKind; | 4 | use ide_db::SymbolKind; |
5 | use itertools::Itertools; | 5 | use itertools::Itertools; |
6 | use test_utils::mark; | ||
7 | 6 | ||
8 | use crate::{ | 7 | use crate::{ |
9 | item::{CompletionItem, CompletionKind, ImportEdit}, | 8 | item::{CompletionItem, CompletionKind, ImportEdit}, |
@@ -56,27 +55,26 @@ impl<'a> EnumRender<'a> { | |||
56 | } | 55 | } |
57 | 56 | ||
58 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { | 57 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { |
59 | let mut builder = CompletionItem::new( | 58 | let mut item = CompletionItem::new( |
60 | CompletionKind::Reference, | 59 | CompletionKind::Reference, |
61 | self.ctx.source_range(), | 60 | self.ctx.source_range(), |
62 | self.qualified_name.clone(), | 61 | self.qualified_name.clone(), |
63 | ) | 62 | ); |
64 | .kind(SymbolKind::Variant) | 63 | item.kind(SymbolKind::Variant) |
65 | .set_documentation(self.variant.docs(self.ctx.db())) | 64 | .set_documentation(self.variant.docs(self.ctx.db())) |
66 | .set_deprecated(self.ctx.is_deprecated(self.variant)) | 65 | .set_deprecated(self.ctx.is_deprecated(self.variant)) |
67 | .add_import(import_to_add) | 66 | .add_import(import_to_add) |
68 | .detail(self.detail()); | 67 | .detail(self.detail()); |
69 | 68 | ||
70 | if self.variant_kind == StructKind::Tuple { | 69 | if self.variant_kind == StructKind::Tuple { |
71 | mark::hit!(inserts_parens_for_tuple_enums); | 70 | cov_mark::hit!(inserts_parens_for_tuple_enums); |
72 | let params = Params::Anonymous(self.variant.fields(self.ctx.db()).len()); | 71 | let params = Params::Anonymous(self.variant.fields(self.ctx.db()).len()); |
73 | builder = | 72 | item.add_call_parens(self.ctx.completion, self.short_qualified_name, params); |
74 | builder.add_call_parens(self.ctx.completion, self.short_qualified_name, params); | ||
75 | } else if self.path.is_some() { | 73 | } else if self.path.is_some() { |
76 | builder = builder.lookup_by(self.short_qualified_name); | 74 | item.lookup_by(self.short_qualified_name); |
77 | } | 75 | } |
78 | 76 | ||
79 | builder.build() | 77 | item.build() |
80 | } | 78 | } |
81 | 79 | ||
82 | fn detail(&self) -> String { | 80 | fn detail(&self) -> String { |
@@ -103,13 +101,11 @@ impl<'a> EnumRender<'a> { | |||
103 | 101 | ||
104 | #[cfg(test)] | 102 | #[cfg(test)] |
105 | mod tests { | 103 | mod tests { |
106 | use test_utils::mark; | ||
107 | |||
108 | use crate::test_utils::check_edit; | 104 | use crate::test_utils::check_edit; |
109 | 105 | ||
110 | #[test] | 106 | #[test] |
111 | fn inserts_parens_for_tuple_enums() { | 107 | fn inserts_parens_for_tuple_enums() { |
112 | mark::check!(inserts_parens_for_tuple_enums); | 108 | cov_mark::check!(inserts_parens_for_tuple_enums); |
113 | check_edit( | 109 | check_edit( |
114 | "Some", | 110 | "Some", |
115 | r#" | 111 | r#" |
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index e46e21d24..f4dabe3d1 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs | |||
@@ -3,7 +3,6 @@ | |||
3 | use hir::{HasSource, HirDisplay, Type}; | 3 | use hir::{HasSource, HirDisplay, Type}; |
4 | use ide_db::SymbolKind; | 4 | use ide_db::SymbolKind; |
5 | use syntax::ast::Fn; | 5 | use syntax::ast::Fn; |
6 | use test_utils::mark; | ||
7 | 6 | ||
8 | use crate::{ | 7 | use crate::{ |
9 | item::{CompletionItem, CompletionItemKind, CompletionKind, ImportEdit}, | 8 | item::{CompletionItem, CompletionItemKind, CompletionKind, ImportEdit}, |
@@ -42,16 +41,21 @@ impl<'a> FunctionRender<'a> { | |||
42 | 41 | ||
43 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { | 42 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { |
44 | let params = self.params(); | 43 | let params = self.params(); |
45 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), self.name.clone()) | 44 | let mut item = CompletionItem::new( |
46 | .kind(self.kind()) | 45 | CompletionKind::Reference, |
46 | self.ctx.source_range(), | ||
47 | self.name.clone(), | ||
48 | ); | ||
49 | item.kind(self.kind()) | ||
47 | .set_documentation(self.ctx.docs(self.func)) | 50 | .set_documentation(self.ctx.docs(self.func)) |
48 | .set_deprecated( | 51 | .set_deprecated( |
49 | self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func), | 52 | self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func), |
50 | ) | 53 | ) |
51 | .detail(self.detail()) | 54 | .detail(self.detail()) |
52 | .add_call_parens(self.ctx.completion, self.name, params) | 55 | .add_call_parens(self.ctx.completion, self.name, params) |
53 | .add_import(import_to_add) | 56 | .add_import(import_to_add); |
54 | .build() | 57 | |
58 | item.build() | ||
55 | } | 59 | } |
56 | 60 | ||
57 | fn detail(&self) -> String { | 61 | fn detail(&self) -> String { |
@@ -82,7 +86,7 @@ impl<'a> FunctionRender<'a> { | |||
82 | self.func.method_params(self.ctx.db()).unwrap_or_default() | 86 | self.func.method_params(self.ctx.db()).unwrap_or_default() |
83 | } else { | 87 | } else { |
84 | if let Some(s) = ast_params.self_param() { | 88 | if let Some(s) = ast_params.self_param() { |
85 | mark::hit!(parens_for_method_call_as_assoc_fn); | 89 | cov_mark::hit!(parens_for_method_call_as_assoc_fn); |
86 | params_pats.push(Some(s.to_string())); | 90 | params_pats.push(Some(s.to_string())); |
87 | } | 91 | } |
88 | self.func.assoc_fn_params(self.ctx.db()) | 92 | self.func.assoc_fn_params(self.ctx.db()) |
@@ -114,8 +118,6 @@ impl<'a> FunctionRender<'a> { | |||
114 | 118 | ||
115 | #[cfg(test)] | 119 | #[cfg(test)] |
116 | mod tests { | 120 | mod tests { |
117 | use test_utils::mark; | ||
118 | |||
119 | use crate::{ | 121 | use crate::{ |
120 | test_utils::{check_edit, check_edit_with_config, TEST_CONFIG}, | 122 | test_utils::{check_edit, check_edit_with_config, TEST_CONFIG}, |
121 | CompletionConfig, | 123 | CompletionConfig, |
@@ -123,7 +125,7 @@ mod tests { | |||
123 | 125 | ||
124 | #[test] | 126 | #[test] |
125 | fn inserts_parens_for_function_calls() { | 127 | fn inserts_parens_for_function_calls() { |
126 | mark::check!(inserts_parens_for_function_calls); | 128 | cov_mark::check!(inserts_parens_for_function_calls); |
127 | check_edit( | 129 | check_edit( |
128 | "no_args", | 130 | "no_args", |
129 | r#" | 131 | r#" |
@@ -191,7 +193,7 @@ fn bar(s: &S) { | |||
191 | 193 | ||
192 | #[test] | 194 | #[test] |
193 | fn parens_for_method_call_as_assoc_fn() { | 195 | fn parens_for_method_call_as_assoc_fn() { |
194 | mark::check!(parens_for_method_call_as_assoc_fn); | 196 | cov_mark::check!(parens_for_method_call_as_assoc_fn); |
195 | check_edit( | 197 | check_edit( |
196 | "foo", | 198 | "foo", |
197 | r#" | 199 | r#" |
@@ -213,7 +215,7 @@ fn main() { S::foo(${1:&self})$0 } | |||
213 | 215 | ||
214 | #[test] | 216 | #[test] |
215 | fn suppress_arg_snippets() { | 217 | fn suppress_arg_snippets() { |
216 | mark::check!(suppress_arg_snippets); | 218 | cov_mark::check!(suppress_arg_snippets); |
217 | check_edit_with_config( | 219 | check_edit_with_config( |
218 | CompletionConfig { add_call_argument_snippets: false, ..TEST_CONFIG }, | 220 | CompletionConfig { add_call_argument_snippets: false, ..TEST_CONFIG }, |
219 | "with_args", | 221 | "with_args", |
diff --git a/crates/ide_completion/src/render/macro_.rs b/crates/ide_completion/src/render/macro_.rs index a4535786f..3fa21ba7c 100644 --- a/crates/ide_completion/src/render/macro_.rs +++ b/crates/ide_completion/src/render/macro_.rs | |||
@@ -3,7 +3,6 @@ | |||
3 | use hir::{Documentation, HasSource}; | 3 | use hir::{Documentation, HasSource}; |
4 | use ide_db::SymbolKind; | 4 | use ide_db::SymbolKind; |
5 | use syntax::display::macro_label; | 5 | use syntax::display::macro_label; |
6 | use test_utils::mark; | ||
7 | 6 | ||
8 | use crate::{ | 7 | use crate::{ |
9 | item::{CompletionItem, CompletionKind, ImportEdit}, | 8 | item::{CompletionItem, CompletionKind, ImportEdit}, |
@@ -40,29 +39,31 @@ impl<'a> MacroRender<'a> { | |||
40 | } | 39 | } |
41 | 40 | ||
42 | fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> { | 41 | fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> { |
43 | let mut builder = | 42 | let mut item = |
44 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label()) | 43 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label()); |
45 | .kind(SymbolKind::Macro) | 44 | item.kind(SymbolKind::Macro) |
46 | .set_documentation(self.docs.clone()) | 45 | .set_documentation(self.docs.clone()) |
47 | .set_deprecated(self.ctx.is_deprecated(self.macro_)) | 46 | .set_deprecated(self.ctx.is_deprecated(self.macro_)) |
48 | .add_import(import_to_add) | 47 | .add_import(import_to_add) |
49 | .set_detail(self.detail()); | 48 | .set_detail(self.detail()); |
50 | 49 | ||
51 | let needs_bang = self.needs_bang(); | 50 | let needs_bang = self.needs_bang(); |
52 | builder = match self.ctx.snippet_cap() { | 51 | match self.ctx.snippet_cap() { |
53 | Some(cap) if needs_bang => { | 52 | Some(cap) if needs_bang => { |
54 | let snippet = self.snippet(); | 53 | let snippet = self.snippet(); |
55 | let lookup = self.lookup(); | 54 | let lookup = self.lookup(); |
56 | builder.insert_snippet(cap, snippet).lookup_by(lookup) | 55 | item.insert_snippet(cap, snippet).lookup_by(lookup); |
56 | } | ||
57 | None if needs_bang => { | ||
58 | item.insert_text(self.banged_name()); | ||
57 | } | 59 | } |
58 | None if needs_bang => builder.insert_text(self.banged_name()), | ||
59 | _ => { | 60 | _ => { |
60 | mark::hit!(dont_insert_macro_call_parens_unncessary); | 61 | cov_mark::hit!(dont_insert_macro_call_parens_unncessary); |
61 | builder.insert_text(&self.name) | 62 | item.insert_text(&self.name); |
62 | } | 63 | } |
63 | }; | 64 | }; |
64 | 65 | ||
65 | Some(builder.build()) | 66 | Some(item.build()) |
66 | } | 67 | } |
67 | 68 | ||
68 | fn needs_bang(&self) -> bool { | 69 | fn needs_bang(&self) -> bool { |
@@ -125,13 +126,11 @@ fn guess_macro_braces(macro_name: &str, docs: &str) -> (&'static str, &'static s | |||
125 | 126 | ||
126 | #[cfg(test)] | 127 | #[cfg(test)] |
127 | mod tests { | 128 | mod tests { |
128 | use test_utils::mark; | ||
129 | |||
130 | use crate::test_utils::check_edit; | 129 | use crate::test_utils::check_edit; |
131 | 130 | ||
132 | #[test] | 131 | #[test] |
133 | fn dont_insert_macro_call_parens_unncessary() { | 132 | fn dont_insert_macro_call_parens_unncessary() { |
134 | mark::check!(dont_insert_macro_call_parens_unncessary); | 133 | cov_mark::check!(dont_insert_macro_call_parens_unncessary); |
135 | check_edit( | 134 | check_edit( |
136 | "frobnicate!", | 135 | "frobnicate!", |
137 | r#" | 136 | r#" |
diff --git a/crates/ide_completion/src/render/pattern.rs b/crates/ide_completion/src/render/pattern.rs index 465dfe00c..ca2926125 100644 --- a/crates/ide_completion/src/render/pattern.rs +++ b/crates/ide_completion/src/render/pattern.rs | |||
@@ -69,19 +69,19 @@ fn build_completion( | |||
69 | ctx: RenderContext<'_>, | 69 | ctx: RenderContext<'_>, |
70 | name: String, | 70 | name: String, |
71 | pat: String, | 71 | pat: String, |
72 | item: impl HasAttrs + Copy, | 72 | def: impl HasAttrs + Copy, |
73 | ) -> CompletionItem { | 73 | ) -> CompletionItem { |
74 | let completion = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), name) | 74 | let mut item = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), name); |
75 | .kind(CompletionItemKind::Binding) | 75 | item.kind(CompletionItemKind::Binding) |
76 | .set_documentation(ctx.docs(item)) | 76 | .set_documentation(ctx.docs(def)) |
77 | .set_deprecated(ctx.is_deprecated(item)) | 77 | .set_deprecated(ctx.is_deprecated(def)) |
78 | .detail(&pat); | 78 | .detail(&pat); |
79 | let completion = if let Some(snippet_cap) = ctx.snippet_cap() { | 79 | if let Some(snippet_cap) = ctx.snippet_cap() { |
80 | completion.insert_snippet(snippet_cap, pat) | 80 | item.insert_snippet(snippet_cap, pat); |
81 | } else { | 81 | } else { |
82 | completion.insert_text(pat) | 82 | item.insert_text(pat); |
83 | }; | 83 | }; |
84 | completion.build() | 84 | item.build() |
85 | } | 85 | } |
86 | 86 | ||
87 | fn render_pat( | 87 | fn render_pat( |
diff --git a/crates/ide_completion/src/render/type_alias.rs b/crates/ide_completion/src/render/type_alias.rs index bd97c3692..e47b4c745 100644 --- a/crates/ide_completion/src/render/type_alias.rs +++ b/crates/ide_completion/src/render/type_alias.rs | |||
@@ -36,17 +36,17 @@ impl<'a> TypeAliasRender<'a> { | |||
36 | let name = self.name()?; | 36 | let name = self.name()?; |
37 | let detail = self.detail(); | 37 | let detail = self.detail(); |
38 | 38 | ||
39 | let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name) | 39 | let mut item = |
40 | .kind(SymbolKind::TypeAlias) | 40 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name); |
41 | item.kind(SymbolKind::TypeAlias) | ||
41 | .set_documentation(self.ctx.docs(self.type_alias)) | 42 | .set_documentation(self.ctx.docs(self.type_alias)) |
42 | .set_deprecated( | 43 | .set_deprecated( |
43 | self.ctx.is_deprecated(self.type_alias) | 44 | self.ctx.is_deprecated(self.type_alias) |
44 | || self.ctx.is_deprecated_assoc_item(self.type_alias), | 45 | || self.ctx.is_deprecated_assoc_item(self.type_alias), |
45 | ) | 46 | ) |
46 | .detail(detail) | 47 | .detail(detail); |
47 | .build(); | ||
48 | 48 | ||
49 | Some(item) | 49 | Some(item.build()) |
50 | } | 50 | } |
51 | 51 | ||
52 | fn name(&self) -> Option<String> { | 52 | fn name(&self) -> Option<String> { |