feat(lsp): wire diagnostic.link_severity through from client config
The broken-link diagnostic severity was already consulted by
collect_diagnostics, but Config.diagnostic was hardcoded to the default and
never populated from initializationOptions/didChangeConfiguration. Parse a
client-supplied `diagnostic.link_severity` ('off'|'hint'|'warn'|'error',
case-insensitive) into LinkSeverity and apply it in both from_init_params and
apply_change. Partial config updates that omit `diagnostic` preserve the
existing severity rather than resetting it.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -153,6 +153,21 @@ pub enum LinkSeverity {
|
||||
Error,
|
||||
}
|
||||
|
||||
impl LinkSeverity {
|
||||
/// Parse a client-supplied severity string. Case-insensitive;
|
||||
/// accepts both `warn` and `warning`. Returns `None` for unknown
|
||||
/// values so callers can fall back to the default.
|
||||
pub fn parse(s: &str) -> Option<Self> {
|
||||
match s.trim().to_ascii_lowercase().as_str() {
|
||||
"off" => Some(Self::Off),
|
||||
"hint" => Some(Self::Hint),
|
||||
"warn" | "warning" => Some(Self::Warning),
|
||||
"error" => Some(Self::Error),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WikiConfig {
|
||||
/// Synthetic default used when the client supplies neither
|
||||
/// `initializationOptions` nor a workspace root. `name` is empty;
|
||||
@@ -360,7 +375,7 @@ impl Config {
|
||||
|
||||
Config {
|
||||
wikis,
|
||||
diagnostic: DiagnosticConfig::default(),
|
||||
diagnostic: diagnostic_from_raw(&raw.diagnostic),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,6 +417,11 @@ impl Config {
|
||||
}
|
||||
self.wikis = vec![wc];
|
||||
}
|
||||
// Only touch diagnostic settings when the payload carries them, so a
|
||||
// partial `didChangeConfiguration` doesn't reset severity to default.
|
||||
if raw.diagnostic.is_some() {
|
||||
self.diagnostic = diagnostic_from_raw(&raw.diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,6 +469,25 @@ struct InitOptions {
|
||||
file_extension: Option<String>,
|
||||
syntax: Option<String>,
|
||||
log_level: Option<String>,
|
||||
diagnostic: Option<RawDiagnostic>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
struct RawDiagnostic {
|
||||
#[serde(default)]
|
||||
link_severity: Option<String>,
|
||||
}
|
||||
|
||||
/// Build a [`DiagnosticConfig`] from the raw client payload, falling back
|
||||
/// to defaults for absent or unrecognised values.
|
||||
fn diagnostic_from_raw(raw: &Option<RawDiagnostic>) -> DiagnosticConfig {
|
||||
let link_severity = raw
|
||||
.as_ref()
|
||||
.and_then(|d| d.link_severity.as_deref())
|
||||
.and_then(LinkSeverity::parse)
|
||||
.unwrap_or_default();
|
||||
DiagnosticConfig { link_severity }
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user