InSyncWithFoo / pyright-langserver-for-pycharm

Pyright language server integration for PyCharm Professional
https://insyncwithfoo.github.io/pyright-langserver-for-pycharm/
MIT License
51 stars 2 forks source link

WSL: Pyright correctly identifies issues in the log but the annotations don't appear in Pycharm #78

Open Tamjow opened 1 month ago

Tamjow commented 1 month ago

What happened?

Hello, I'm having an issue with the annotations not showing up in pycharm, even though pyright does correctly identify issues with code and logs them. This plugin used to work for me previously (first version with WSL support), but I haven't been able to make it work since reinstalling Windows and setting up WSL again.

Current versions: Pyright langserver Pycharm plugin: 1.1.0 (also tested the version that previously worked, specifically from this comment) Python: 3.10.12 Pyright: 1.1.375 Pycharm: 2024.2.1 (tried 2024.1.4 as well with no effect)

What I tried: Everything from the problems page, even a fresh IDE reinstall without using any of the old data didn't help. Additionally:

Relevant settings: pycharm64_2024-09-09_10-16-39 pycharm64_2024-09-09_10-16-44 image

Steps to reproduce

in WSL

  1. Install the Pyright langserver Pycharm plugin
  2. Set it up to use either the global pyright-langserver or one in a venv specific to the project
  3. Notice that despite showing in logs, the annotations don't appear in the Pycharm window

Code used to test

def foo(v: str) -> None:
    ...

foo(5)

Relevant log output or stack trace

