Skip to content

Commit 2d09b5b

Browse files
committed
diagnostics: Fix specificity calculation for message-based matches
Fixed a bug in `calculate_match_specificity` where the priority bonus for message-based pattern matches was computed but not returned. The function was executing `specificity + 2` instead of `specificity += 2`, resulting in message-based matches having the same priority as code-based matches. This caused the diagnostic configuration system to incorrectly handle cases where both code-based and message-based patterns matched the same diagnostic. Message-based patterns should have higher priority (specificity +2) to allow more fine-grained control. Added a test case to verify that message-based literal matches (specificity=4) are correctly prioritized over code-based regex matches (specificity=1).
1 parent 0a65a5a commit 2d09b5b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/diagnostics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function calculate_match_specificity(
148148
end
149149
specificity == 0 && return specificity
150150
if is_message_match
151-
specificity + 2
151+
specificity += 2
152152
end
153153
return specificity
154154
end

test/test_diagnostics.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,32 @@ end
562562
JETLS.apply_diagnostic_config!(diagnostics, manager)
563563
@test isempty(diagnostics)
564564
end
565+
566+
# message-based patterns should have higher priority than code-based patterns
567+
let diagnostics = [
568+
make_test_diagnostic(;
569+
code = JETLS.LOWERING_MACRO_EXPANSION_ERROR_CODE,
570+
severity = DiagnosticSeverity.Error,
571+
message = "Macro name `@interface` not found")
572+
]
573+
manager = make_test_manager(Dict{String,Any}(
574+
"diagnostic" => Dict{String,Any}(
575+
"patterns" => [
576+
Dict{String,Any}(
577+
"pattern" => "lowering/macro-expansion-error",
578+
"match_by" => "code",
579+
"match_type" => "literal",
580+
"severity" => "hint"),
581+
Dict{String,Any}(
582+
"pattern" => "Macro name `@interface` not found",
583+
"match_by" => "message",
584+
"match_type" => "literal",
585+
"severity" => "info"),
586+
])))
587+
JETLS.apply_diagnostic_config!(diagnostics, manager)
588+
@test length(diagnostics) == 1
589+
@test only(diagnostics).severity == DiagnosticSeverity.Information
590+
end
565591
end
566592
end
567593

0 commit comments

Comments
 (0)