use crate::{
Ident,
SourceKey,
database::{
DynPartition,
PartitionKey,
},
protocol::lsp::SymbolKind,
};
pub struct DocumentSymbols;
impl PartitionKey for DocumentSymbols {
const KEY: Ident = Ident::new("laburnum::document_symbols");
}
impl DynPartition for DocumentSymbols {
type DynSortKey = DocumentSymbolSortKey;
type RecordConstraint = dyn DocumentSymbolRecord;
}
impl<R: DocumentSymbolRecord + crate::record::Record>
crate::database::DynPartitionRecord<DocumentSymbols> for R
{
}
#[derive(Debug, Clone)]
pub enum DocumentSymbolSortKey {
Symbol {
source_key: SourceKey,
symbol_kind: SymbolKind,
ident: Ident,
},
All,
FilePrefix {
source_key: SourceKey,
},
}
impl std::fmt::Display for DocumentSymbolSortKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
| DocumentSymbolSortKey::Symbol {
source_key,
symbol_kind,
ident,
} => write!(f, "{}|{}|{}", source_key, symbol_kind, ident),
| DocumentSymbolSortKey::All => Ok(()),
| DocumentSymbolSortKey::FilePrefix { source_key } => {
write!(f, "{}", source_key)
},
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SymbolKindVariant {
Symbol,
Reference,
}
pub trait DocumentSymbolRecord: Send + Sync + std::fmt::Debug {
fn get_ident(&self) -> Ident;
fn get_ident_path(&self) -> Vec<Ident>;
fn get_ident_range(&self) -> crate::protocol::lsp::Range;
fn source_key(&self) -> SourceKey;
fn span(&self) -> crate::source::Span;
fn symbol_kind(&self) -> SymbolKind;
fn target_source_key(&self) -> Option<SourceKey> {
None
}
fn symbol_kind_variant(&self) -> SymbolKindVariant {
SymbolKindVariant::Symbol
}
fn to_document_symbol(
&self,
source_cache: &crate::source::cache::reporter::SourceCacheReader,
encoding: &crate::protocol::lsp::PositionEncodingKind,
) -> crate::protocol::lsp::DocumentSymbol;
fn definition_location(
&self,
_source_cache: &crate::source::cache::reporter::SourceCacheReader,
_encoding: &crate::protocol::lsp::PositionEncodingKind,
) -> Option<crate::protocol::lsp::Location> {
None
}
fn hover_info(
&self,
_source_cache: &crate::source::cache::reporter::SourceCacheReader,
_encoding: &crate::protocol::lsp::PositionEncodingKind,
) -> Option<crate::protocol::lsp::Hover> {
None
}
fn rename_range(
&self,
_source_cache: &crate::source::cache::reporter::SourceCacheReader,
_encoding: &crate::protocol::lsp::PositionEncodingKind,
) -> Option<crate::protocol::lsp::Range> {
None
}
}