ruff/crates/ty
Brent Westbrook e64d772788
Standardize syntax error construction (#20903)
Summary
--

This PR unifies the two different ways Ruff and ty construct syntax
errors. Ruff has been storing the primary message in the diagnostic
itself, while ty attached the message to the primary annotation:

```
> ruff check try.py
invalid-syntax: name capture `x` makes remaining patterns unreachable
 --> try.py:2:10
  |
1 | match 42:
2 |     case x: ...
  |          ^
3 |     case y: ...
  |

Found 1 error.
> uvx ty check try.py
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
Checking ------------------------------------------------------------ 1/1 files                                                                                                 
error[invalid-syntax]
 --> try.py:2:10
  |
1 | match 42:
2 |     case x: ...
  |          ^ name capture `x` makes remaining patterns unreachable
3 |     case y: ...
  |

Found 1 diagnostic
```

I think there are benefits to both approaches, and I do like ty's
version, but I feel like we should pick one (and it might help with
#20901 eventually). I slightly prefer Ruff's version, so I went with
that. Hopefully this isn't too controversial, but I'm happy to close
this if it is.

Note that this shouldn't change any other diagnostic formats in ty
because
[`Diagnostic::primary_message`](98d27c4128/crates/ruff_db/src/diagnostic/mod.rs (L177))
was already falling back to the primary annotation message if the
diagnostic message was empty. As a result, I think this change will
partially resolve the FIXME therein.

Test Plan
--

Existing tests with updated snapshots
2025-10-16 11:56:32 -04:00
..
docs [ty] Add version hint for failed stdlib attribute accesses (#20909) 2025-10-16 14:07:33 +00:00
src [ty] Limit shown import paths to at most 5 unless ty runs with -v (#20912) 2025-10-16 13:18:09 +02:00
tests Standardize syntax error construction (#20903) 2025-10-16 11:56:32 -04:00
build.rs [ty] Fix server version (#19284) 2025-07-14 09:06:34 +02:00
Cargo.toml [ty] Support LSP client settings (#19614) 2025-08-06 18:37:21 +05:30
CONTRIBUTING.md Fix link typo in ty's CONTRIBUTING.md (#18923) 2025-06-24 20:23:31 +00:00
README.md [ty] contribution guide (#18061) 2025-05-13 10:55:01 +02:00

ty

ty is an extremely fast type checker. Currently, it is a work-in-progress and not ready for production use.

The Rust code for ty lives in this repository; see CONTRIBUTING.md for more information on contributing to ty.

See the ty repo for ty documentation and releases.