2024-09-09 10:15:12,465 [  59987]   INFO - #c.i.p.l.i.LspServerImpl - PyrightLSDescriptor@newproj(ShutdownNormally;0): LSP server process terminated. Exit code: 143
Command line: /home/mat/.local/bin/pyright-langserver --stdio
2024-09-09 10:15:12,512 [  60034]   INFO - #com.insyncwithfoo.pyrightls.server.PyrightLSDescriptor - AllConfigurations(alwaysUseGlobal=true, globalExecutable=\\wsl.localhost\Ubuntu\home\mat\.local\bin\pyright-langserver, useEditorFont=false, addTooltipPrefix=true, linkErrorCodes=false, hoverSupport=true, completionSupport=false, goToDefinitionSupport=false, logLevel=WARNING, taggedHints=true, autoImportCompletions=true, autocompleteParentheses=false, diagnosticsSupport=true, autoRestartServer=false, monkeypatchAutoImportDetails=true, monkeypatchTrailingQuoteBug=true, projectExecutable=null, autoSuggestExecutable=true, workspaceFolders=PROJECT_BASE, targetedFileExtensions=py|pyi, diagnosticMode=OPEN_FILES_ONLY, autoSearchPaths=true)
2024-09-09 10:15:12,513 [  60035]   INFO - #c.i.p.l.i.LspServerImpl - PyrightLSDescriptor@newproj(Initializing;0): Starting LSP server
2024-09-09 10:15:12,513 [  60035]   INFO - #c.i.p.l.a.LspServerDescriptor - PyrightLSDescriptor@newproj: starting LSP server: /home/mat/.local/bin/pyright-langserver [--stdio]
2024-09-09 10:15:12,521 [  60043]   INFO - #c.i.p.l.i.LspServerImpl - PyrightLSDescriptor@newproj(Initializing;0): LSP server process started: /home/mat/.local/bin/pyright-langserver --stdio
2024-09-09 10:15:12,521 [  60043]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - PyrightLSDescriptor@newproj: LSP server listener thread started
2024-09-09 10:15:12,521 [  60043]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - PyrightLSDescriptor@newproj: initializing LSP server
2024-09-09 10:15:12,524 [  60046]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - --> PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":"1","method":"initialize","params":{"processId":null,"rootPath":"//wsl.localhost/Ubuntu/home/mat/test/newproj","rootUri":"file:///home/mat/test/newproj","capabilities":{"workspace":{"workspaceEdit":{"documentChanges":true,"resourceOperations":["create"],"failureHandling":"abort"},"didChangeWatchedFiles":{"relativePatternSupport":true,"dynamicRegistration":true},"executeCommand":{"dynamicRegistration":false},"workspaceFolders":true},"textDocument":{"completion":{"completionItem":{"snippetSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation"]},"labelDetailsSupport":true},"completionList":{"itemDefaults":["commitCharacters","editRange","insertTextFormat","insertTextMode","data"]}},"hover":{"contentFormat":["markdown","plaintext"]},"references":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"definition":{"linkSupport":true},"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","","source","refactor"]}},"disabledSupport":true,"dataSupport":true,"resolveSupport":{"properties":["edit"]}},"publishDiagnostics":{"tagSupport":{"valueSet":[1,2]},"versionSupport":true}},"window":{"showMessage":{},"showDocument":{"support":true}},"general":{"staleRequestSupport":{"cancel":true,"retryOnContentModified":[]}}},"clientInfo":{"name":"PyCharm Professional Edition","version":"242.21829.153"},"workspaceFolders":[{"uri":"file:///home/mat/test/newproj","name":"newproj"}]}}
2024-09-09 10:15:12,665 [  60187]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - <-- PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Pyright language server 1.1.375 starting"}}
2024-09-09 10:15:12,666 [  60188]   INFO - #c.i.p.l.i.LspServerImpl - PyrightLSDescriptor@newproj(Initializing;0): window/logMessage Info: Pyright language server 1.1.375 starting
2024-09-09 10:15:12,666 [  60188]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - <-- PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server root directory: file:///home/mat/.cache/pyright-python/1.1.375/node_modules/pyright/dist"}}
2024-09-09 10:15:12,666 [  60188]   INFO - #c.i.p.l.i.LspServerImpl - PyrightLSDescriptor@newproj(Initializing;0): window/logMessage Info: Server root directory: file:///home/mat/.cache/pyright-python/1.1.375/node_modules/pyright/dist
2024-09-09 10:15:12,670 [  60192]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - <-- PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Starting service instance \"newproj\""}}
2024-09-09 10:15:12,670 [  60192]   INFO - #c.i.p.l.i.LspServerImpl - PyrightLSDescriptor@newproj(Initializing;0): window/logMessage Info: Starting service instance "newproj"
2024-09-09 10:15:12,670 [  60192]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - <-- PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":"1","result":{"capabilities":{"textDocumentSync":2,"definitionProvider":{"workDoneProgress":true},"declarationProvider":{"workDoneProgress":true},"typeDefinitionProvider":{"workDoneProgress":true},"referencesProvider":{"workDoneProgress":true},"documentSymbolProvider":{"workDoneProgress":true},"workspaceSymbolProvider":{"workDoneProgress":true},"hoverProvider":{"workDoneProgress":true},"documentHighlightProvider":{"workDoneProgress":true},"renameProvider":{"prepareProvider":true,"workDoneProgress":true},"completionProvider":{"triggerCharacters":[".","[","\"","'"],"resolveProvider":true,"workDoneProgress":true,"completionItem":{"labelDetailsSupport":true}},"signatureHelpProvider":{"triggerCharacters":["(",",",")"],"workDoneProgress":true},"codeActionProvider":{"codeActionKinds":["quickfix","source.organizeImports"],"workDoneProgress":true},"executeCommandProvider":{"commands":[],"workDoneProgress":true},"callHierarchyProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}}}}}
2024-09-09 10:15:12,673 [  60195]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - --> PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","method":"initialized","params":{}}
2024-09-09 10:15:12,675 [  60197]   INFO - #c.i.p.l.i.LspServerImpl - PyrightLSDescriptor@newproj(Running;0): LSP server initialized in 0.162s
2024-09-09 10:15:12,675 [  60197]   FINE - #c.i.p.l.i.LspServerImpl - PyrightLSDescriptor@newproj(Running;0): Opening files after server initialization or after move/rename: [file:////wsl.localhost/Ubuntu/home/mat/test/newproj/test.py]
2024-09-09 10:15:12,675 [  60197]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - --> PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"python":{"pythonPath":"/home/mat/test/newproj/env/bin/python","analysis":{"logLevel":"Warning","autoImportCompletions":true,"diagnosticMode":"openFilesOnly","autoSearchPaths":true}},"pyright":{"disableTaggedHints":false}}}}
2024-09-09 10:15:12,677 [  60199]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - --> PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///home/mat/test/newproj/test.py","languageId":"python","version":19,"text":"def foo(v: str) -\u003e None:\n    ...\n\nfoo(5)"}}}
2024-09-09 10:15:12,677 [  60199]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - <-- PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":0,"method":"client/registerCapability","params":{"registrations":[{"id":"365d7b65-5f3d-4699-9ef3-199801cbb619","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/pyrightconfig.json","kind":7},{"globPattern":"**","kind":7}]}}]}}
2024-09-09 10:15:12,679 [  60201]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - --> PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":0,"result":null}
2024-09-09 10:15:12,731 [  60253]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - <-- PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":1,"method":"client/registerCapability","params":{"registrations":[{"id":"8809426f-d4d9-4ef9-8144-bde2cce11021","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/pyrightconfig.json","kind":7},{"globPattern":"**","kind":7},{"globPattern":{"baseUri":"file:///usr/lib/python3.10","pattern":"**"},"kind":7}]}}]}}
2024-09-09 10:15:12,732 [  60254]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - --> PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":1,"result":null}
2024-09-09 10:15:12,733 [  60255]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - <-- PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":2,"method":"client/unregisterCapability","params":{"unregisterations":[{"id":"365d7b65-5f3d-4699-9ef3-199801cbb619","method":"workspace/didChangeWatchedFiles"}]}}
2024-09-09 10:15:12,733 [  60255]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - --> PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":2,"result":null}
2024-09-09 10:15:13,065 [  60587]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - <-- PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/mat/test/newproj/test.py","version":19,"diagnostics":[{"range":{"start":{"line":3,"character":4},"end":{"line":3,"character":5}},"message":"Argument of type \"Literal[5]\" cannot be assigned to parameter \"v\" of type \"str\" in function \"foo\"\n  \"Literal[5]\" is incompatible with \"str\"","severity":1,"code":"reportArgumentType","source":"Pyright","codeDescription":{"href":"https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType"}},{"range":{"start":{"line":0,"character":8},"end":{"line":0,"character":9}},"message":"\"v\" is not accessed","severity":4,"source":"Pyright","tags":[1]}]}}
2024-09-09 10:15:13,068 [  60590]   WARN - #c.i.p.l.i.LspDiagnosticsCache - Could not find file with diagnostics: file:///home/mat/test/newproj/test.py
2024-09-09 10:15:14,252 [  61774]   INFO - #c.i.u.g.s.GistStorageImpl - Cleaning old huge-gists dirs from [C:\Users\Mat\AppData\Local\JetBrains\PyCharm2024.2\caches\huge-gists] ...
2024-09-09 10:15:14,253 [  61775]   INFO - #c.i.u.g.s.GistStorageImpl - Cleaning old huge-gists dirs finished
2024-09-09 10:15:14,661 [  62183]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - --> PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":"2","method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///home/mat/test/newproj/test.py"},"range":{"start":{"line":2,"character":0},"end":{"line":2,"character":0}},"context":{"diagnostics":[],"triggerKind":2}}}
2024-09-09 10:15:14,664 [  62186]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - <-- PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","id":"2","result":[]}
2024-09-09 10:15:16,124 [  63646]   FINE - #c.i.p.l.i.c.Lsp4jServerConnector - --> PyrightLSDescriptor@newproj: {"jsonrpc":"2.0","method":"workspace/didChangeWatchedFiles","params":{"changes":[{"uri":"file:///home/mat/test/newproj/test.py","type":2}]}}
2024-09-09 10:15:16,434 [  63956]   INFO - #c.i.w.i.i.j.s.JpsGlobalModelSynchronizerImpl - Saving global entities com.intellij.platform.workspace.jps.entities.SdkEntity to files
2024-09-09 10:15:16,435 [  63957]   INFO - #c.i.w.i.i.j.s.JpsGlobalModelSynchronizerImpl - Saving global entities com.intellij.platform.workspace.jps.entities.LibraryEntity to files

Operating system

Windows

InSyncWithFoo commented 1 month ago

I couldn't reproduce the problem, even with the same configurations, WSL distro, Pyright version, PyCharm version and project/file locations. The outputs (plus minor rearrangements) are almost identical, save for the user names and wsl.localhost/wsl$ (note that I also used the former in my executable path).

I'm sorry to say that I'm out of ideas for now. I know this shouldn't be the case, but as a workaround, you could temporarily switch back to Windows until we find out what the cause is.

Tamjow commented 1 month ago

Thanks for trying my configuration, one thing I forgot to mention was that it previously worked on my Windows 10 and my (re)install changed it to Windows 11, so maybe that's related. Regardless I appreciate your attempt, I'll try to figure out some workarounds or maybe I'll try on a different W11 machine to verify.