Simplify
This commit is contained in:
parent
b66f181bc0
commit
e09d410dcd
@ -9,7 +9,6 @@ use hir::{
|
||||
};
|
||||
use ide_db::{
|
||||
base_db::{FileId, FileRange},
|
||||
symbol_index::FileSymbolKind,
|
||||
SymbolKind,
|
||||
};
|
||||
use ide_db::{defs::Definition, RootDatabase};
|
||||
@ -174,18 +173,7 @@ impl TryToNav for FileSymbol {
|
||||
Some(NavigationTarget {
|
||||
file_id: full_range.file_id,
|
||||
name: self.name.clone(),
|
||||
kind: Some(match self.kind {
|
||||
FileSymbolKind::Function => SymbolKind::Function,
|
||||
FileSymbolKind::Struct => SymbolKind::Struct,
|
||||
FileSymbolKind::Enum => SymbolKind::Enum,
|
||||
FileSymbolKind::Trait => SymbolKind::Trait,
|
||||
FileSymbolKind::Module => SymbolKind::Module,
|
||||
FileSymbolKind::TypeAlias => SymbolKind::TypeAlias,
|
||||
FileSymbolKind::Const => SymbolKind::Const,
|
||||
FileSymbolKind::Static => SymbolKind::Static,
|
||||
FileSymbolKind::Macro => SymbolKind::Macro,
|
||||
FileSymbolKind::Union => SymbolKind::Union,
|
||||
}),
|
||||
kind: Some(self.kind.into()),
|
||||
full_range: full_range.range,
|
||||
focus_range: Some(name_range.range),
|
||||
container_name: self.container_name.clone(),
|
||||
@ -367,13 +355,7 @@ impl TryToNav for hir::MacroDef {
|
||||
let mut res = NavigationTarget::from_named(
|
||||
db,
|
||||
src.as_ref().with_value(name_owner),
|
||||
match self.kind() {
|
||||
hir::MacroKind::Declarative
|
||||
| hir::MacroKind::BuiltIn
|
||||
| hir::MacroKind::ProcMacro => SymbolKind::Macro,
|
||||
hir::MacroKind::Derive => SymbolKind::Derive,
|
||||
hir::MacroKind::Attr => SymbolKind::Attribute,
|
||||
},
|
||||
self.kind().into(),
|
||||
);
|
||||
res.docs = self.docs(db);
|
||||
Some(res)
|
||||
|
@ -375,13 +375,7 @@ fn highlight_def(
|
||||
) -> Highlight {
|
||||
let db = sema.db;
|
||||
let mut h = match def {
|
||||
Definition::Macro(m) => Highlight::new(HlTag::Symbol(match m.kind() {
|
||||
hir::MacroKind::Declarative | hir::MacroKind::BuiltIn | hir::MacroKind::ProcMacro => {
|
||||
SymbolKind::Macro
|
||||
}
|
||||
hir::MacroKind::Derive => SymbolKind::Derive,
|
||||
hir::MacroKind::Attr => SymbolKind::Attribute,
|
||||
})),
|
||||
Definition::Macro(m) => Highlight::new(HlTag::Symbol(m.kind().into())),
|
||||
Definition::Field(_) => Highlight::new(HlTag::Symbol(SymbolKind::Field)),
|
||||
Definition::Module(module) => {
|
||||
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Module));
|
||||
|
@ -52,14 +52,8 @@ impl<'a> MacroRender<'a> {
|
||||
} else {
|
||||
Some(self.ctx.source_range())
|
||||
}?;
|
||||
let kind = match self.macro_.kind() {
|
||||
hir::MacroKind::Derive => SymbolKind::Derive,
|
||||
hir::MacroKind::Attr => SymbolKind::Attribute,
|
||||
hir::MacroKind::BuiltIn | hir::MacroKind::Declarative | hir::MacroKind::ProcMacro => {
|
||||
SymbolKind::Macro
|
||||
}
|
||||
};
|
||||
let mut item = CompletionItem::new(kind, source_range, self.label());
|
||||
let mut item =
|
||||
CompletionItem::new(SymbolKind::from(self.macro_.kind()), source_range, self.label());
|
||||
item.set_deprecated(self.ctx.is_deprecated(self.macro_)).set_detail(self.detail());
|
||||
|
||||
if let Some(import_to_add) = import_to_add {
|
||||
|
@ -171,6 +171,18 @@ pub enum SymbolKind {
|
||||
Variant,
|
||||
}
|
||||
|
||||
impl From<hir::MacroKind> for SymbolKind {
|
||||
fn from(it: hir::MacroKind) -> Self {
|
||||
match it {
|
||||
hir::MacroKind::Declarative | hir::MacroKind::BuiltIn | hir::MacroKind::ProcMacro => {
|
||||
SymbolKind::Macro
|
||||
}
|
||||
hir::MacroKind::Derive => SymbolKind::Derive,
|
||||
hir::MacroKind::Attr => SymbolKind::Attribute,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
mod sourcegen_lints;
|
||||
|
@ -44,7 +44,7 @@ use rayon::prelude::*;
|
||||
use rustc_hash::FxHashSet;
|
||||
use syntax::{ast::HasName, AstNode, SmolStr, SyntaxNode, SyntaxNodePtr};
|
||||
|
||||
use crate::RootDatabase;
|
||||
use crate::{RootDatabase, SymbolKind};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Query {
|
||||
@ -430,6 +430,23 @@ impl FileSymbolKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FileSymbolKind> for SymbolKind {
|
||||
fn from(it: FileSymbolKind) -> Self {
|
||||
match it {
|
||||
FileSymbolKind::Const => SymbolKind::Const,
|
||||
FileSymbolKind::Enum => SymbolKind::Enum,
|
||||
FileSymbolKind::Function => SymbolKind::Function,
|
||||
FileSymbolKind::Macro => SymbolKind::Macro,
|
||||
FileSymbolKind::Module => SymbolKind::Module,
|
||||
FileSymbolKind::Static => SymbolKind::Static,
|
||||
FileSymbolKind::Struct => SymbolKind::Struct,
|
||||
FileSymbolKind::Trait => SymbolKind::Trait,
|
||||
FileSymbolKind::TypeAlias => SymbolKind::TypeAlias,
|
||||
FileSymbolKind::Union => SymbolKind::Union,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents an outstanding module that the symbol collector must collect symbols from.
|
||||
struct SymbolCollectorWork {
|
||||
module_id: ModuleId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user