diff options
Diffstat (limited to 'crates/completion/src/completions.rs')
-rw-r--r-- | crates/completion/src/completions.rs | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/crates/completion/src/completions.rs b/crates/completion/src/completions.rs deleted file mode 100644 index c3ce6e51d..000000000 --- a/crates/completion/src/completions.rs +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | //! This module defines an accumulator for completions which are going to be presented to user. | ||
2 | |||
3 | pub(crate) mod attribute; | ||
4 | pub(crate) mod dot; | ||
5 | pub(crate) mod record; | ||
6 | pub(crate) mod pattern; | ||
7 | pub(crate) mod fn_param; | ||
8 | pub(crate) mod keyword; | ||
9 | pub(crate) mod snippet; | ||
10 | pub(crate) mod qualified_path; | ||
11 | pub(crate) mod unqualified_path; | ||
12 | pub(crate) mod postfix; | ||
13 | pub(crate) mod macro_in_item_position; | ||
14 | pub(crate) mod trait_impl; | ||
15 | pub(crate) mod mod_; | ||
16 | pub(crate) mod flyimport; | ||
17 | |||
18 | use hir::{ModPath, ScopeDef, Type}; | ||
19 | |||
20 | use crate::{ | ||
21 | item::Builder, | ||
22 | render::{ | ||
23 | const_::render_const, | ||
24 | enum_variant::render_variant, | ||
25 | function::render_fn, | ||
26 | macro_::render_macro, | ||
27 | pattern::{render_struct_pat, render_variant_pat}, | ||
28 | render_field, render_resolution, render_tuple_field, | ||
29 | type_alias::render_type_alias, | ||
30 | RenderContext, | ||
31 | }, | ||
32 | CompletionContext, CompletionItem, | ||
33 | }; | ||
34 | |||
35 | /// Represents an in-progress set of completions being built. | ||
36 | #[derive(Debug, Default)] | ||
37 | pub struct Completions { | ||
38 | buf: Vec<CompletionItem>, | ||
39 | } | ||
40 | |||
41 | impl Into<Vec<CompletionItem>> for Completions { | ||
42 | fn into(self) -> Vec<CompletionItem> { | ||
43 | self.buf | ||
44 | } | ||
45 | } | ||
46 | |||
47 | impl Builder { | ||
48 | /// Convenience method, which allows to add a freshly created completion into accumulator | ||
49 | /// without binding it to the variable. | ||
50 | pub(crate) fn add_to(self, acc: &mut Completions) { | ||
51 | acc.add(self.build()) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | impl Completions { | ||
56 | pub(crate) fn add(&mut self, item: CompletionItem) { | ||
57 | self.buf.push(item.into()) | ||
58 | } | ||
59 | |||
60 | pub(crate) fn add_all<I>(&mut self, items: I) | ||
61 | where | ||
62 | I: IntoIterator, | ||
63 | I::Item: Into<CompletionItem>, | ||
64 | { | ||
65 | items.into_iter().for_each(|item| self.add(item.into())) | ||
66 | } | ||
67 | |||
68 | pub(crate) fn add_field(&mut self, ctx: &CompletionContext, field: hir::Field, ty: &Type) { | ||
69 | let item = render_field(RenderContext::new(ctx), field, ty); | ||
70 | self.add(item); | ||
71 | } | ||
72 | |||
73 | pub(crate) fn add_tuple_field(&mut self, ctx: &CompletionContext, field: usize, ty: &Type) { | ||
74 | let item = render_tuple_field(RenderContext::new(ctx), field, ty); | ||
75 | self.add(item); | ||
76 | } | ||
77 | |||
78 | pub(crate) fn add_resolution( | ||
79 | &mut self, | ||
80 | ctx: &CompletionContext, | ||
81 | local_name: String, | ||
82 | resolution: &ScopeDef, | ||
83 | ) { | ||
84 | if let Some(item) = render_resolution(RenderContext::new(ctx), local_name, resolution) { | ||
85 | self.add(item); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | pub(crate) fn add_macro( | ||
90 | &mut self, | ||
91 | ctx: &CompletionContext, | ||
92 | name: Option<String>, | ||
93 | macro_: hir::MacroDef, | ||
94 | ) { | ||
95 | let name = match name { | ||
96 | Some(it) => it, | ||
97 | None => return, | ||
98 | }; | ||
99 | if let Some(item) = render_macro(RenderContext::new(ctx), None, name, macro_) { | ||
100 | self.add(item); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | pub(crate) fn add_function( | ||
105 | &mut self, | ||
106 | ctx: &CompletionContext, | ||
107 | func: hir::Function, | ||
108 | local_name: Option<String>, | ||
109 | ) { | ||
110 | if let Some(item) = render_fn(RenderContext::new(ctx), None, local_name, func) { | ||
111 | self.add(item) | ||
112 | } | ||
113 | } | ||
114 | |||
115 | pub(crate) fn add_variant_pat( | ||
116 | &mut self, | ||
117 | ctx: &CompletionContext, | ||
118 | variant: hir::Variant, | ||
119 | local_name: Option<hir::Name>, | ||
120 | ) { | ||
121 | if let Some(item) = render_variant_pat(RenderContext::new(ctx), variant, local_name) { | ||
122 | self.add(item); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | pub(crate) fn add_struct_pat( | ||
127 | &mut self, | ||
128 | ctx: &CompletionContext, | ||
129 | strukt: hir::Struct, | ||
130 | local_name: Option<hir::Name>, | ||
131 | ) { | ||
132 | if let Some(item) = render_struct_pat(RenderContext::new(ctx), strukt, local_name) { | ||
133 | self.add(item); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { | ||
138 | if let Some(item) = render_const(RenderContext::new(ctx), constant) { | ||
139 | self.add(item); | ||
140 | } | ||
141 | } | ||
142 | |||
143 | pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { | ||
144 | if let Some(item) = render_type_alias(RenderContext::new(ctx), type_alias) { | ||
145 | self.add(item) | ||
146 | } | ||
147 | } | ||
148 | |||
149 | pub(crate) fn add_qualified_enum_variant( | ||
150 | &mut self, | ||
151 | ctx: &CompletionContext, | ||
152 | variant: hir::Variant, | ||
153 | path: ModPath, | ||
154 | ) { | ||
155 | let item = render_variant(RenderContext::new(ctx), None, None, variant, Some(path)); | ||
156 | self.add(item); | ||
157 | } | ||
158 | |||
159 | pub(crate) fn add_enum_variant( | ||
160 | &mut self, | ||
161 | ctx: &CompletionContext, | ||
162 | variant: hir::Variant, | ||
163 | local_name: Option<String>, | ||
164 | ) { | ||
165 | let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None); | ||
166 | self.add(item); | ||
167 | } | ||
168 | } | ||