Skip to content

Comments

[ty] Fix stale documents on Windows#18544

Merged
MichaReiser merged 3 commits intomainfrom
micha/ty-server-document-key-api
Jun 9, 2025
Merged

[ty] Fix stale documents on Windows#18544
MichaReiser merged 3 commits intomainfrom
micha/ty-server-document-key-api

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jun 8, 2025

Summary

This is mostly a refactor which should fix the stale diagnostics on Windows (I've to test this when I'm back home and have access to my windows machine).

The main refactor is that Index now stores a map from AnySystemPath to the documents instead of Url. This removes the need to convert between Url -> AnySystemPath and AnySystemPath -> Url, which can lead mismatches.

Closes astral-sh/ty#601

Test Plan

Tested that completions and diagnostics work on macos.

Screen.Recording.2025-06-08.162410.mp4

- Update publish_diagnostics to accept DocumentKey instead of Url
- Change LSPSystem::make_document_ref to take AnySystemPath directly
- Add Session::text_document_keys method for DocumentKey iteration
- Update notification handlers to use DocumentKey consistently
- Remove URL conversion overhead in diagnostic workflows
@MichaReiser MichaReiser added server Related to the LSP server ty Multi-file analysis & type inference labels Jun 8, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2025

mypy_primer results

No ecosystem changes detected ✅

@MichaReiser
Copy link
Member Author

I still have to test if this fixes the bug on windows. I plan to do this later today. But I think this is good for review.

@MichaReiser MichaReiser marked this pull request as ready for review June 8, 2025 07:45
@MichaReiser MichaReiser requested review from dhruvmanila and removed request for AlexWaygood, carljm, dcreager and sharkdp June 8, 2025 07:46
@AlexWaygood AlexWaygood added the windows Specific to the Windows platform label Jun 8, 2025
Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Looks good, thank you for jumping on and fixing this quickly!

Comment on lines +31 to 34
let Ok(key) = session.key_from_url(uri.clone()) else {
tracing::debug!("Failed to create document key from URI: {}", uri);
return Ok(());
};
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to your PR, there are various instances of this kind of failures like this one and then there's key.to_url() where adding these debug logs consistently would be useful.

Comment on lines 44 to 52
#[derive(Clone, Debug)]
pub enum DocumentKey {
Notebook(Url),
NotebookCell(Url),
Text(Url),
pub(crate) enum DocumentKey {
Notebook(AnySystemPath),
NotebookCell {
cell_url: Url,
notebook_path: AnySystemPath,
},
Text(AnySystemPath),
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we keep the Url as well for both Notebook and Text variants? That might help to avoid converting between AnySystemPath and Url. This would make the key.to_url calls to return Url instead of Option<Url> and avoid the cost of converting a path to Url when we already had the Url before.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, but the Url is not available in the LSPSystem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, and the client seems to be fine if the urls are slightly different. We could consider making AnySystemPath more strict so that toUrl could never fail but seems like a different refactor

@dhruvmanila
Copy link
Member

I still have to test if this fixes the bug on windows. I plan to do this later today. But I think this is good for review.

I'm assuming that the video in the PR description is on Windows.

@MichaReiser MichaReiser merged commit b44062b into main Jun 9, 2025
35 checks passed
@MichaReiser MichaReiser deleted the micha/ty-server-document-key-api branch June 9, 2025 14:39
med1844 pushed a commit to med1844/ruff that referenced this pull request Jun 10, 2025
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 windows Specific to the Windows platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

diagnostics don't update until the language server is restarted on windows

3 participants