Skip to content

Commit 5f5e14d

Browse files
authored
fix(ide): lower unused diagnostics to hints (#145)
1 parent 5538f5d commit 5f5e14d

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/lsp_ext/to_proto.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub(crate) fn diagnostic(
139139
let tags = diagnostic_tags(&diag);
140140
lsp_types::Diagnostic {
141141
range: self::range(line_info, diag.range),
142-
severity: diagnostic_severity(diag.severity),
142+
severity: diagnostic_severity(&diag),
143143
code: Some(lsp_types::NumberOrString::String(format!("{}:{}", diag.subsystem, diag.code))),
144144
code_description: None,
145145
source: Some(
@@ -203,9 +203,15 @@ fn diagnostic_selector_hints(diag: &ide_diagnostics::Diagnostic) -> Vec<String>
203203
selectors
204204
}
205205

206-
fn diagnostic_severity(severity: SlangDiagnosticSeverity) -> Option<lsp_types::DiagnosticSeverity> {
206+
fn diagnostic_severity(
207+
diag: &ide_diagnostics::Diagnostic,
208+
) -> Option<lsp_types::DiagnosticSeverity> {
209+
if diagnostic_is_unnecessary(diag) {
210+
return Some(lsp_types::DiagnosticSeverity::HINT);
211+
}
212+
207213
use lsp_types::DiagnosticSeverity as LspSeverity;
208-
match severity {
214+
match diag.severity {
209215
SlangDiagnosticSeverity::Ignored => None,
210216
SlangDiagnosticSeverity::Note => Some(LspSeverity::INFORMATION),
211217
SlangDiagnosticSeverity::Warning => Some(LspSeverity::WARNING),
@@ -225,6 +231,10 @@ fn diagnostic_tags(diag: &ide_diagnostics::Diagnostic) -> Option<Vec<lsp_types::
225231
(!tags.is_empty()).then_some(tags)
226232
}
227233

234+
fn diagnostic_is_unnecessary(diag: &ide_diagnostics::Diagnostic) -> bool {
235+
diag.tags.contains(&ide_diagnostics::DiagnosticTag::Unnecessary)
236+
}
237+
228238
fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind {
229239
use lsp_types::SymbolKind as LspSymbolKind;
230240
match symbol_kind {
@@ -924,7 +934,7 @@ mod tests {
924934
use crate::i18n::{I18n, Locale};
925935

926936
#[test]
927-
fn diagnostic_maps_unnecessary_tag() {
937+
fn diagnostic_maps_unnecessary_tag_as_hint() {
928938
let line_info = LineInfo {
929939
index: Arc::new(LineIndex::new("logic inactive;\n")),
930940
ending: LineEnding::Unix,
@@ -948,6 +958,8 @@ mod tests {
948958

949959
let lsp_diag = diagnostic(I18n::new(Locale::En), &line_info, diag);
950960

961+
assert_eq!(lsp_diag.severity, Some(lsp_types::DiagnosticSeverity::HINT));
962+
assert_eq!(lsp_diag.code, Some(lsp_types::NumberOrString::String("0:2".to_owned())));
951963
assert_eq!(lsp_diag.tags, Some(vec![lsp_types::DiagnosticTag::UNNECESSARY]));
952964
}
953965
}

0 commit comments

Comments
 (0)