Move completion label functions to display
This commit is contained in:
parent
dfaebd76ab
commit
946b5789d1
@ -13,12 +13,10 @@ mod complete_scope;
|
||||
mod complete_postfix;
|
||||
|
||||
use ra_db::SourceDatabase;
|
||||
use ra_syntax::{ast::{self, AstNode}, SyntaxKind::{ATTR, COMMENT}};
|
||||
|
||||
use crate::{
|
||||
db,
|
||||
FilePosition,
|
||||
FunctionSignature,
|
||||
completion::{
|
||||
completion_item::{Completions, CompletionKind},
|
||||
completion_context::CompletionContext,
|
||||
@ -71,29 +69,3 @@ pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Opti
|
||||
complete_postfix::complete_postfix(&mut acc, &ctx);
|
||||
Some(acc)
|
||||
}
|
||||
|
||||
pub fn function_label(node: &ast::FnDef) -> Option<String> {
|
||||
Some(FunctionSignature::from(node).to_string())
|
||||
}
|
||||
|
||||
pub fn const_label(node: &ast::ConstDef) -> String {
|
||||
let label: String = node
|
||||
.syntax()
|
||||
.children_with_tokens()
|
||||
.filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR))
|
||||
.map(|node| node.to_string())
|
||||
.collect();
|
||||
|
||||
label.trim().to_owned()
|
||||
}
|
||||
|
||||
pub fn type_label(node: &ast::TypeAliasDef) -> String {
|
||||
let label: String = node
|
||||
.syntax()
|
||||
.children_with_tokens()
|
||||
.filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR))
|
||||
.map(|node| node.to_string())
|
||||
.collect();
|
||||
|
||||
label.trim().to_owned()
|
||||
}
|
||||
|
@ -6,6 +6,9 @@ use ra_syntax::ast::NameOwner;
|
||||
|
||||
use crate::completion::{
|
||||
Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem,
|
||||
};
|
||||
|
||||
use crate::display::{
|
||||
function_label, const_label, type_label,
|
||||
};
|
||||
|
||||
@ -101,7 +104,7 @@ impl Completions {
|
||||
CompletionItemKind::Function
|
||||
})
|
||||
.set_documentation(func.docs(ctx.db))
|
||||
.set_detail(detail);
|
||||
.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);
|
||||
|
@ -3,10 +3,36 @@
|
||||
use super::*;
|
||||
use std::fmt::{self, Display};
|
||||
use join_to_string::join;
|
||||
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner};
|
||||
use ra_syntax::{ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner}, SyntaxKind::{ATTR, COMMENT}};
|
||||
use std::convert::From;
|
||||
use hir::Docs;
|
||||
|
||||
pub(crate) fn function_label(node: &ast::FnDef) -> String {
|
||||
FunctionSignature::from(node).to_string()
|
||||
}
|
||||
|
||||
pub(crate) fn const_label(node: &ast::ConstDef) -> String {
|
||||
let label: String = node
|
||||
.syntax()
|
||||
.children_with_tokens()
|
||||
.filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR))
|
||||
.map(|node| node.to_string())
|
||||
.collect();
|
||||
|
||||
label.trim().to_owned()
|
||||
}
|
||||
|
||||
pub(crate) fn type_label(node: &ast::TypeAliasDef) -> String {
|
||||
let label: String = node
|
||||
.syntax()
|
||||
.children_with_tokens()
|
||||
.filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR))
|
||||
.map(|node| node.to_string())
|
||||
.collect();
|
||||
|
||||
label.trim().to_owned()
|
||||
}
|
||||
|
||||
/// Contains information about a function signature
|
||||
#[derive(Debug)]
|
||||
pub struct FunctionSignature {
|
||||
|
@ -235,7 +235,7 @@ impl NavigationTarget {
|
||||
}
|
||||
|
||||
visitor()
|
||||
.visit(crate::completion::function_label)
|
||||
.visit(|node: &ast::FnDef| Some(crate::display::function_label(node)))
|
||||
.visit(|node: &ast::StructDef| visit_node(node, "struct "))
|
||||
.visit(|node: &ast::EnumDef| visit_node(node, "enum "))
|
||||
.visit(|node: &ast::TraitDef| visit_node(node, "trait "))
|
||||
|
Loading…
x
Reference in New Issue
Block a user