implement a temporary workaround for #8058

This commit is contained in:
Josh Mcguigan 2021-03-21 17:30:56 -07:00
parent 858ad55437
commit 8cd94900f7
4 changed files with 37 additions and 7 deletions

View File

@ -26,7 +26,7 @@ use crate::{
render::{
const_::render_const,
enum_variant::render_variant,
function::render_fn,
function::{render_fn, render_method},
macro_::render_macro,
pattern::{render_struct_pat, render_variant_pat},
render_field, render_resolution, render_tuple_field,
@ -123,6 +123,17 @@ impl Completions {
}
}
pub(crate) fn add_method(
&mut self,
ctx: &CompletionContext,
func: hir::Function,
local_name: Option<String>,
) {
if let Some(item) = render_method(RenderContext::new(ctx), None, local_name, func) {
self.add(item)
}
}
pub(crate) fn add_variant_pat(
&mut self,
ctx: &CompletionContext,

View File

@ -51,7 +51,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &T
&& ctx.scope.module().map_or(true, |m| func.is_visible_from(ctx.db, m))
&& seen_methods.insert(func.name(ctx.db))
{
acc.add_function(ctx, func, None);
acc.add_method(ctx, func, None);
}
None::<()>
});

View File

@ -148,8 +148,10 @@ impl<'a> Render<'a> {
..CompletionRelevance::default()
});
if let Some(ref_match) = compute_ref_match(self.ctx.completion, ty) {
item.ref_match(ref_match);
if let Some(_ref_match) = compute_ref_match(self.ctx.completion, ty) {
// FIXME
// For now we don't properly calculate the edits for ref match
// completions on struct fields, so we've disabled them. See #8058.
}
item.build()

View File

@ -20,7 +20,17 @@ pub(crate) fn render_fn<'a>(
fn_: hir::Function,
) -> Option<CompletionItem> {
let _p = profile::span("render_fn");
Some(FunctionRender::new(ctx, local_name, fn_)?.render(import_to_add))
Some(FunctionRender::new(ctx, local_name, fn_, false)?.render(import_to_add))
}
pub(crate) fn render_method<'a>(
ctx: RenderContext<'a>,
import_to_add: Option<ImportEdit>,
local_name: Option<String>,
fn_: hir::Function,
) -> Option<CompletionItem> {
let _p = profile::span("render_method");
Some(FunctionRender::new(ctx, local_name, fn_, true)?.render(import_to_add))
}
#[derive(Debug)]
@ -29,6 +39,7 @@ struct FunctionRender<'a> {
name: String,
func: hir::Function,
ast_node: Fn,
is_method: bool,
}
impl<'a> FunctionRender<'a> {
@ -36,11 +47,12 @@ impl<'a> FunctionRender<'a> {
ctx: RenderContext<'a>,
local_name: Option<String>,
fn_: hir::Function,
is_method: bool,
) -> Option<FunctionRender<'a>> {
let name = local_name.unwrap_or_else(|| fn_.name(ctx.db()).to_string());
let ast_node = fn_.source(ctx.db())?.value;
Some(FunctionRender { ctx, name, func: fn_, ast_node })
Some(FunctionRender { ctx, name, func: fn_, ast_node, is_method })
}
fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem {
@ -67,7 +79,12 @@ impl<'a> FunctionRender<'a> {
});
if let Some(ref_match) = compute_ref_match(self.ctx.completion, &ret_type) {
item.ref_match(ref_match);
// FIXME
// For now we don't properly calculate the edits for ref match
// completions on methods, so we've disabled them. See #8058.
if !self.is_method {
item.ref_match(ref_match);
}
}
item.build()