From caf0fa20a7d895612ceee1948d6a9895e53bee4a Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Tue, 3 Nov 2020 10:17:59 +0300 Subject: Provide only explicit constructor for RenderContext --- crates/completion/src/completions.rs | 22 +++++++++++++--------- crates/completion/src/render.rs | 8 +------- 2 files changed, 14 insertions(+), 16 deletions(-) (limited to 'crates/completion') diff --git a/crates/completion/src/completions.rs b/crates/completion/src/completions.rs index b54771fcd..d59f5ca05 100644 --- a/crates/completion/src/completions.rs +++ b/crates/completion/src/completions.rs @@ -52,12 +52,12 @@ impl Completions { } pub(crate) fn add_field(&mut self, ctx: &CompletionContext, field: hir::Field, ty: &Type) { - let item = Render::new(ctx.into()).add_field(field, ty); + let item = Render::new(RenderContext::new(ctx)).add_field(field, ty); self.add(item); } pub(crate) fn add_tuple_field(&mut self, ctx: &CompletionContext, field: usize, ty: &Type) { - let item = Render::new(ctx.into()).add_tuple_field(field, ty); + let item = Render::new(RenderContext::new(ctx)).add_tuple_field(field, ty); self.add(item); } @@ -67,7 +67,9 @@ impl Completions { local_name: String, resolution: &ScopeDef, ) { - if let Some(item) = Render::new(ctx.into()).render_resolution(local_name, resolution) { + if let Some(item) = + Render::new(RenderContext::new(ctx)).render_resolution(local_name, resolution) + { self.add(item); } } @@ -82,7 +84,7 @@ impl Completions { Some(it) => it, None => return, }; - if let Some(item) = MacroRender::new(ctx.into(), name, macro_).render() { + if let Some(item) = MacroRender::new(RenderContext::new(ctx), name, macro_).render() { self.add(item); } } @@ -93,18 +95,18 @@ impl Completions { func: hir::Function, local_name: Option, ) { - let item = FunctionRender::new(ctx.into(), local_name, func).render(); + let item = FunctionRender::new(RenderContext::new(ctx), local_name, func).render(); self.add(item) } pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { - if let Some(item) = ConstRender::new(ctx.into(), constant).render() { + if let Some(item) = ConstRender::new(RenderContext::new(ctx), constant).render() { self.add(item); } } pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { - if let Some(item) = TypeAliasRender::new(ctx.into(), type_alias).render() { + if let Some(item) = TypeAliasRender::new(RenderContext::new(ctx), type_alias).render() { self.add(item) } } @@ -115,7 +117,8 @@ impl Completions { variant: hir::EnumVariant, path: ModPath, ) { - let item = EnumVariantRender::new(ctx.into(), None, variant, Some(path)).render(); + let item = + EnumVariantRender::new(RenderContext::new(ctx), None, variant, Some(path)).render(); self.add(item); } @@ -125,7 +128,8 @@ impl Completions { variant: hir::EnumVariant, local_name: Option, ) { - let item = EnumVariantRender::new(ctx.into(), local_name, variant, None).render(); + let item = + EnumVariantRender::new(RenderContext::new(ctx), local_name, variant, None).render(); self.add(item); } } diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index dd9edc514..dfba81734 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs @@ -36,7 +36,7 @@ pub(crate) struct RenderContext<'a> { } impl<'a> RenderContext<'a> { - fn new(completion: &'a CompletionContext<'a>) -> RenderContext<'a> { + pub(crate) fn new(completion: &'a CompletionContext<'a>) -> RenderContext<'a> { RenderContext { completion } } @@ -74,12 +74,6 @@ impl<'a> RenderContext<'a> { } } -impl<'a> From<&'a CompletionContext<'a>> for RenderContext<'a> { - fn from(ctx: &'a CompletionContext<'a>) -> RenderContext<'a> { - RenderContext::new(ctx) - } -} - impl<'a> Render<'a> { pub(crate) fn new(ctx: RenderContext<'a>) -> Render<'a> { Render { ctx } -- cgit v1.2.3