mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
move enum-variants to presentation
This commit is contained in:
parent
9af525dbd6
commit
5887c0e574
2 changed files with 21 additions and 21 deletions
|
@ -1,9 +1,8 @@
|
||||||
use join_to_string::join;
|
use hir::{Resolution};
|
||||||
use hir::{Docs, Resolution};
|
|
||||||
use ra_syntax::{AstNode, ast::NameOwner};
|
use ra_syntax::{AstNode, ast::NameOwner};
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
|
|
||||||
use crate::completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext};
|
use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext};
|
||||||
|
|
||||||
pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
let path = match &ctx.path_prefix {
|
let path = match &ctx.path_prefix {
|
||||||
|
@ -39,24 +38,9 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Enum(e) => {
|
hir::ModuleDef::Enum(e) => {
|
||||||
e.variants(ctx.db).into_iter().for_each(|variant| {
|
for variant in e.variants(ctx.db) {
|
||||||
if let Some(name) = variant.name(ctx.db) {
|
acc.add_enum_variant(ctx, variant);
|
||||||
let detail_types =
|
|
||||||
variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db));
|
|
||||||
let detail =
|
|
||||||
join(detail_types).separator(", ").surround_with("(", ")").to_string();
|
|
||||||
|
|
||||||
CompletionItem::new(
|
|
||||||
CompletionKind::Reference,
|
|
||||||
ctx.source_range(),
|
|
||||||
name.to_string(),
|
|
||||||
)
|
|
||||||
.kind(CompletionItemKind::EnumVariant)
|
|
||||||
.set_documentation(variant.docs(ctx.db))
|
|
||||||
.set_detail(Some(detail))
|
|
||||||
.add_to(acc)
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Struct(s) => {
|
hir::ModuleDef::Struct(s) => {
|
||||||
let ty = s.ty(ctx.db);
|
let ty = s.ty(ctx.db);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//! This modules takes care of rendering various defenitions as completion items.
|
//! This modules takes care of rendering various defenitions as completion items.
|
||||||
|
use join_to_string::join;
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
use hir::Docs;
|
use hir::Docs;
|
||||||
|
|
||||||
|
@ -60,6 +61,21 @@ impl Completions {
|
||||||
}
|
}
|
||||||
self.add(builder)
|
self.add(builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) {
|
||||||
|
let name = match variant.name(ctx.db) {
|
||||||
|
Some(it) => it,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db));
|
||||||
|
let detail = join(detail_types).separator(", ").surround_with("(", ")").to_string();
|
||||||
|
|
||||||
|
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string())
|
||||||
|
.kind(CompletionItemKind::EnumVariant)
|
||||||
|
.set_documentation(variant.docs(ctx.db))
|
||||||
|
.detail(detail)
|
||||||
|
.add_to(self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> {
|
fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue