Skip to content

Conversation

@dhruvmanila
Copy link
Member

Summary

Previously, the virtual files were being added to the default database that's present on the session. This is wrong because the default database is for any files that don't belong to any project i.e., they're outside of any projects managed by the server. Virtual files are neither part of the project nor it is outside the projects. This was not the intention as in the initial version, virtual files were being added to the only project database managed by the server.

This PR fixes this by reverting back to the original behavior where virtual files will be added to the only project database present. When support for multiple workspace and project is added, this will require updating (astral-sh/ty#794).

This is required for #19264 because workspace diagnostics doesn't check the default project database yet. Ideally, the default db should be checked as well.

The implementation of this PR means that virtual files are now being included for workspace diagnostics but it doesn't work completely e.g., if I save an untitled file the diagnostics disappears but it doesn't appear back for the (now) saved file on disk as shown in the following video demonstration:

Screen.Recording.2025-07-14.at.14.00.18.mov

@dhruvmanila dhruvmanila added internal An internal refactor or improvement ty Multi-file analysis & type inference server Related to the LSP server labels Jul 14, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@dhruvmanila dhruvmanila removed the internal An internal refactor or improvement label Jul 14, 2025
@dhruvmanila
Copy link
Member Author

Actually, this is not an "internal" change as the server now starts checking virtual files in workspace diagnostic mode.

@dhruvmanila
Copy link
Member Author

The implementation of this PR means that virtual files are now being included for workspace diagnostics but it doesn't work completely e.g., if I save an untitled file the diagnostics disappears but it doesn't appear back for the (now) saved file on disk as shown in the following video demonstration:

I think the reason the other case isn't working is that the file doesn't exists on disk and so the File's initial status is NotFound. This is based on the warning that I get in #19264:

2025-07-14 14:17:26.316681000  WARN notification{method="textDocument/didOpen"}: Failed to create a salsa file for /Users/dhruv/playground/ty-server/src/ty_server/other.py

Now, the linked PR does fix the issue here which I'm not exactly sure how.

@MichaReiser
Copy link
Member

This is required for #19264 because workspace diagnostics doesn't check the default project database yet. Ideally, the default db should be checked as well.

I don't think this will be necessary. We only use the default database so that we can provide basic LSP features for those files. I don't think we have to provide diagnostics.

I think the reason the other case isn't working is that the file doesn't exists on disk and so the File's initial status is NotFound. This is based on the warning that I get in #19264:

I'm not sure where this message is logged which makes it difficult to help. It probably makes sense to add a log statement to system_path_to_file to see why it returns None and if it's because the status is NotFound, why apply_changes doesn't update the file status.

@dhruvmanila dhruvmanila force-pushed the dhruv/virtual-files-in-project-db branch from c14535c to 993d565 Compare July 14, 2025 13:57
@dhruvmanila
Copy link
Member Author

Somehow, this change is also initializing the default database when I open a virtual file and select the Python language for that virtual file.

@dhruvmanila dhruvmanila merged commit b4c42eb into main Jul 14, 2025
37 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/virtual-files-in-project-db branch July 14, 2025 14:47
dcreager added a commit that referenced this pull request Jul 14, 2025
* dcreager/merge-arguments: (223 commits)
  fix docs
  Combine CallArguments and CallArgumentTypes
  [ty] Sync vendored typeshed stubs (#19334)
  [`refurb`] Make example error out-of-the-box (`FURB122`) (#19297)
  [refurb] Make example error out-of-the-box (FURB177) (#19309)
  [ty] ignore errors when reformatting codemodded typeshed (#19332)
  [ty] Provide docstrings for stdlib APIs when hovering over them in an IDE (#19311)
  [ty] Add virtual files to the only project database (#19322)
  Add t-string fixtures for rules that do not need to be modified (#19146)
  [ty] Remove `FileLookupError` (#19323)
  [ty] Fix handling of metaclasses in `object.<CURSOR>` completions
  [ty] Use an interval map for scopes by expression (#19025)
  [ty] List all `enum` members (#19283)
  [ty] Handle configuration errors in LSP more gracefully (#19262)
  [ty] Use python version and path from Python extension (#19012)
  [`pep8_naming`] Avoid false positives on standard library functions with uppercase names (`N802`) (#18907)
  Update Rust crate toml to 0.9.0 (#19320)
  [ty] Fix server version (#19284)
  Update NPM Development dependencies (#19319)
  Update taiki-e/install-action action to v2.56.13 (#19317)
  ...
@dhruvmanila dhruvmanila mentioned this pull request Jul 15, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants