-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Support publishing diagnostics in the server #18309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
4ed53ac
to
86bde6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This overall looks good.
I think there's an opportunity to reduce code duplication a bit and there are some code paths that I don't understand (see inline comments)
let lsp_diagnostics = diagnostics.as_slice().iter().map(|diagnostic| { | ||
( | ||
// TODO: Use the cell index instead using `source_kind` | ||
usize::default(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is usize::default
correct here? What is it used for? I also don't understand the comment beauase it's unclear to me where we use source kind here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to use source_kind
(which is currently commented out) to get the NotebookIndex
which will be used to get the cell index in which the diagnostics occur. This index will be used to get the URI for that cell to publish the diagnostics for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we also need to think about how this integrates with didWatchedFilesChange
. I don't think it's necessary to call publish diagnostic if a single python file changed because that file isn't open. But we have to re-publish all diagnostics when the configuration changed
d6b28cf
to
e76575a
Compare
Video testing that any changes to configuration files refreshes the diagnostics via publish mechanism in Zed: Screen.Recording.2025-05-27.at.13.03.29.mov |
crates/ty_server/src/server/api/notifications/did_change_watched_files.rs
Outdated
Show resolved
Hide resolved
3794ace
to
fc2d725
Compare
|
||
// SAFETY: Only paths that are part of the workspace are registered for file watching. | ||
// So, virtual paths and paths that are outside of a workspace does not trigger this | ||
// notification. | ||
let db = session.project_db_for_path_mut(&*root).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaReiser can you verify this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is accurate. It may change in the future but we'll then need to change this line :)
let result = db.apply_changes(changes, None); | ||
|
||
project_changed |= result.project_changed(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be fine even after we add support for multiple workspaces.
|
||
// SAFETY: Only paths that are part of the workspace are registered for file watching. | ||
// So, virtual paths and paths that are outside of a workspace does not trigger this | ||
// notification. | ||
let db = session.project_db_for_path_mut(&*root).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is accurate. It may change in the future but we'll then need to change this line :)
* main: [ty] Support ephemeral uv virtual environments (#18335) Add a `ViolationMetadata::rule` method (#18234) Return `DiagnosticGuard` from `Checker::report_diagnostic` (#18232) [flake8_use_pathlib]: Replace os.symlink with Path.symlink_to (PTH211) (#18337) [ty] Support cancellation and retry in the server (#18273) [ty] Synthetic function-like callables (#18242) [ty] Support publishing diagnostics in the server (#18309) Add Autofix for ISC003 (#18256) [`pyupgrade`]: new rule UP050 (`useless-class-metaclass-type`) (#18334) [pycodestyle] Make `E712` suggestion not assume a context (#18328)
* main: (246 commits) [ty] Simplify signature types, use them in `CallableType` (astral-sh#18344) [ty] Support ephemeral uv virtual environments (astral-sh#18335) Add a `ViolationMetadata::rule` method (astral-sh#18234) Return `DiagnosticGuard` from `Checker::report_diagnostic` (astral-sh#18232) [flake8_use_pathlib]: Replace os.symlink with Path.symlink_to (PTH211) (astral-sh#18337) [ty] Support cancellation and retry in the server (astral-sh#18273) [ty] Synthetic function-like callables (astral-sh#18242) [ty] Support publishing diagnostics in the server (astral-sh#18309) Add Autofix for ISC003 (astral-sh#18256) [`pyupgrade`]: new rule UP050 (`useless-class-metaclass-type`) (astral-sh#18334) [pycodestyle] Make `E712` suggestion not assume a context (astral-sh#18328) put similar dunder-call tests next to each other (astral-sh#18343) [ty] Derive `PartialOrd, Ord` for `KnownInstanceType` (astral-sh#18340) [ty] Simplify `Type::try_bool()` (astral-sh#18342) [ty] Simplify `Type::normalized` slightly (astral-sh#18339) [ty] Move arviz off the list of selected primer projects (astral-sh#18336) [ty] Add --config-file CLI arg (astral-sh#18083) [ty] Tell the user why we inferred a certain Python version when reporting version-specific syntax errors (astral-sh#18295) [ty] Implement implicit inheritance from `Generic[]` for PEP-695 generic classes (astral-sh#18283) [ty] Add hint if async context manager is used in non-async with statement (astral-sh#18299) ...
Summary
This PR adds support for publishing diagnostics from the ty language server.
It only adds support for it for text documents and not notebook documents because the server doesn't have full notebook support yet.
Closes: astral-sh/ty#79
Test Plan
Testing this out in Helix and Zed since those are the two editors that I know of that doesn't support pull diagnostics:
Helix
Screen.Recording.2025-05-26.at.10.36.21.mov
Zed
Screen.Recording.2025-05-26.at.10.30.22.mov