Skip to content

Stale diagnostics when content is updated outside the editor #2353

@dhruvmanila

Description

@dhruvmanila

Summary

As seen in the following video, when I add new content to the file using echo, the diagnostics isn't updated:

Screen.Recording.2026-01-06.at.11.01.49.mov

Here's the code:

import os

import something

And, then use the following command to append the file with a new unknown import:

echo "import other\n" >> src/ty_server/bug.py

Here's what Neovim is sending when the above command is executed which is a didClose notification followed by a didOpen notification with the updated file content:

2026-01-06 11:02:09 [DEBUG] rpc.send {
  jsonrpc = "2.0",
  method = "textDocument/didClose",
  params = {
    textDocument = {
      uri = "file:///Users/dhruv/playground/ty-server/src/ty_server/bug.py"
    }
  }
}
2026-01-06 11:02:09 [DEBUG] rpc.send {
  jsonrpc = "2.0",
  method = "textDocument/didOpen",
  params = {
    textDocument = {
      languageId = "python",
      text = "import os\n\nimport something\nimport other\n\n",
      uri = "file:///Users/dhruv/playground/ty-server/src/ty_server/bug.py",
      version = 0
    }
  }
}

And, here's the logs which says that ty thinks the diagnostics are unchanged:

2026-01-06 11:02:09 [DEBUG] rpc.send {
  id = 6,
  jsonrpc = "2.0",
  method = "textDocument/diagnostic",
  params = {
    previousResultId = "919997a55b1181a2",
    textDocument = {
      uri = "file:///Users/dhruv/playground/ty-server/src/ty_server/bug.py"
    }
  }
}
2026-01-06 11:02:09 [DEBUG] rpc.receive {
  id = 6,
  jsonrpc = "2.0",
  result = {
    kind = "unchanged",
    resultId = "919997a55b1181a2"
  }
}

These are the ty server's debug logs during the didClose and didOpen events:

2026-01-06 11:02:09.644047000 DEBUG notification{method="textDocument/didClose"}: Closing file `/Users/dhruv/playground/ty-server/src/ty_server/bug.py`
2026-01-06 11:02:09.644209000 DEBUG notification{method="textDocument/didClose"}: Take open project files
2026-01-06 11:02:09.644357000 DEBUG notification{method="textDocument/didClose"}:set_open_files{open_files={}}: Set open project files (count: 0)
2026-01-06 11:02:09.644687000 DEBUG notification{method="textDocument/didOpen"}: Opening file `/Users/dhruv/playground/ty-server/src/ty_server/bug.py`
2026-01-06 11:02:09.644716000 DEBUG notification{method="textDocument/didOpen"}: Take open project files
2026-01-06 11:02:09.644771000 DEBUG notification{method="textDocument/didOpen"}:set_open_files{open_files={file(Id(c09))}}: Set open project files (count: 1)

Version

ty ruff/0.14.10+203 (e63cf978a 2026-01-05)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingserverRelated to the LSP server

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions