aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/completions.rs
diff options
context:
space:
mode:
authorIgor Aleksanov <[email protected]>2020-11-03 07:33:13 +0000
committerIgor Aleksanov <[email protected]>2020-11-03 07:33:13 +0000
commit4d333ebb6372c135e5a723da899528cc22d07faa (patch)
tree7ab4c7f113a1686d7378502e2685d3529cb6f5ba /crates/completion/src/completions.rs
parentcaf0fa20a7d895612ceee1948d6a9895e53bee4a (diff)
Get rid of do-er antipattern
Diffstat (limited to 'crates/completion/src/completions.rs')
-rw-r--r--crates/completion/src/completions.rs22
1 files changed, 9 insertions, 13 deletions
diff --git a/crates/completion/src/completions.rs b/crates/completion/src/completions.rs
index d59f5ca05..162d567d9 100644
--- a/crates/completion/src/completions.rs
+++ b/crates/completion/src/completions.rs
@@ -52,12 +52,12 @@ impl Completions {
52 } 52 }
53 53
54 pub(crate) fn add_field(&mut self, ctx: &CompletionContext, field: hir::Field, ty: &Type) { 54 pub(crate) fn add_field(&mut self, ctx: &CompletionContext, field: hir::Field, ty: &Type) {
55 let item = Render::new(RenderContext::new(ctx)).add_field(field, ty); 55 let item = render_field(RenderContext::new(ctx), field, ty);
56 self.add(item); 56 self.add(item);
57 } 57 }
58 58
59 pub(crate) fn add_tuple_field(&mut self, ctx: &CompletionContext, field: usize, ty: &Type) { 59 pub(crate) fn add_tuple_field(&mut self, ctx: &CompletionContext, field: usize, ty: &Type) {
60 let item = Render::new(RenderContext::new(ctx)).add_tuple_field(field, ty); 60 let item = render_tuple_field(RenderContext::new(ctx), field, ty);
61 self.add(item); 61 self.add(item);
62 } 62 }
63 63
@@ -67,9 +67,7 @@ impl Completions {
67 local_name: String, 67 local_name: String,
68 resolution: &ScopeDef, 68 resolution: &ScopeDef,
69 ) { 69 ) {
70 if let Some(item) = 70 if let Some(item) = render_resolution(RenderContext::new(ctx), local_name, resolution) {
71 Render::new(RenderContext::new(ctx)).render_resolution(local_name, resolution)
72 {
73 self.add(item); 71 self.add(item);
74 } 72 }
75 } 73 }
@@ -84,7 +82,7 @@ impl Completions {
84 Some(it) => it, 82 Some(it) => it,
85 None => return, 83 None => return,
86 }; 84 };
87 if let Some(item) = MacroRender::new(RenderContext::new(ctx), name, macro_).render() { 85 if let Some(item) = render_macro(RenderContext::new(ctx), name, macro_) {
88 self.add(item); 86 self.add(item);
89 } 87 }
90 } 88 }
@@ -95,18 +93,18 @@ impl Completions {
95 func: hir::Function, 93 func: hir::Function,
96 local_name: Option<String>, 94 local_name: Option<String>,
97 ) { 95 ) {
98 let item = FunctionRender::new(RenderContext::new(ctx), local_name, func).render(); 96 let item = render_fn(RenderContext::new(ctx), local_name, func);
99 self.add(item) 97 self.add(item)
100 } 98 }
101 99
102 pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { 100 pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
103 if let Some(item) = ConstRender::new(RenderContext::new(ctx), constant).render() { 101 if let Some(item) = render_const(RenderContext::new(ctx), constant) {
104 self.add(item); 102 self.add(item);
105 } 103 }
106 } 104 }
107 105
108 pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { 106 pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) {
109 if let Some(item) = TypeAliasRender::new(RenderContext::new(ctx), type_alias).render() { 107 if let Some(item) = render_type_alias(RenderContext::new(ctx), type_alias) {
110 self.add(item) 108 self.add(item)
111 } 109 }
112 } 110 }
@@ -117,8 +115,7 @@ impl Completions {
117 variant: hir::EnumVariant, 115 variant: hir::EnumVariant,
118 path: ModPath, 116 path: ModPath,
119 ) { 117 ) {
120 let item = 118 let item = render_enum_variant(RenderContext::new(ctx), None, variant, Some(path));
121 EnumVariantRender::new(RenderContext::new(ctx), None, variant, Some(path)).render();
122 self.add(item); 119 self.add(item);
123 } 120 }
124 121
@@ -128,8 +125,7 @@ impl Completions {
128 variant: hir::EnumVariant, 125 variant: hir::EnumVariant,
129 local_name: Option<String>, 126 local_name: Option<String>,
130 ) { 127 ) {
131 let item = 128 let item = render_enum_variant(RenderContext::new(ctx), local_name, variant, None);
132 EnumVariantRender::new(RenderContext::new(ctx), local_name, variant, None).render();
133 self.add(item); 129 self.add(item);
134 } 130 }
135} 131}