Remove ShortLabel
This commit is contained in:
parent
b4ed3e1551
commit
4628d94e74
@ -2,8 +2,7 @@
|
||||
//! into types that may be used to render in a UI.
|
||||
|
||||
pub(crate) mod navigation_target;
|
||||
mod short_label;
|
||||
|
||||
pub(crate) use navigation_target::{ToNav, TryToNav};
|
||||
|
||||
pub(crate) use syntax::display::{function_declaration, macro_label};
|
||||
pub(crate) use syntax::display::macro_label;
|
||||
|
@ -5,9 +5,10 @@
|
||||
use either::Either;
|
||||
use hir::{
|
||||
AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirDisplay, InFile, ModuleSource,
|
||||
Semantics,
|
||||
};
|
||||
use ide_db::{
|
||||
base_db::{FileId, FileRange, SourceDatabase},
|
||||
base_db::{FileId, FileRange},
|
||||
symbol_index::FileSymbolKind,
|
||||
SymbolKind,
|
||||
};
|
||||
@ -19,8 +20,6 @@
|
||||
|
||||
use crate::FileSymbol;
|
||||
|
||||
use super::short_label::ShortLabel;
|
||||
|
||||
/// `NavigationTarget` represents and element in the editor's UI which you can
|
||||
/// click on to navigate to a particular piece of code.
|
||||
///
|
||||
@ -502,21 +501,22 @@ fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
||||
///
|
||||
/// e.g. `struct Name`, `enum Name`, `fn Name`
|
||||
pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> {
|
||||
let parse = db.parse(symbol.file_id);
|
||||
let node = symbol.ptr.to_node(parse.tree().syntax());
|
||||
let sema = Semantics::new(db);
|
||||
let parse = sema.parse(symbol.file_id);
|
||||
let node = symbol.ptr.to_node(parse.syntax());
|
||||
|
||||
match_ast! {
|
||||
match node {
|
||||
ast::Fn(it) => it.short_label(),
|
||||
ast::Struct(it) => it.short_label(),
|
||||
ast::Enum(it) => it.short_label(),
|
||||
ast::Trait(it) => it.short_label(),
|
||||
ast::Module(it) => it.short_label(),
|
||||
ast::TypeAlias(it) => it.short_label(),
|
||||
ast::Const(it) => it.short_label(),
|
||||
ast::Static(it) => it.short_label(),
|
||||
ast::RecordField(it) => it.short_label(),
|
||||
ast::Variant(it) => it.short_label(),
|
||||
ast::Fn(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Struct(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Enum(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Trait(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Module(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::TypeAlias(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Const(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Static(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::RecordField(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Variant(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -1,128 +0,0 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
use stdx::format_to;
|
||||
use syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
|
||||
|
||||
pub(crate) trait ShortLabel {
|
||||
fn short_label(&self) -> Option<String>;
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::Fn {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
Some(crate::display::function_declaration(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::Struct {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
short_label_from_node(self, "struct ")
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::Union {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
short_label_from_node(self, "union ")
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::Enum {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
short_label_from_node(self, "enum ")
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::Trait {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
if self.unsafe_token().is_some() {
|
||||
short_label_from_node(self, "unsafe trait ")
|
||||
} else {
|
||||
short_label_from_node(self, "trait ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::Module {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
short_label_from_node(self, "mod ")
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::SourceFile {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::BlockExpr {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::TypeAlias {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
let mut buf = short_label_from_node(self, "type ")?;
|
||||
if let Some(type_ref) = self.ty() {
|
||||
format_to!(buf, " = {}", type_ref.syntax());
|
||||
}
|
||||
Some(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::Const {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
short_label_from_ty(self, self.ty(), "const ")
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::Static {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
short_label_from_ty(self, self.ty(), "static ")
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::RecordField {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
short_label_from_ty(self, self.ty(), "")
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::Variant {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
Some(self.name()?.text().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortLabel for ast::ConstParam {
|
||||
fn short_label(&self) -> Option<String> {
|
||||
let mut buf = "const ".to_owned();
|
||||
buf.push_str(self.name()?.text());
|
||||
if let Some(type_ref) = self.ty() {
|
||||
format_to!(buf, ": {}", type_ref.syntax());
|
||||
}
|
||||
Some(buf)
|
||||
}
|
||||
}
|
||||
|
||||
fn short_label_from_ty<T>(node: &T, ty: Option<ast::Type>, prefix: &str) -> Option<String>
|
||||
where
|
||||
T: NameOwner + VisibilityOwner,
|
||||
{
|
||||
let mut buf = short_label_from_node(node, prefix)?;
|
||||
|
||||
if let Some(type_ref) = ty {
|
||||
format_to!(buf, ": {}", type_ref.syntax());
|
||||
}
|
||||
|
||||
Some(buf)
|
||||
}
|
||||
|
||||
fn short_label_from_node<T>(node: &T, label: &str) -> Option<String>
|
||||
where
|
||||
T: NameOwner + VisibilityOwner,
|
||||
{
|
||||
let mut buf = node.visibility().map(|v| format!("{} ", v.syntax())).unwrap_or_default();
|
||||
buf.push_str(label);
|
||||
buf.push_str(node.name()?.text());
|
||||
Some(buf)
|
||||
}
|
Loading…
Reference in New Issue
Block a user