mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
move res completion to presentation
This commit is contained in:
parent
2369af8c82
commit
a650a93bf5
3 changed files with 42 additions and 41 deletions
|
@ -1,8 +1,8 @@
|
||||||
use hir::Resolution;
|
use hir::Resolution;
|
||||||
use ra_syntax::{AstNode, ast::NameOwner};
|
use ra_syntax::AstNode;
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
|
|
||||||
use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext};
|
use crate::completion::{Completions, 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 {
|
||||||
|
@ -27,14 +27,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def));
|
||||||
CompletionItem::new(
|
|
||||||
CompletionKind::Reference,
|
|
||||||
ctx.source_range(),
|
|
||||||
name.to_string(),
|
|
||||||
)
|
|
||||||
.from_resolution(ctx, &res.def.map(hir::Resolution::Def))
|
|
||||||
.add_to(acc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Enum(e) => {
|
hir::ModuleDef::Enum(e) => {
|
||||||
|
@ -52,30 +45,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
acc.add_function(ctx, func);
|
acc.add_function(ctx, func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ImplItem::Const(ct) => {
|
hir::ImplItem::Const(ct) => acc.add_const(ctx, ct),
|
||||||
let source = ct.source(ctx.db);
|
hir::ImplItem::Type(ty) => acc.add_type(ctx, ty),
|
||||||
if let Some(name) = source.1.name() {
|
|
||||||
CompletionItem::new(
|
|
||||||
CompletionKind::Reference,
|
|
||||||
ctx.source_range(),
|
|
||||||
name.text().to_string(),
|
|
||||||
)
|
|
||||||
.from_const(ctx, ct)
|
|
||||||
.add_to(acc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hir::ImplItem::Type(ty) => {
|
|
||||||
let source = ty.source(ctx.db);
|
|
||||||
if let Some(name) = source.1.name() {
|
|
||||||
CompletionItem::new(
|
|
||||||
CompletionKind::Reference,
|
|
||||||
ctx.source_range(),
|
|
||||||
name.text().to_string(),
|
|
||||||
)
|
|
||||||
.from_type(ctx, ty)
|
|
||||||
.add_to(acc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None::<()>
|
None::<()>
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext};
|
use crate::completion::{Completions, CompletionContext};
|
||||||
|
|
||||||
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
if !ctx.is_trivial_path {
|
if !ctx.is_trivial_path {
|
||||||
|
@ -6,11 +6,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
}
|
}
|
||||||
let names = ctx.resolver.all_names(ctx.db);
|
let names = ctx.resolver.all_names(ctx.db);
|
||||||
|
|
||||||
names.into_iter().for_each(|(name, res)| {
|
names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res));
|
||||||
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string())
|
|
||||||
.from_resolution(ctx, &res)
|
|
||||||
.add_to(acc)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
//! 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 join_to_string::join;
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
use hir::Docs;
|
use hir::{Docs, PerNs, Resolution};
|
||||||
|
use ra_syntax::ast::NameOwner;
|
||||||
|
|
||||||
use crate::completion::{
|
use crate::completion::{
|
||||||
Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem,
|
Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem,
|
||||||
|
@ -33,6 +34,17 @@ impl Completions {
|
||||||
.add_to(self);
|
.add_to(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn add_resolution(
|
||||||
|
&mut self,
|
||||||
|
ctx: &CompletionContext,
|
||||||
|
local_name: String,
|
||||||
|
res: &PerNs<Resolution>,
|
||||||
|
) {
|
||||||
|
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), local_name)
|
||||||
|
.from_resolution(ctx, res)
|
||||||
|
.add_to(self);
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) {
|
pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) {
|
||||||
let sig = func.signature(ctx.db);
|
let sig = func.signature(ctx.db);
|
||||||
|
|
||||||
|
@ -62,6 +74,28 @@ impl Completions {
|
||||||
self.add(builder)
|
self.add(builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
|
||||||
|
let (_file_id, cosnt_def) = constant.source(ctx.db);
|
||||||
|
let name = match cosnt_def.name() {
|
||||||
|
Some(name) => name,
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
|
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
|
||||||
|
.from_const(ctx, constant)
|
||||||
|
.add_to(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn add_type(&mut self, ctx: &CompletionContext, type_alias: hir::Type) {
|
||||||
|
let (_file_id, type_def) = type_alias.source(ctx.db);
|
||||||
|
let name = match type_def.name() {
|
||||||
|
Some(name) => name,
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
|
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
|
||||||
|
.from_type(ctx, type_alias)
|
||||||
|
.add_to(self);
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) {
|
pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) {
|
||||||
let name = match variant.name(ctx.db) {
|
let name = match variant.name(ctx.db) {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue