microsoft / microsoft/pyright

Language Server hangs due to uninitialized workspaces

Open
#11,103 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

I'm trying to integrate pyright into Eclipse via [lsp4e](https://github.com/eclipse-lsp4e/lsp4e).
The language server is successfully initialized but it does seem to respond to any requests afterwards.

I did some debugging and noticed that the workspaces are added during the `initialize` request, but are not yet initialized, due to this:
https://github.com/microsoft/pyright/blob/6f3b72c148dc9db557e133b84e0f9a962e31a9b1/packages/pyright-internal/src/workspaceFactory.ts#L38-L44

The actual initialization of the workspaces is supposed to happen when client sends the `initialized` request, but
Pyright only does this if the client does not support workspace folders (which lsp4e does):
https://github.com/microsoft/pyright/blob/6f3b72c148dc9db557e133b84e0f9a962e31a9b1/packages/pyright-internal/src/languageServerBase.ts#L705-L709
I don't understand this check, but this might be the problem?

All further requests, i.e., `textDocument/hover`, never respond, because the LS is waiting for the workspaces to be initialized.

The bug does not occur when using pyright in VS Code because the workspace initialization is also triggered when the client sends `workspace/didChangeConfiguration`, which VS Code seems to do after `initialized`. But AFAIK, doing so is not required as per LSP Spec.

**VS Code extension or command-line**
I'm using Pyright 1.1.407 through the unofficial Python package

Sidenote:
lsp4e does eventually send a `workspace/didChangeWorkspaceFolders` which re-adds all workspaces and properly initializes them, but this should not be necessary.

Contributor guide

Open the contributing guide

Research direction

Start with packages/pyright-internal/src/workspaceFactory.ts and languageServerBase.ts at the linked initialize and initialized handling. Trace how workspace folders are added and initialized when the client supports workspace folders. Done means a client such as lsp4e can send initialized and then receive responses to requests such as textDocument/hover without relying on workspace/didChangeConfiguration or workspace/didChangeWorkspaceFolders.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.