Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Fix diagnostics in ignored folders after adding new files#25236

Merged
MichaReiser merged 4 commits into
mainfrom
micha/file-watching-ignored
May 23, 2026
Merged

[ty] Fix diagnostics in ignored folders after adding new files#25236
MichaReiser merged 4 commits into
mainfrom
micha/file-watching-ignored

Conversation

@MichaReiser

@MichaReiser MichaReiser commented May 19, 2026

Copy link
Copy Markdown
Member

Summary

@dhruvmanila pointed out in #25183 (comment) that there are cases where ty incorrectly adds files to the project during an incremental walk if the created files (or folders) are within an ignored directory.

The root cause is that the ignore crate doesn't check whether an input path is ignored. It follows the order, you've told me to walk this directory so I will. And neither did ty. It simply walks any directory in which it sees new files.

Unfortunately, there's no ad-hoc way of testing whether a directory or file is ignored. This is why, at least for now, this PR changes our incremental walking to always start from the project root, but incremental walking skips directories in which we didn't observe any newly created files or directories. However, we want to avoid unnecessary traversal when we can. E.g. we don't want to schedule a traversal for compilation results in the target directory if that directory is excluded. That's why this PR implements a heuristic for the common case where there is one root-level ignore or gitignore file. Any path that's excluded by those ignore files don't schedule a re-index.

@MichaReiser MichaReiser added bug Something isn't working server Related to the LSP server ty Multi-file analysis & type inference labels May 19, 2026
@MichaReiser MichaReiser changed the title [ty] Fix diagnostics in ignored files after adding new fi [ty] Fix diagnostics in ignored folders after adding new files May 19, 2026
@astral-sh-bot

astral-sh-bot Bot commented May 19, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134.

@astral-sh-bot

astral-sh-bot Bot commented May 19, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented May 19, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@MichaReiser MichaReiser changed the title [ty] Fix diagnostics in ignored folders after adding new files [ty] Fix diagnostics in ignored folders after adding new files by retraversal May 19, 2026
@BurntSushi

BurntSushi commented May 20, 2026

Copy link
Copy Markdown
Member

The root cause is that the ignore crate doesn't check whether an input path is ignored.

Yeah, the high level API is too high and the low level API is too low. Sad. I've wanted a more ad hoc API as a middle layer for a while now. So in that sense, I'd love to have it upstreamed. But I'd really want the middle level API to be used as the implementation for the high level so that the very subtle, thorny and poorly coded logic isn't replicated. It can stay subtle, thorny and poorly coded, but limiting it to 1 copy would be nice. Whether I'll have the review bandwidth for that any time soon... IDK. I'd have to see the change. If it's cheap to produce a patch, it's worth a shot. Things that would make it easier:

  1. No API breaking changes. (Not opposed to them. It's just a lot less friction to do a release this way.)
  2. Keep the new API as small as possible.

I would be tempted to go the route of full re-traversal as a temporary fix depending on the aforementioned patch. Do you have a sense via a benchmarks of the cost of this? It's obviously slower, but how does it impact the UX?

@MichaReiser MichaReiser force-pushed the micha/file-watching-ignored branch from a32c503 to 9144c15 Compare May 21, 2026 12:16
@astral-sh-bot

astral-sh-bot Bot commented May 21, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser force-pushed the micha/file-watching-ignored branch from 9144c15 to 08c3697 Compare May 21, 2026 12:22
@MichaReiser MichaReiser changed the title [ty] Fix diagnostics in ignored folders after adding new files by retraversal [ty] Fix diagnostics in ignored folders after adding new files May 21, 2026
@MichaReiser MichaReiser marked this pull request as ready for review May 21, 2026 13:11

@charliermarsh charliermarsh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. I guess the "concerning" case would be something like: a Python file is created deep in the directory hierarchy, and there's no ignore at the root, and the root has a lot of files or directories in it, etc.?

@MichaReiser

Copy link
Copy Markdown
Member Author

This makes sense to me. I guess the "concerning" case would be something like: a Python file is created deep in the directory hierarchy, and there's no ignore at the root, and the root has a lot of files or directories in it, etc.?

Yes, the concern are directories that contain a large amount of files that are not ignored at the root level in combination with a burst of didWatchedFilesChange events (they're not batched into a single or few messages).

@MichaReiser MichaReiser merged commit 8e420ea into main May 23, 2026
60 checks passed
@MichaReiser MichaReiser deleted the micha/file-watching-ignored branch May 23, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants