2020-02-06 07:43:46 -06:00
|
|
|
//! This crate defines the core datastructure representing IDE state -- `RootDatabase`.
|
|
|
|
//!
|
|
|
|
//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search.
|
2020-02-06 05:07:06 -06:00
|
|
|
|
2023-12-05 04:35:09 -06:00
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
2022-07-20 07:59:42 -05:00
|
|
|
|
2020-10-02 08:45:09 -05:00
|
|
|
mod apply_change;
|
2021-10-12 01:59:39 -05:00
|
|
|
|
2022-03-06 12:01:30 -06:00
|
|
|
pub mod active_parameter;
|
2021-06-14 05:27:11 -05:00
|
|
|
pub mod assists;
|
2020-02-06 09:23:28 -06:00
|
|
|
pub mod defs;
|
2024-01-26 13:08:10 -06:00
|
|
|
pub mod documentation;
|
2022-03-06 12:01:30 -06:00
|
|
|
pub mod famous_defs;
|
|
|
|
pub mod helpers;
|
2021-03-02 17:26:53 -06:00
|
|
|
pub mod items_locator;
|
2022-03-06 12:01:30 -06:00
|
|
|
pub mod label;
|
|
|
|
pub mod path_transform;
|
|
|
|
pub mod rename;
|
|
|
|
pub mod rust_doc;
|
|
|
|
pub mod search;
|
2020-05-06 04:31:26 -05:00
|
|
|
pub mod source_change;
|
2022-03-06 12:01:30 -06:00
|
|
|
pub mod symbol_index;
|
2020-10-24 02:47:23 -05:00
|
|
|
pub mod traits;
|
2022-03-06 12:01:30 -06:00
|
|
|
pub mod ty_filter;
|
2023-03-01 06:55:21 -06:00
|
|
|
pub mod use_trivial_constructor;
|
2020-02-06 05:17:40 -06:00
|
|
|
|
2022-03-06 12:01:30 -06:00
|
|
|
pub mod imports {
|
|
|
|
pub mod import_assets;
|
|
|
|
pub mod insert_use;
|
|
|
|
pub mod merge_imports;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod generated {
|
|
|
|
pub mod lints;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod syntax_helpers {
|
|
|
|
pub mod format_string;
|
2022-09-10 08:36:50 -05:00
|
|
|
pub mod format_string_exprs;
|
2024-01-26 13:08:10 -06:00
|
|
|
pub mod insert_whitespace_into_node;
|
|
|
|
pub mod node_ext;
|
2022-03-10 10:07:11 -06:00
|
|
|
|
|
|
|
pub use parser::LexedStr;
|
2022-03-06 12:01:30 -06:00
|
|
|
}
|
2021-06-14 10:46:27 -05:00
|
|
|
|
2023-12-18 07:53:11 -06:00
|
|
|
pub use hir::Change;
|
2023-12-18 05:09:54 -06:00
|
|
|
|
2023-05-02 09:12:22 -05:00
|
|
|
use std::{fmt, mem::ManuallyDrop};
|
2020-02-06 05:08:08 -06:00
|
|
|
|
2020-08-13 09:25:38 -05:00
|
|
|
use base_db::{
|
2020-07-07 03:14:48 -05:00
|
|
|
salsa::{self, Durability},
|
2021-05-17 12:07:10 -05:00
|
|
|
AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast,
|
2020-02-06 05:08:08 -06:00
|
|
|
};
|
2023-05-02 04:56:48 -05:00
|
|
|
use hir::db::{DefDatabase, ExpandDatabase, HirDatabase};
|
2023-05-02 09:12:22 -05:00
|
|
|
use triomphe::Arc;
|
2020-02-06 05:08:08 -06:00
|
|
|
|
2020-03-10 12:56:15 -05:00
|
|
|
use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase};
|
2022-04-25 11:51:59 -05:00
|
|
|
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
|
2020-02-06 05:08:08 -06:00
|
|
|
|
2023-05-03 21:18:41 -05:00
|
|
|
pub use ::line_index;
|
|
|
|
|
2020-10-24 03:39:57 -05:00
|
|
|
/// `base_db` is normally also needed in places where `ide_db` is used, so this re-export is for convenience.
|
|
|
|
pub use base_db;
|
|
|
|
|
2021-11-16 05:15:47 -06:00
|
|
|
pub type FxIndexSet<T> = indexmap::IndexSet<T, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
|
|
|
|
pub type FxIndexMap<K, V> =
|
|
|
|
indexmap::IndexMap<K, V, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
|
|
|
|
|
2020-02-06 05:08:08 -06:00
|
|
|
#[salsa::database(
|
2020-08-13 09:25:38 -05:00
|
|
|
base_db::SourceDatabaseExtStorage,
|
2022-03-06 12:01:30 -06:00
|
|
|
base_db::SourceDatabaseStorage,
|
2023-03-13 10:33:52 -05:00
|
|
|
hir::db::ExpandDatabaseStorage,
|
2020-02-06 05:08:08 -06:00
|
|
|
hir::db::DefDatabaseStorage,
|
2022-03-06 12:01:30 -06:00
|
|
|
hir::db::HirDatabaseStorage,
|
|
|
|
hir::db::InternDatabaseStorage,
|
|
|
|
LineIndexDatabaseStorage,
|
|
|
|
symbol_index::SymbolsDatabaseStorage
|
2020-02-06 05:08:08 -06:00
|
|
|
)]
|
2020-02-06 05:43:56 -06:00
|
|
|
pub struct RootDatabase {
|
2021-08-28 16:05:40 -05:00
|
|
|
// We use `ManuallyDrop` here because every codegen unit that contains a
|
|
|
|
// `&RootDatabase -> &dyn OtherDatabase` cast will instantiate its drop glue in the vtable,
|
|
|
|
// which duplicates `Weak::drop` and `Arc::drop` tens of thousands of times, which makes
|
|
|
|
// compile times of all `ide_*` and downstream crates suffer greatly.
|
|
|
|
storage: ManuallyDrop<salsa::Storage<RootDatabase>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for RootDatabase {
|
|
|
|
fn drop(&mut self) {
|
2022-03-06 12:01:30 -06:00
|
|
|
unsafe { ManuallyDrop::drop(&mut self.storage) };
|
2021-08-28 16:05:40 -05:00
|
|
|
}
|
2020-02-06 05:08:08 -06:00
|
|
|
}
|
|
|
|
|
2020-07-07 03:14:48 -05:00
|
|
|
impl fmt::Debug for RootDatabase {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.debug_struct("RootDatabase").finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 10:33:52 -05:00
|
|
|
impl Upcast<dyn ExpandDatabase> for RootDatabase {
|
2023-08-16 04:18:11 -05:00
|
|
|
#[inline]
|
2023-03-13 10:33:52 -05:00
|
|
|
fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
|
2024-01-18 06:59:49 -06:00
|
|
|
self
|
2020-03-13 10:05:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Upcast<dyn DefDatabase> for RootDatabase {
|
2023-08-16 04:18:11 -05:00
|
|
|
#[inline]
|
2020-03-13 10:05:46 -05:00
|
|
|
fn upcast(&self) -> &(dyn DefDatabase + 'static) {
|
2024-01-18 06:59:49 -06:00
|
|
|
self
|
2020-03-13 10:05:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 04:43:36 -05:00
|
|
|
impl Upcast<dyn HirDatabase> for RootDatabase {
|
2023-08-16 04:18:11 -05:00
|
|
|
#[inline]
|
2020-07-01 04:43:36 -05:00
|
|
|
fn upcast(&self) -> &(dyn HirDatabase + 'static) {
|
2024-01-18 06:59:49 -06:00
|
|
|
self
|
2020-07-01 04:43:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-06 05:08:08 -06:00
|
|
|
impl FileLoader for RootDatabase {
|
2023-04-22 02:48:37 -05:00
|
|
|
fn file_text(&self, file_id: FileId) -> Arc<str> {
|
2020-02-06 05:08:08 -06:00
|
|
|
FileLoaderDelegate(self).file_text(file_id)
|
|
|
|
}
|
2022-07-20 08:02:08 -05:00
|
|
|
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
|
2020-12-09 10:01:15 -06:00
|
|
|
FileLoaderDelegate(self).resolve_path(path)
|
2020-02-06 05:08:08 -06:00
|
|
|
}
|
2024-01-10 07:51:51 -06:00
|
|
|
fn relevant_crates(&self, file_id: FileId) -> Arc<[CrateId]> {
|
2020-02-06 05:08:08 -06:00
|
|
|
FileLoaderDelegate(self).relevant_crates(file_id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-17 12:07:10 -05:00
|
|
|
impl salsa::Database for RootDatabase {}
|
2020-02-06 05:08:08 -06:00
|
|
|
|
|
|
|
impl Default for RootDatabase {
|
|
|
|
fn default() -> RootDatabase {
|
2020-03-10 12:56:15 -05:00
|
|
|
RootDatabase::new(None)
|
2020-02-06 05:08:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RootDatabase {
|
2020-03-10 12:56:15 -05:00
|
|
|
pub fn new(lru_capacity: Option<usize>) -> RootDatabase {
|
2021-08-28 16:05:40 -05:00
|
|
|
let mut db = RootDatabase { storage: ManuallyDrop::new(salsa::Storage::default()) };
|
2020-02-06 05:08:08 -06:00
|
|
|
db.set_crate_graph_with_durability(Default::default(), Durability::HIGH);
|
2023-03-25 12:20:42 -05:00
|
|
|
db.set_proc_macros_with_durability(Default::default(), Durability::HIGH);
|
2020-02-06 05:08:08 -06:00
|
|
|
db.set_local_roots_with_durability(Default::default(), Durability::HIGH);
|
|
|
|
db.set_library_roots_with_durability(Default::default(), Durability::HIGH);
|
2023-03-29 12:13:40 -05:00
|
|
|
db.set_expand_proc_attr_macros_with_durability(false, Durability::HIGH);
|
2024-01-09 13:43:17 -06:00
|
|
|
db.update_base_query_lru_capacities(lru_capacity);
|
2023-11-19 11:42:25 -06:00
|
|
|
db.setup_syntax_context_root();
|
2020-02-06 05:08:08 -06:00
|
|
|
db
|
|
|
|
}
|
2020-03-20 15:09:23 -05:00
|
|
|
|
2023-03-29 12:13:40 -05:00
|
|
|
pub fn enable_proc_attr_macros(&mut self) {
|
|
|
|
self.set_expand_proc_attr_macros_with_durability(true, Durability::HIGH);
|
|
|
|
}
|
|
|
|
|
2024-01-09 13:43:17 -06:00
|
|
|
pub fn update_base_query_lru_capacities(&mut self, lru_capacity: Option<usize>) {
|
2023-04-22 03:35:40 -05:00
|
|
|
let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_PARSE_LRU_CAP);
|
2020-08-13 09:25:38 -05:00
|
|
|
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
|
2023-04-22 03:35:40 -05:00
|
|
|
// macro expansions are usually rather small, so we can afford to keep more of them alive
|
|
|
|
hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity);
|
2024-01-09 13:43:17 -06:00
|
|
|
hir::db::BorrowckQuery.in_db_mut(self).set_lru_capacity(base_db::DEFAULT_BORROWCK_LRU_CAP);
|
2020-03-20 15:09:23 -05:00
|
|
|
}
|
2023-03-25 17:03:22 -05:00
|
|
|
|
|
|
|
pub fn update_lru_capacities(&mut self, lru_capacities: &FxHashMap<Box<str>, usize>) {
|
|
|
|
use hir::db as hir_db;
|
|
|
|
|
|
|
|
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(
|
2023-04-22 03:35:40 -05:00
|
|
|
lru_capacities
|
|
|
|
.get(stringify!(ParseQuery))
|
|
|
|
.copied()
|
|
|
|
.unwrap_or(base_db::DEFAULT_PARSE_LRU_CAP),
|
2023-03-25 17:03:22 -05:00
|
|
|
);
|
|
|
|
hir_db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(
|
|
|
|
lru_capacities
|
|
|
|
.get(stringify!(ParseMacroExpansionQuery))
|
|
|
|
.copied()
|
2023-04-22 03:35:40 -05:00
|
|
|
.unwrap_or(4 * base_db::DEFAULT_PARSE_LRU_CAP),
|
2023-03-25 17:03:22 -05:00
|
|
|
);
|
2024-01-09 13:43:17 -06:00
|
|
|
hir_db::BorrowckQuery.in_db_mut(self).set_lru_capacity(
|
|
|
|
lru_capacities
|
|
|
|
.get(stringify!(BorrowckQuery))
|
|
|
|
.copied()
|
|
|
|
.unwrap_or(base_db::DEFAULT_BORROWCK_LRU_CAP),
|
|
|
|
);
|
2023-03-25 17:03:22 -05:00
|
|
|
|
|
|
|
macro_rules! update_lru_capacity_per_query {
|
|
|
|
($( $module:ident :: $query:ident )*) => {$(
|
|
|
|
if let Some(&cap) = lru_capacities.get(stringify!($query)) {
|
|
|
|
$module::$query.in_db_mut(self).set_lru_capacity(cap);
|
|
|
|
}
|
|
|
|
)*}
|
|
|
|
}
|
|
|
|
update_lru_capacity_per_query![
|
|
|
|
// SourceDatabase
|
|
|
|
// base_db::ParseQuery
|
|
|
|
// base_db::CrateGraphQuery
|
|
|
|
// base_db::ProcMacrosQuery
|
|
|
|
|
|
|
|
// SourceDatabaseExt
|
|
|
|
// base_db::FileTextQuery
|
|
|
|
// base_db::FileSourceRootQuery
|
|
|
|
// base_db::SourceRootQuery
|
|
|
|
base_db::SourceRootCratesQuery
|
|
|
|
|
|
|
|
// ExpandDatabase
|
|
|
|
hir_db::AstIdMapQuery
|
|
|
|
// hir_db::ParseMacroExpansionQuery
|
|
|
|
// hir_db::InternMacroCallQuery
|
2023-09-29 05:37:57 -05:00
|
|
|
hir_db::MacroArgQuery
|
2023-07-10 09:23:29 -05:00
|
|
|
hir_db::DeclMacroExpanderQuery
|
2023-03-25 17:03:22 -05:00
|
|
|
// hir_db::MacroExpandQuery
|
|
|
|
hir_db::ExpandProcMacroQuery
|
2023-04-16 16:12:25 -05:00
|
|
|
hir_db::ParseMacroExpansionErrorQuery
|
2023-03-25 17:03:22 -05:00
|
|
|
|
|
|
|
// DefDatabase
|
|
|
|
hir_db::FileItemTreeQuery
|
|
|
|
hir_db::CrateDefMapQueryQuery
|
|
|
|
hir_db::BlockDefMapQuery
|
|
|
|
hir_db::StructDataWithDiagnosticsQuery
|
|
|
|
hir_db::UnionDataWithDiagnosticsQuery
|
|
|
|
hir_db::EnumDataQuery
|
2024-01-15 03:24:14 -06:00
|
|
|
hir_db::EnumVariantDataWithDiagnosticsQuery
|
2023-03-25 17:03:22 -05:00
|
|
|
hir_db::ImplDataWithDiagnosticsQuery
|
|
|
|
hir_db::TraitDataWithDiagnosticsQuery
|
|
|
|
hir_db::TraitAliasDataQuery
|
|
|
|
hir_db::TypeAliasDataQuery
|
|
|
|
hir_db::FunctionDataQuery
|
|
|
|
hir_db::ConstDataQuery
|
|
|
|
hir_db::StaticDataQuery
|
|
|
|
hir_db::Macro2DataQuery
|
|
|
|
hir_db::MacroRulesDataQuery
|
|
|
|
hir_db::ProcMacroDataQuery
|
|
|
|
hir_db::BodyWithSourceMapQuery
|
|
|
|
hir_db::BodyQuery
|
|
|
|
hir_db::ExprScopesQuery
|
|
|
|
hir_db::GenericParamsQuery
|
|
|
|
hir_db::FieldsAttrsQuery
|
|
|
|
hir_db::FieldsAttrsSourceMapQuery
|
|
|
|
hir_db::AttrsQuery
|
|
|
|
hir_db::CrateLangItemsQuery
|
|
|
|
hir_db::LangItemQuery
|
|
|
|
hir_db::ImportMapQuery
|
|
|
|
hir_db::FieldVisibilitiesQuery
|
|
|
|
hir_db::FunctionVisibilityQuery
|
|
|
|
hir_db::ConstVisibilityQuery
|
|
|
|
hir_db::CrateSupportsNoStdQuery
|
|
|
|
|
|
|
|
// HirDatabase
|
|
|
|
hir_db::InferQueryQuery
|
|
|
|
hir_db::MirBodyQuery
|
|
|
|
hir_db::BorrowckQuery
|
|
|
|
hir_db::TyQuery
|
|
|
|
hir_db::ValueTyQuery
|
|
|
|
hir_db::ImplSelfTyQuery
|
|
|
|
hir_db::ConstParamTyQuery
|
|
|
|
hir_db::ConstEvalQuery
|
|
|
|
hir_db::ConstEvalDiscriminantQuery
|
|
|
|
hir_db::ImplTraitQuery
|
|
|
|
hir_db::FieldTypesQuery
|
|
|
|
hir_db::LayoutOfAdtQuery
|
|
|
|
hir_db::TargetDataLayoutQuery
|
|
|
|
hir_db::CallableItemSignatureQuery
|
|
|
|
hir_db::ReturnTypeImplTraitsQuery
|
|
|
|
hir_db::GenericPredicatesForParamQuery
|
|
|
|
hir_db::GenericPredicatesQuery
|
|
|
|
hir_db::TraitEnvironmentQuery
|
|
|
|
hir_db::GenericDefaultsQuery
|
|
|
|
hir_db::InherentImplsInCrateQuery
|
|
|
|
hir_db::InherentImplsInBlockQuery
|
|
|
|
hir_db::IncoherentInherentImplCratesQuery
|
|
|
|
hir_db::TraitImplsInCrateQuery
|
|
|
|
hir_db::TraitImplsInBlockQuery
|
|
|
|
hir_db::TraitImplsInDepsQuery
|
|
|
|
// hir_db::InternCallableDefQuery
|
|
|
|
// hir_db::InternLifetimeParamIdQuery
|
|
|
|
// hir_db::InternImplTraitIdQuery
|
|
|
|
// hir_db::InternTypeOrConstParamIdQuery
|
|
|
|
// hir_db::InternClosureQuery
|
2023-12-25 16:12:45 -06:00
|
|
|
// hir_db::InternCoroutineQuery
|
2023-03-25 17:03:22 -05:00
|
|
|
hir_db::AssociatedTyDataQuery
|
|
|
|
hir_db::TraitDatumQuery
|
2022-08-23 07:56:56 -05:00
|
|
|
hir_db::AdtDatumQuery
|
2023-03-25 17:03:22 -05:00
|
|
|
hir_db::ImplDatumQuery
|
|
|
|
hir_db::FnDefDatumQuery
|
|
|
|
hir_db::FnDefVarianceQuery
|
|
|
|
hir_db::AdtVarianceQuery
|
|
|
|
hir_db::AssociatedTyValueQuery
|
|
|
|
hir_db::TraitSolveQueryQuery
|
|
|
|
hir_db::ProgramClausesForChalkEnvQuery
|
|
|
|
|
|
|
|
// SymbolsDatabase
|
|
|
|
symbol_index::ModuleSymbolsQuery
|
|
|
|
symbol_index::LibrarySymbolsQuery
|
|
|
|
// symbol_index::LocalRootsQuery
|
|
|
|
// symbol_index::LibraryRootsQuery
|
|
|
|
|
|
|
|
// LineIndexDatabase
|
|
|
|
crate::LineIndexQuery
|
|
|
|
|
|
|
|
// InternDatabase
|
|
|
|
// hir_db::InternFunctionQuery
|
|
|
|
// hir_db::InternStructQuery
|
|
|
|
// hir_db::InternUnionQuery
|
|
|
|
// hir_db::InternEnumQuery
|
|
|
|
// hir_db::InternConstQuery
|
|
|
|
// hir_db::InternStaticQuery
|
|
|
|
// hir_db::InternTraitQuery
|
|
|
|
// hir_db::InternTraitAliasQuery
|
|
|
|
// hir_db::InternTypeAliasQuery
|
|
|
|
// hir_db::InternImplQuery
|
|
|
|
// hir_db::InternExternBlockQuery
|
|
|
|
// hir_db::InternBlockQuery
|
|
|
|
// hir_db::InternMacro2Query
|
|
|
|
// hir_db::InternProcMacroQuery
|
|
|
|
// hir_db::InternMacroRulesQuery
|
|
|
|
];
|
|
|
|
}
|
2020-02-06 05:08:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl salsa::ParallelDatabase for RootDatabase {
|
|
|
|
fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
|
2021-08-28 16:05:40 -05:00
|
|
|
salsa::Snapshot::new(RootDatabase { storage: ManuallyDrop::new(self.storage.snapshot()) })
|
2020-02-06 05:08:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::query_group(LineIndexDatabaseStorage)]
|
2021-05-17 12:07:10 -05:00
|
|
|
pub trait LineIndexDatabase: base_db::SourceDatabase {
|
2020-02-06 05:08:08 -06:00
|
|
|
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
|
|
|
|
}
|
|
|
|
|
2020-07-07 03:14:48 -05:00
|
|
|
fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> {
|
2020-02-06 05:08:08 -06:00
|
|
|
let text = db.file_text(file_id);
|
2022-12-23 01:51:52 -06:00
|
|
|
Arc::new(LineIndex::new(&text))
|
2020-02-06 05:08:08 -06:00
|
|
|
}
|
2021-01-20 08:25:34 -06:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
|
|
pub enum SymbolKind {
|
2021-12-04 11:01:22 -06:00
|
|
|
Attribute,
|
2021-12-03 09:53:30 -06:00
|
|
|
BuiltinAttr,
|
2021-01-20 11:38:12 -06:00
|
|
|
Const,
|
2021-01-20 08:25:34 -06:00
|
|
|
ConstParam,
|
2021-12-04 11:18:09 -06:00
|
|
|
Derive,
|
2022-07-24 07:05:37 -05:00
|
|
|
DeriveHelper,
|
2021-01-20 11:38:12 -06:00
|
|
|
Enum,
|
|
|
|
Field,
|
|
|
|
Function,
|
|
|
|
Impl,
|
|
|
|
Label,
|
2021-01-20 08:25:34 -06:00
|
|
|
LifetimeParam,
|
|
|
|
Local,
|
2021-01-20 11:38:12 -06:00
|
|
|
Macro,
|
|
|
|
Module,
|
|
|
|
SelfParam,
|
2022-03-05 16:34:37 -06:00
|
|
|
SelfType,
|
2021-01-20 08:25:34 -06:00
|
|
|
Static,
|
|
|
|
Struct,
|
2021-12-03 10:15:19 -06:00
|
|
|
ToolModule,
|
2021-01-20 08:25:34 -06:00
|
|
|
Trait,
|
2023-03-03 09:24:07 -06:00
|
|
|
TraitAlias,
|
2021-01-20 11:38:12 -06:00
|
|
|
TypeAlias,
|
|
|
|
TypeParam,
|
|
|
|
Union,
|
|
|
|
ValueParam,
|
|
|
|
Variant,
|
2021-01-20 08:25:34 -06:00
|
|
|
}
|
2021-10-12 01:59:39 -05:00
|
|
|
|
2021-12-07 08:06:56 -06:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-02 04:56:48 -05:00
|
|
|
impl From<hir::ModuleDefId> for SymbolKind {
|
|
|
|
fn from(it: hir::ModuleDefId) -> Self {
|
2022-01-12 12:56:47 -06:00
|
|
|
match it {
|
2023-05-02 04:56:48 -05:00
|
|
|
hir::ModuleDefId::ConstId(..) => SymbolKind::Const,
|
|
|
|
hir::ModuleDefId::EnumVariantId(..) => SymbolKind::Variant,
|
|
|
|
hir::ModuleDefId::FunctionId(..) => SymbolKind::Function,
|
|
|
|
hir::ModuleDefId::MacroId(..) => SymbolKind::Macro,
|
|
|
|
hir::ModuleDefId::ModuleId(..) => SymbolKind::Module,
|
|
|
|
hir::ModuleDefId::StaticId(..) => SymbolKind::Static,
|
|
|
|
hir::ModuleDefId::AdtId(hir::AdtId::StructId(..)) => SymbolKind::Struct,
|
|
|
|
hir::ModuleDefId::AdtId(hir::AdtId::EnumId(..)) => SymbolKind::Enum,
|
|
|
|
hir::ModuleDefId::AdtId(hir::AdtId::UnionId(..)) => SymbolKind::Union,
|
|
|
|
hir::ModuleDefId::TraitId(..) => SymbolKind::Trait,
|
|
|
|
hir::ModuleDefId::TraitAliasId(..) => SymbolKind::TraitAlias,
|
|
|
|
hir::ModuleDefId::TypeAliasId(..) => SymbolKind::TypeAlias,
|
|
|
|
hir::ModuleDefId::BuiltinType(..) => SymbolKind::TypeAlias,
|
2022-01-12 12:56:47 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-06 12:01:30 -06:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
pub struct SnippetCap {
|
|
|
|
_private: (),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SnippetCap {
|
|
|
|
pub const fn new(allow_snippets: bool) -> Option<SnippetCap> {
|
|
|
|
if allow_snippets {
|
|
|
|
Some(SnippetCap { _private: () })
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 01:59:39 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2023-05-03 21:18:41 -05:00
|
|
|
mod line_index;
|
2024-01-26 13:08:10 -06:00
|
|
|
mod sourcegen_lints;
|
2021-10-12 01:59:39 -05:00
|
|
|
}
|