Skip to main content

omena_lsp_server/
lsp_output.rs

1use crate::{LspQuerySnapshotV0, LspStyleHoverCandidate};
2use omena_query::{
3    OmenaQueryExternalSifInputV0, OmenaQuerySourceDocumentInputV0,
4    OmenaQuerySourceMissingSelectorDiagnosticCandidateV0, OmenaQuerySourceSyntaxIndexV0,
5    OmenaQueryStyleHoverCandidateV0, OmenaQueryStylePackageManifestV0,
6    OmenaQueryStyleResolutionInputsV0, OmenaQueryStyleSelectorDefinitionV0,
7    OmenaQueryStyleSourceInputV0,
8};
9use serde_json::Value;
10
11pub const OPTIMIZING_DIAGNOSTICS_DELAY_MS: u64 = 200;
12
13#[derive(Debug, Clone, PartialEq)]
14pub struct ScheduledLspOutput {
15    pub value: Value,
16    pub delay_millis: Option<u64>,
17    pub coalesce_key: Option<String>,
18}
19
20impl ScheduledLspOutput {
21    pub fn immediate(value: Value) -> Self {
22        Self {
23            value,
24            delay_millis: None,
25            coalesce_key: None,
26        }
27    }
28
29    pub fn immediate_coalesced(value: Value, coalesce_key: String) -> Self {
30        Self {
31            value,
32            delay_millis: None,
33            coalesce_key: Some(coalesce_key),
34        }
35    }
36
37    pub fn delayed(value: Value, delay_millis: u64) -> Self {
38        Self {
39            value,
40            delay_millis: Some(delay_millis),
41            coalesce_key: None,
42        }
43    }
44
45    pub fn delayed_coalesced(value: Value, delay_millis: u64, coalesce_key: String) -> Self {
46        Self {
47            value,
48            delay_millis: Some(delay_millis),
49            coalesce_key: Some(coalesce_key),
50        }
51    }
52
53    pub fn into_value(self) -> Value {
54        self.value
55    }
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub struct DiagnosticsPipelineTierPlanV0 {
60    pub baseline_evidence: &'static str,
61    pub optimizing_evidence: &'static str,
62    pub baseline_feedback_evidence: Option<&'static str>,
63}
64
65#[derive(Debug, Clone)]
66pub struct LspOwnedStyleDiagnosticsRenderInputsV0 {
67    pub document_uri: String,
68    pub document_text: String,
69    pub query_candidates: Vec<OmenaQueryStyleHoverCandidateV0>,
70    pub snapshot_id: Option<omena_query::OmenaWorkspaceSnapshotIdV0>,
71    pub style_sources: Vec<OmenaQueryStyleSourceInputV0>,
72    pub source_documents: Vec<OmenaQuerySourceDocumentInputV0>,
73    pub package_manifests: Vec<OmenaQueryStylePackageManifestV0>,
74    pub external_sifs: Vec<OmenaQueryExternalSifInputV0>,
75    pub resolution_inputs: OmenaQueryStyleResolutionInputsV0,
76    pub deep_analysis: bool,
77    pub configured_severity: u8,
78}
79
80#[derive(Debug, Clone)]
81pub struct LspOwnedSourceDiagnosticsRenderInputsV0 {
82    pub document_uri: String,
83    pub document_text: String,
84    pub source_syntax_index: OmenaQuerySourceSyntaxIndexV0,
85    pub source_selector_candidates: Vec<LspStyleHoverCandidate>,
86    pub style_sources: Vec<OmenaQueryStyleSourceInputV0>,
87    pub query_definitions: Vec<OmenaQueryStyleSelectorDefinitionV0>,
88    pub source_selector_fallback_candidates:
89        Vec<OmenaQuerySourceMissingSelectorDiagnosticCandidateV0>,
90    pub global_class_fallthroughs: Vec<LspGlobalClassFallthroughCandidateV0>,
91    pub configured_severity: u8,
92}
93
94/// A reference that failed the bound module's export set but resolved in
95/// the GLOBAL class universe (tier two): rendered as the
96/// `globalClassFallthrough` disclosure instead of a missing-selector
97/// warning. Property accesses never produce one — they have no runtime
98/// fall-through and stay strict.
99#[derive(Debug, Clone)]
100pub struct LspGlobalClassFallthroughCandidateV0 {
101    pub selector_name: String,
102    pub global_definition_uri: String,
103    pub target_style_uri: String,
104    pub target_style_source: String,
105    pub source_reference_range: omena_query::ParserRangeV0,
106}
107
108#[derive(Debug)]
109pub enum DeferredDiagnosticsRenderInputsV0 {
110    StyleSnapshot(Box<LspQuerySnapshotV0>),
111    Source(Box<LspOwnedSourceDiagnosticsRenderInputsV0>),
112}
113
114#[derive(Debug)]
115pub struct LspDeferredDiagnosticsDispatchV0 {
116    pub uri: String,
117    pub coalesce_key: String,
118    pub tier_plan: DiagnosticsPipelineTierPlanV0,
119    pub workspace_snapshot_id: Option<omena_query::OmenaWorkspaceSnapshotIdV0>,
120    pub render_inputs: DeferredDiagnosticsRenderInputsV0,
121    /// Tide-ledger epoch at dispatch time: the reverse-dependency refresh
122    /// this compute produces is stamped with it, so edits racing the
123    /// worker keep the memo honestly stale.
124    pub ledger_epoch: u64,
125}
126
127/// A reverse-dependency memo refresh produced as a BYPRODUCT of an
128/// off-loop selector build: the loop applies it from the completion
129/// channel instead of ever building a selector itself.
130#[derive(Debug, Clone)]
131pub struct LspReverseDependencyRefreshV0 {
132    pub revision: u64,
133    pub ledger_epoch: u64,
134    pub summary: omena_query::OmenaQueryCrossFileSummaryV0,
135}