Skip to content

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Dec 3, 2025

Summary

fixes: astral-sh/ty#1727

This PR fixes the reported duplicated diagnostic in astral-sh/ty#1727 by skipping publish_diagnostics
if pull diagnostics are enabled, similar to how we do this in other places.

While this PR fixes the duplicate diagnostics, there's still the question why vim sends didChangeWatchedFiles for
a file that's currently open in the editor. The issue with that is that the server is now in this awkward spot
that it has to decide whether it should use the new content on disk OR the content that's currently open in the editor (as reported by didOpen, didChange). For now, ty uses the content sent by didOpen/didChange,
meaning, ty will ignore the new content when checking the project.

I think this is the sensible thing to do here. The client either has to tell the server that the file is now closed,
in which case ty will use the content from disk, or that the user accepted the on-disk changes over the in-editor changes
by sending a didChange notification.

Test Plan

Added E2E test

@MichaReiser MichaReiser requested a review from carljm as a code owner December 3, 2025 07:55
@MichaReiser MichaReiser added the bug Something isn't working label Dec 3, 2025
@MichaReiser MichaReiser requested a review from sharkdp as a code owner December 3, 2025 07:55
@MichaReiser MichaReiser added the server Related to the LSP server label Dec 3, 2025
@MichaReiser MichaReiser requested a review from dcreager as a code owner December 3, 2025 07:55
@MichaReiser MichaReiser added bug Something isn't working server Related to the LSP server labels Dec 3, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 3, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 3, 2025

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/_logging.py:153:13: warning[unsupported-base] Unsupported class base with type `<class 'Mapping[str, Style]'> | <class 'Mapping[str, Divergent]'>`
- Found 42 diagnostics
+ Found 41 diagnostics

No memory usage changes detected ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 3, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser force-pushed the micha/did-changed-watched-files-publish-diagnostics branch from 5015526 to 3abadc2 Compare December 3, 2025 08:22
@MichaReiser MichaReiser force-pushed the micha/did-changed-watched-files-publish-diagnostics branch from 3abadc2 to 1e71d29 Compare December 3, 2025 08:25
@AlexWaygood AlexWaygood removed their request for review December 3, 2025 08:37
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Dec 3, 2025
@carljm carljm requested review from dhruvmanila and removed request for carljm December 4, 2025 00:33
@dhruvmanila
Copy link
Member

While this PR fixes the duplicate diagnostics, there's still the question why vim sends didChangeWatchedFiles for
a file that's currently open in the editor.

Yeah, I'm not sure either. I looked at the request payload:

{
  jsonrpc = '2.0',
  method = 'workspace/didChangeWatchedFiles',
  params = {
    changes = {
      { type = 3, uri = 'file:///Users/dhruv/dotfiles/4913' },
      { type = 1, uri = 'file:///Users/dhruv/dotfiles/t.py' },
      { type = 3, uri = 'file:///Users/dhruv/dotfiles/t.py~' },
    },
  },
}

It seems to be sending an entry stating that the t.py file was created which seems weird because the file is already open in the editor and it already exists on the filesystem.

@MichaReiser MichaReiser merged commit a9f2bb4 into main Dec 4, 2025
41 checks passed
@MichaReiser MichaReiser deleted the micha/did-changed-watched-files-publish-diagnostics branch December 4, 2025 07:12
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.

vim.diagnostic.setloclist: Duplicate diagnostics shown after buffer save

4 participants