use crate::{
Ident,
database::{
DynPartition,
PartitionKey,
},
protocol::lsp,
};
pub struct WorkDoneProgress;
#[derive(Debug, Clone)]
pub enum WorkDoneProgressSortKey {
Token { token: String },
}
impl std::fmt::Display for WorkDoneProgressSortKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
| WorkDoneProgressSortKey::Token { token } => write!(f, "{}", token),
}
}
}
impl PartitionKey for WorkDoneProgress {
const KEY: Ident = Ident::new("laburnum::work_done_progress");
}
impl DynPartition for WorkDoneProgress {
type DynSortKey = WorkDoneProgressSortKey;
type RecordConstraint = dyn WorkDoneProgressRecord;
}
impl<R: WorkDoneProgressRecord + crate::record::Record>
crate::database::DynPartitionRecord<WorkDoneProgress> for R
{
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProgressStage {
Begin,
Report,
End,
}
pub trait WorkDoneProgressRecord: Send + Sync + std::fmt::Debug {
fn stage(&self) -> ProgressStage;
fn title(&self) -> Option<&str>;
fn message(&self) -> Option<&str>;
fn percentage(&self) -> Option<u32>;
fn cancellable(&self) -> Option<bool>;
fn to_lsp_progress(&self) -> lsp::WorkDoneProgress {
match self.stage() {
| ProgressStage::Begin => {
lsp::WorkDoneProgress::Begin(lsp::WorkDoneProgressBegin {
title: self.title().unwrap_or("Working").to_string(),
cancellable: self.cancellable(),
message: self.message().map(String::from),
percentage: self.percentage(),
})
},
| ProgressStage::Report => {
lsp::WorkDoneProgress::Report(lsp::WorkDoneProgressReport {
cancellable: self.cancellable(),
message: self.message().map(String::from),
percentage: self.percentage(),
})
},
| ProgressStage::End => {
lsp::WorkDoneProgress::End(lsp::WorkDoneProgressEnd {
message: self.message().map(String::from),
})
},
}
}
fn token(&self) -> &str;
}