Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions crates/analysis/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zerosyntax_schema::{RefKind, ValueType};
use zerosyntax_syntax::ast::{Field, Module};
use zerosyntax_syntax::{Parse, SyntaxErrorKind, SyntaxKind, SyntaxNode, SyntaxToken};

use crate::diagnostics::{pragma_rest, pragma_words, Diagnostic, Severity};
use crate::diagnostics::{pragma_rest, pragma_words, Diagnostic};
use crate::model::scope_schema;
use crate::{nav, Analyzer, Span, WorkspaceIndex};

Expand Down Expand Up @@ -196,12 +196,8 @@ fn diagnostic_fixes(
}
_ => {}
}
// Suppress pragma: warnings and hints only; never errors, never the
// misspelled-suppression hint (suppressing it is self-defeating).
if d.severity != Severity::Error
&& d.code != "unknown-suppression"
&& suppress_seen.insert(d.code)
{
// Suppressing the misspelled-suppression hint is self-defeating.
if d.code != "unknown-suppression" && suppress_seen.insert(d.code) {
suppress_fix(parse, text, d.code, out);
}
}
Expand Down Expand Up @@ -422,7 +418,7 @@ fn stub_keyword<'a>(analyzer: &'a Analyzer, kind: RefKind) -> Option<&'a str> {
}

/// Offer to add `; zerosyntax-disable: <code>` at the top of the file (or
/// append to an existing pragma line) for warning/hint diagnostics.
/// append to an existing pragma line) for a diagnostic.
fn suppress_fix(parse: &Parse, text: &str, code: &'static str, out: &mut Vec<Fix>) {
let root = parse.syntax();
let mut first_pragma: Option<(u32, bool)> = None; // (insert offset, has_any_codes)
Expand Down Expand Up @@ -916,17 +912,14 @@ mod tests {
}

#[test]
fn suppress_fix_severity_and_dedupe_rules() {
// bad-bool is Error severity → no Suppress action.
fn suppress_fix_errors_and_dedupes() {
// Error diagnostics get the same Suppress action as warnings.
let src_err = "Weapon W\n ScaleWeaponSpeed = Maybe\nEnd\n";
let fx_err = all_fixes(src_err);
let has_suppress_for_error = fx_err
.iter()
.any(|f| f.title.contains("Suppress") && f.title.contains("bad-bool"));
assert!(
!has_suppress_for_error,
"errors must not get suppress: {fx_err:?}"
);
assert!(has_suppress_for_error, "error missing suppress: {fx_err:?}");

// Two unresolved references with the same code → only one Suppress action.
let src_dup = "Weapon W\n FireFX = NoSuchFX\n FireFX = NoSuchFX2\nEnd\n";
Expand Down
2 changes: 1 addition & 1 deletion crates/analysis/tests/spec/QuickfixSuppress.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; Quickfix test: suppress-in-file pragma.

; bad-bool fires an Error on "Maybe" → no Suppress action.
; bad-bool fires an Error on "Maybe" → Suppress action offered.
Weapon QFSuppressWeapon
ScaleWeaponSpeed = Maybe
FireFX = UnknownFXRef
Expand Down
4 changes: 2 additions & 2 deletions crates/analysis/tests/spec/QuickfixSuppress.spec.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# "Maybe" fires bad-bool (Error) → no Suppress quickfix
# "Maybe" fires bad-bool (Error) → Suppress quickfix offered
[[diag]]
severity = "error"
code = "bad-bool"
on = "Maybe"

[[action]]
on = "Maybe"
not_offers = ["Suppress"]
offers = ["Suppress"]

# UnknownFXRef fires unresolved-reference (Warning) → Suppress quickfix offered
[[diag]]
Expand Down
6 changes: 3 additions & 3 deletions docs/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Separate multiple codes with spaces or commas. Multiple file-scope pragma lines
accumulate. A misspelled code produces `unknown-suppression` instead of silently
hiding nothing.

Suppressions are intended for warnings and hints that are valid for a specific
file. Fix error-level syntax and schema problems rather than suppressing them.
Suppressions can hide any diagnostic code for a specific file. Prefer fixing
error-level syntax and schema problems when possible.

## Diagnostic codes

Expand Down Expand Up @@ -64,4 +64,4 @@ available fix.
| Create a stub definition | A reference points to a missing definition that can be scaffolded safely. |
| Remove an unreachable `WeaponSet` or `ArmorSet` | An upgrade-conditioned set can never activate. |
| Insert a matching upgrade module or set | An object has only one side of an upgrade-conditioned weapon or armor setup. |
| Suppress a code in this file | A warning or hint is intentional for the current file. |
| Suppress a code in this file | A diagnostic is intentional for the current file. |