Skip to content

Commit

Permalink
feat(Automattic#306): harper-ls supporting default and specific lint …
Browse files Browse the repository at this point in the history
…severities
  • Loading branch information
grantlemons committed Dec 12, 2024
1 parent eaf7a9f commit c7c4ccc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion harper-ls/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl Backend {
lints_to_diagnostics(
doc_state.document.get_full_content(),
&lints,
config.diagnostic_severity,
config.default_diagnostic_severity,
)
}

Expand Down
12 changes: 6 additions & 6 deletions harper-ls/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct Config {
pub user_dict_path: PathBuf,
pub file_dict_path: PathBuf,
pub lint_config: LintGroupConfig,
pub diagnostic_severity: LintSeverity,
pub default_diagnostic_severity: LintSeverity,
pub code_action_config: CodeActionConfig,
pub isolate_english: bool,
}
Expand Down Expand Up @@ -87,12 +87,12 @@ impl Config {
}
}

if let Some(v) = value.get("linters") {
base.lint_config = serde_json::from_value(v.clone())?;
if let Some(v) = value.get("diagnosticSeverity") {
base.default_diagnostic_severity = serde_json::from_value(v.clone())?;
}

if let Some(v) = value.get("diagnosticSeverity") {
base.diagnostic_severity = serde_json::from_value(v.clone())?;
if let Some(v) = value.get("linters") {
base.lint_config = serde_json::from_value(v.clone())?;
}

if let Some(v) = value.get("codeActions") {
Expand Down Expand Up @@ -121,7 +121,7 @@ impl Default for Config {
.unwrap()
.join("harper-ls/file_dictionaries/"),
lint_config: LintGroupConfig::default(),
diagnostic_severity: LintSeverity::Hint,
default_diagnostic_severity: LintSeverity::Hint,
code_action_config: CodeActionConfig::default(),
isolate_english: false,
}
Expand Down
11 changes: 7 additions & 4 deletions harper-ls/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use crate::pos_conv::span_to_range;
pub fn lints_to_diagnostics(
source: &[char],
lints: &[Lint],
severity: LintSeverity,
default_severity: LintSeverity,
) -> Vec<Diagnostic> {
lints
.iter()
.map(|lint| lint_to_diagnostic(lint, source, severity))
.map(|lint| lint_to_diagnostic(lint, source, default_severity))
.collect()
}

Expand Down Expand Up @@ -86,12 +86,15 @@ pub fn lint_to_code_actions<'a>(
results
}

fn lint_to_diagnostic(lint: &Lint, source: &[char], severity: LintSeverity) -> Diagnostic {
fn lint_to_diagnostic(lint: &Lint, source: &[char], default_severity: LintSeverity) -> Diagnostic {
let range = span_to_range(source, lint.span);

Diagnostic {
range,
severity: Some(severity_to_lsp(severity)),
severity: lint
.severity
.or_else(|| Some(default_severity))
.map(|s| severity_to_lsp(s)),
code: None,
code_description: None,
source: Some("Harper".to_string()),
Expand Down

0 comments on commit c7c4ccc

Please sign in to comment.