use crate::{
Ident,
SourceKey,
database::{
DynPartition,
PartitionKey,
},
protocol::lsp::FoldingRange,
};
pub struct DocumentFoldingRange;
impl PartitionKey for DocumentFoldingRange {
const KEY: Ident = Ident::new("laburnum::document_folding_range");
}
impl DynPartition for DocumentFoldingRange {
type DynSortKey = FoldingRangeSortKey;
type RecordConstraint = dyn FoldingRangeRecord;
}
impl<R: FoldingRangeRecord + crate::record::Record>
crate::database::DynPartitionRecord<DocumentFoldingRange> for R
{
}
#[derive(Debug, Clone)]
pub enum FoldingRangeSortKey {
Range {
source_key: SourceKey,
start_line: u32,
end_line: u32,
start_character: u32,
end_character: u32,
},
All,
FilePrefix {
source_key: SourceKey,
},
}
impl std::fmt::Display for FoldingRangeSortKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
| FoldingRangeSortKey::Range {
source_key,
start_line,
end_line,
start_character,
end_character,
} => {
write!(
f,
"{}|{:010}|{:010}|{:010}|{:010}",
source_key, start_line, end_line, start_character, end_character
)
},
| FoldingRangeSortKey::All => Ok(()),
| FoldingRangeSortKey::FilePrefix { source_key } => {
write!(f, "{}", source_key)
},
}
}
}
pub trait FoldingRangeRecord: Send + Sync + std::fmt::Debug {
fn source_key(&self) -> SourceKey;
fn to_folding_range(&self) -> FoldingRange;
}