Skip to content

Commit 0847063

Browse files
committed
docs: Add documentation comments to project hooks and refactor hook vector initialization.
1 parent 168fdd6 commit 0847063

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

crates/tinymist/src/project.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ impl ServerState {
189189
stats: Arc::default(),
190190
});
191191

192-
let mut hooks: Vec<Box<dyn CompileHook + Send + Sync>> = Vec::new();
193-
hooks.push(Box::new(DiagHook::new(analysis.clone(), editor_tx.clone())));
194-
hooks.push(Box::new(LintHook::new(analysis.clone(), editor_tx.clone())));
192+
let mut hooks: Vec<Box<dyn CompileHook + Send + Sync>> = vec![
193+
Box::new(DiagHook::new(analysis.clone(), editor_tx.clone())),
194+
Box::new(LintHook::new(analysis.clone(), editor_tx.clone())),
195+
];
195196
#[cfg(feature = "preview")]
196197
hooks.push(Box::new(PreviewHook::new(preview)));
197198
#[cfg(feature = "export")]
@@ -466,12 +467,14 @@ fn push_editor_diagnostics(
466467
.log_error("failed to send diagnostics");
467468
}
468469

470+
/// A hook that handles diagnostics.
469471
pub struct DiagHook {
470472
analysis: Arc<Analysis>,
471473
editor_tx: EditorSender,
472474
}
473475

474476
impl DiagHook {
477+
/// Creates a new diagnostics hook.
475478
pub fn new(analysis: Arc<Analysis>, editor_tx: EditorSender) -> Self {
476479
Self {
477480
analysis,
@@ -499,8 +502,11 @@ impl DiagHook {
499502
}
500503
}
501504

505+
/// A hook that handles compilation events.
502506
pub trait CompileHook {
507+
/// Notifies the hook of a compilation result.
503508
fn notify(&self, dv: ProjVersion, art: &LspCompiledArtifact, client: &Arc<dyn ProjectClient>);
509+
/// Notifies the hook of a compilation status.
504510
fn status(&self, _revision: usize, _rep: &CompileReport) {}
505511
}
506512

@@ -515,12 +521,14 @@ impl CompileHook for DiagHook {
515521
}
516522
}
517523

524+
/// A hook that handles linting.
518525
pub struct LintHook {
519526
analysis: Arc<Analysis>,
520527
editor_tx: EditorSender,
521528
}
522529

523530
impl LintHook {
531+
/// Creates a new lint hook.
524532
pub fn new(analysis: Arc<Analysis>, editor_tx: EditorSender) -> Self {
525533
Self {
526534
analysis,
@@ -584,12 +592,14 @@ impl CompileHook for LintHook {
584592

585593
#[cfg(feature = "preview")]
586594
#[derive(Clone)]
595+
/// A hook that handles preview.
587596
pub struct PreviewHook {
588597
state: ProjectPreviewState,
589598
}
590599

591600
#[cfg(feature = "preview")]
592601
impl PreviewHook {
602+
/// Creates a new preview hook.
593603
pub fn new(state: ProjectPreviewState) -> Self {
594604
Self { state }
595605
}
@@ -616,6 +626,7 @@ impl PreviewHook {
616626
}
617627
}
618628

629+
#[allow(dead_code)]
619630
fn state(&self) -> ProjectPreviewState {
620631
self.state.clone()
621632
}
@@ -639,16 +650,19 @@ impl CompileHook for PreviewHook {
639650

640651
#[cfg(feature = "export")]
641652
#[derive(Clone)]
653+
/// A hook that handles export.
642654
pub struct ExportHook {
643655
task: crate::task::ExportTask,
644656
}
645657

646658
#[cfg(feature = "export")]
647659
impl ExportHook {
660+
/// Creates a new export hook.
648661
pub fn new(task: crate::task::ExportTask) -> Self {
649662
Self { task }
650663
}
651664

665+
#[allow(dead_code)]
652666
fn task(&self) -> crate::task::ExportTask {
653667
self.task.clone()
654668
}

crates/tinymist/src/tool/project.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ where
8484
let export_task =
8585
crate::task::ExportTask::new(handle, Some(editor_tx.clone()), opts.config.export());
8686

87-
let mut hooks: Vec<Box<dyn CompileHook + Send + Sync>> = Vec::new();
88-
hooks.push(Box::new(DiagHook::new(analysis.clone(), editor_tx.clone())));
89-
hooks.push(Box::new(LintHook::new(analysis.clone(), editor_tx.clone())));
87+
let mut hooks: Vec<Box<dyn CompileHook + Send + Sync>> = vec![
88+
Box::new(DiagHook::new(analysis.clone(), editor_tx.clone())),
89+
Box::new(LintHook::new(analysis.clone(), editor_tx.clone())),
90+
];
9091
#[cfg(feature = "preview")]
9192
hooks.push(Box::new(PreviewHook::new(preview)));
9293
#[cfg(feature = "export")]

0 commit comments

Comments
 (0)