microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.69k stars 768 forks source link

Diagnostics from open files sometime not cleared up when file is closed. #5402

Open heejaechang opened 7 months ago

heejaechang commented 7 months ago
  1. open single folder in vscode
  2. and do FAR on Path - https://github.com/microsoft/pylance-release/blob/main/testing/single/src/findallreferences.py#L6
  3. and click all files references are found

Expected: diagnostics are cleared as new file is opened and old files are automatically closed. Actual: diagnostics are left in problems tab for long time (but it eventually goes away)

...

this repro with 2023.12.1 so must be existing bug.

it eventually goes away so it could be a perf issue. (such as even if a file is closed, we don't cancel pending request such as semantic token or checker requests running in BG so BG is staled or something like that)

rchiodo commented 4 months ago

I think this might be a VS code issue.

We get this during find all references for a file that isn't open:

2024-04-18 16:26:11.415 [info] [Trace - 4:26:11 PM] Sending notification 'textDocument/didOpen'.
2024-04-18 16:26:11.415 [info] Params: {"textDocument":{"uri":"file:///c%3A/Users/rchiodo/source/repos/pylance-release/testing/single/src/lib/__init__.py","languageId":"python","version":1,"text":"# this file conatins references used by other test files.\r\n\r\nfrom findallreferences import FindConstructor\r\n\r\n# object instantiation reference\r\nFindConstructor()\r\n\r\nxx"}}

Which then causes us to show diagnostics for a file that isn't open.

rchiodo commented 4 months ago

I can reproduce this with typescript code too. It's not just python.

rchiodo commented 4 months ago

See this: https://github.com/microsoft/vscode/issues/205790

It seems we need to switch to a pull model if we want this to work correctly. It has to do with hidden tabs.

rchiodo commented 4 months ago

In fact the documentation for pull mentions that textDocument/didOpen didClose are not a consistent method to actually tell what files are visible in the editor:

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics

rchiodo commented 4 months ago

Did open specifically says this:

DidOpenTextDocument Notification (:arrow_right:) The document open notification is sent from the client to the server to signal newly opened text documents. The document’s content is now managed by the client and the server must not try to read the document’s content using the document’s Uri. Open in this sense means it is managed by the client. It doesn’t necessarily mean that its content is presented in an editor.

rchiodo commented 4 months ago

Switching to a pull method can sort of work, but I believe there's a bug in vscode-language-client: https://github.com/microsoft/vscode-languageserver-node/issues/1464