mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
move the rest of presentation to presentation
This commit is contained in:
parent
b7a7872910
commit
98510ec5d3
2 changed files with 20 additions and 50 deletions
|
@ -1,14 +1,8 @@
|
|||
use std::fmt;
|
||||
|
||||
use hir::{Docs, Documentation};
|
||||
use hir::Documentation;
|
||||
use ra_syntax::TextRange;
|
||||
use ra_text_edit::{ TextEditBuilder, TextEdit};
|
||||
|
||||
use crate::completion::{
|
||||
completion_context::CompletionContext,
|
||||
const_label,
|
||||
type_label
|
||||
};
|
||||
use ra_text_edit::{TextEditBuilder, TextEdit};
|
||||
|
||||
/// `CompletionItem` describes a single completion variant in the editor pop-up.
|
||||
/// It is basically a POD with various properties. To construct a
|
||||
|
@ -253,27 +247,6 @@ impl Builder {
|
|||
self.documentation = docs.map(Into::into);
|
||||
self
|
||||
}
|
||||
pub(super) fn from_const(mut self, ctx: &CompletionContext, ct: hir::Const) -> Builder {
|
||||
if let Some(docs) = ct.docs(ctx.db) {
|
||||
self.documentation = Some(docs);
|
||||
}
|
||||
|
||||
self.detail = Some(const_item_label(ctx, ct));
|
||||
self.kind = Some(CompletionItemKind::Const);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub(super) fn from_type(mut self, ctx: &CompletionContext, ty: hir::Type) -> Builder {
|
||||
if let Some(docs) = ty.docs(ctx.db) {
|
||||
self.documentation = Some(docs);
|
||||
}
|
||||
|
||||
self.detail = Some(type_item_label(ctx, ty));
|
||||
self.kind = Some(CompletionItemKind::TypeAlias);
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Into<CompletionItem> for Builder {
|
||||
|
@ -307,16 +280,6 @@ impl Into<Vec<CompletionItem>> for Completions {
|
|||
}
|
||||
}
|
||||
|
||||
fn const_item_label(ctx: &CompletionContext, ct: hir::Const) -> String {
|
||||
let node = ct.source(ctx.db).1;
|
||||
const_label(&node)
|
||||
}
|
||||
|
||||
fn type_item_label(ctx: &CompletionContext, ty: hir::Type) -> String {
|
||||
let node = ty.source(ctx.db).1;
|
||||
type_label(&node)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> {
|
||||
use crate::mock_analysis::{single_file_with_position, analysis_and_position};
|
||||
|
|
|
@ -6,7 +6,7 @@ use ra_syntax::ast::NameOwner;
|
|||
|
||||
use crate::completion::{
|
||||
Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem,
|
||||
function_label,
|
||||
function_label, const_label, type_label,
|
||||
};
|
||||
|
||||
impl Completions {
|
||||
|
@ -91,6 +91,8 @@ impl Completions {
|
|||
) {
|
||||
let sig = func.signature(ctx.db);
|
||||
let name = name.unwrap_or_else(|| sig.name().to_string());
|
||||
let (_, ast_node) = func.source(ctx.db);
|
||||
let detail = function_label(&ast_node);
|
||||
|
||||
let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name)
|
||||
.kind(if sig.has_self_param() {
|
||||
|
@ -99,7 +101,7 @@ impl Completions {
|
|||
CompletionItemKind::Function
|
||||
})
|
||||
.set_documentation(func.docs(ctx.db))
|
||||
.set_detail(function_item_label(ctx, func));
|
||||
.set_detail(detail);
|
||||
// If not an import, add parenthesis automatically.
|
||||
if ctx.use_item_syntax.is_none() && !ctx.is_call {
|
||||
tested_by!(inserts_parens_for_function_calls);
|
||||
|
@ -115,13 +117,18 @@ impl Completions {
|
|||
}
|
||||
|
||||
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() {
|
||||
let (_file_id, ast_node) = constant.source(ctx.db);
|
||||
let name = match ast_node.name() {
|
||||
Some(name) => name,
|
||||
_ => return,
|
||||
};
|
||||
let (_, ast_node) = constant.source(ctx.db);
|
||||
let detail = const_label(&ast_node);
|
||||
|
||||
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
|
||||
.from_const(ctx, constant)
|
||||
.kind(CompletionItemKind::Const)
|
||||
.set_documentation(constant.docs(ctx.db))
|
||||
.detail(detail)
|
||||
.add_to(self);
|
||||
}
|
||||
|
||||
|
@ -131,8 +138,13 @@ impl Completions {
|
|||
Some(name) => name,
|
||||
_ => return,
|
||||
};
|
||||
let (_, ast_node) = type_alias.source(ctx.db);
|
||||
let detail = type_label(&ast_node);
|
||||
|
||||
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string())
|
||||
.from_type(ctx, type_alias)
|
||||
.kind(CompletionItemKind::TypeAlias)
|
||||
.set_documentation(type_alias.docs(ctx.db))
|
||||
.detail(detail)
|
||||
.add_to(self);
|
||||
}
|
||||
|
||||
|
@ -152,11 +164,6 @@ impl Completions {
|
|||
}
|
||||
}
|
||||
|
||||
fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> {
|
||||
let node = function.source(ctx.db).1;
|
||||
function_label(&node)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use test_utils::covers;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue