mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Group import data in a struct
This commit is contained in:
parent
f4ae3650d8
commit
f75f07019b
5 changed files with 49 additions and 52 deletions
|
@ -1,24 +1,23 @@
|
|||
//! Renderer for `enum` variants.
|
||||
|
||||
use hir::{HasAttrs, HirDisplay, ModPath, StructKind};
|
||||
use ide_helpers::insert_use::{ImportScope, MergeBehaviour};
|
||||
use itertools::Itertools;
|
||||
use test_utils::mark;
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind},
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind, ImportToAdd},
|
||||
render::{builder_ext::Params, RenderContext},
|
||||
};
|
||||
|
||||
pub(crate) fn render_enum_variant<'a>(
|
||||
ctx: RenderContext<'a>,
|
||||
import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
|
||||
import_to_add: Option<ImportToAdd>,
|
||||
local_name: Option<String>,
|
||||
variant: hir::EnumVariant,
|
||||
path: Option<ModPath>,
|
||||
) -> CompletionItem {
|
||||
let _p = profile::span("render_enum_variant");
|
||||
EnumVariantRender::new(ctx, local_name, variant, path).render(import_data)
|
||||
EnumVariantRender::new(ctx, local_name, variant, path).render(import_to_add)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -63,10 +62,7 @@ impl<'a> EnumVariantRender<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn render(
|
||||
self,
|
||||
import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
|
||||
) -> CompletionItem {
|
||||
fn render(self, import_to_add: Option<ImportToAdd>) -> CompletionItem {
|
||||
let mut builder = CompletionItem::new(
|
||||
CompletionKind::Reference,
|
||||
self.ctx.source_range(),
|
||||
|
@ -75,7 +71,7 @@ impl<'a> EnumVariantRender<'a> {
|
|||
.kind(CompletionItemKind::EnumVariant)
|
||||
.set_documentation(self.variant.docs(self.ctx.db()))
|
||||
.set_deprecated(self.ctx.is_deprecated(self.variant))
|
||||
.import_data(import_data)
|
||||
.add_import(import_to_add)
|
||||
.detail(self.detail());
|
||||
|
||||
if self.variant_kind == StructKind::Tuple {
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
//! Renderer for function calls.
|
||||
|
||||
use hir::{HasSource, ModPath, Type};
|
||||
use ide_helpers::insert_use::{ImportScope, MergeBehaviour};
|
||||
use hir::{HasSource, Type};
|
||||
use syntax::{ast::Fn, display::function_declaration};
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind},
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind, ImportToAdd},
|
||||
render::{builder_ext::Params, RenderContext},
|
||||
};
|
||||
|
||||
pub(crate) fn render_fn<'a>(
|
||||
ctx: RenderContext<'a>,
|
||||
import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
|
||||
import_to_add: Option<ImportToAdd>,
|
||||
local_name: Option<String>,
|
||||
fn_: hir::Function,
|
||||
) -> CompletionItem {
|
||||
let _p = profile::span("render_fn");
|
||||
FunctionRender::new(ctx, local_name, fn_).render(import_data)
|
||||
FunctionRender::new(ctx, local_name, fn_).render(import_to_add)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -39,10 +38,7 @@ impl<'a> FunctionRender<'a> {
|
|||
FunctionRender { ctx, name, fn_, ast_node }
|
||||
}
|
||||
|
||||
fn render(
|
||||
self,
|
||||
import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
|
||||
) -> CompletionItem {
|
||||
fn render(self, import_to_add: Option<ImportToAdd>) -> CompletionItem {
|
||||
let params = self.params();
|
||||
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), self.name.clone())
|
||||
.kind(self.kind())
|
||||
|
@ -50,7 +46,7 @@ impl<'a> FunctionRender<'a> {
|
|||
.set_deprecated(self.ctx.is_deprecated(self.fn_))
|
||||
.detail(self.detail())
|
||||
.add_call_parens(self.ctx.completion, self.name, params)
|
||||
.import_data(import_data)
|
||||
.add_import(import_to_add)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
//! Renderer for macro invocations.
|
||||
|
||||
use hir::{Documentation, HasSource, ModPath};
|
||||
use ide_helpers::insert_use::{ImportScope, MergeBehaviour};
|
||||
use hir::{Documentation, HasSource};
|
||||
use syntax::display::macro_label;
|
||||
use test_utils::mark;
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind},
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind, ImportToAdd},
|
||||
render::RenderContext,
|
||||
};
|
||||
|
||||
pub(crate) fn render_macro<'a>(
|
||||
ctx: RenderContext<'a>,
|
||||
// TODO kb add some object instead of a tuple?
|
||||
import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
|
||||
import_to_add: Option<ImportToAdd>,
|
||||
name: String,
|
||||
macro_: hir::MacroDef,
|
||||
) -> Option<CompletionItem> {
|
||||
let _p = profile::span("render_macro");
|
||||
MacroRender::new(ctx, name, macro_).render(import_data)
|
||||
MacroRender::new(ctx, name, macro_).render(import_to_add)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -40,10 +38,7 @@ impl<'a> MacroRender<'a> {
|
|||
MacroRender { ctx, name, macro_, docs, bra, ket }
|
||||
}
|
||||
|
||||
fn render(
|
||||
&self,
|
||||
import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
|
||||
) -> Option<CompletionItem> {
|
||||
fn render(&self, import_to_add: Option<ImportToAdd>) -> Option<CompletionItem> {
|
||||
// FIXME: Currently proc-macro do not have ast-node,
|
||||
// such that it does not have source
|
||||
if self.macro_.is_proc_macro() {
|
||||
|
@ -55,7 +50,7 @@ impl<'a> MacroRender<'a> {
|
|||
.kind(CompletionItemKind::Macro)
|
||||
.set_documentation(self.docs.clone())
|
||||
.set_deprecated(self.ctx.is_deprecated(self.macro_))
|
||||
.import_data(import_data)
|
||||
.add_import(import_to_add)
|
||||
.detail(self.detail());
|
||||
|
||||
let needs_bang = self.needs_bang();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue