PTVS icon indicating copy to clipboard operation
PTVS copied to clipboard

ILanguageClient implementation can cause race condition by sending extra didOpen notification

Open gundermanc opened this issue 1 year ago • 0 comments

Describe the bug Python Tools VS Language Server client causes multiple textDocument/didOpen notifications to be sent on solution load. Luckily PyLance seems to handle this fairly gracefully, however in some cases where the user is typing right after solution load, the textDocument/didChange changes synchronized to the document end up getting wiped out by the subsequent textDocument/didOpen, causing Pylance and the Editor to have inconsistent views of the text document content. This partially breaks intellisense features, causes some missing colorization, and misplaced or erroneous error squiggles.

Did opens originate from this stack:

Microsoft.PythonTools.dll!Microsoft.PythonTools.LanguageServerClient.PythonLanguageClient.NotifyWithParametersAsync(string request, object parameters)	Unknown
 	Microsoft.PythonTools.dll!Microsoft.PythonTools.LanguageServerClient.PythonLanguageClient.SendDocumentOpensAsync()	Unknown
 	Microsoft.PythonTools.dll!Microsoft.PythonTools.LanguageServerClient.PythonLanguageClient.InvokeDidChangeWorkspaceFoldersAsync(Microsoft.PythonTools.LanguageServerClient.WorkspaceFolderChanged.WorkspaceFolder[] added, Microsoft.PythonTools.LanguageServerClient.WorkspaceFolderChanged.WorkspaceFolder[] removed)	Unknown

I discovered this bug while investigating an apparent regression caused by: https://devdiv.visualstudio.com/DevDiv/_git/VSLanguageServerClient/pullrequest/414042. After 414042, this issue reproduces much more consistently at solution load.

I am still investigating whether or not the issues are related/

Steps to Reproduce

  1. Open latest VS main.
  2. Open https://aka.ms/vstelemetrymonitor app and set to monitor LSP messages.
  3. Create a new Python console application.
  4. Start typing immediately after the .py file opens
  5. Observe that two didOpen messages with the same content and version number are sent. Sometimes the second can be sent after didChange messages, causing all of the synchronized text from those changes to be lost and Intellisense features to malfunction.

Once the document is out of sync, it remains out of sync until closed and reopened.

gundermanc avatar Aug 08 '22 18:08 gundermanc