helix: "Failed to parse WorkspaceConfiguration params" with pyright LSP server

Summary

When trying to open any .py file with Helix 22.03 and the pyright LSP server configured, Helix crashes out as soon as the file is opened with the following backtrace:

thread ‘main’ panicked at ‘Failed to parse WorkspaceConfiguration params: Error { code: InvalidParams, message: “Invalid params: invalid value: string "", expected relative URL without a base.”, data: None }’, helix-lsp/src/lib.rs:216:22

v0.6.0 worked fine, presumably this is because of PR #1684.

Reproduction Steps

I tried this:

  1. hx -vvv models.py

I expected this to happen:

  • The editor is opened, I can edit the file, and pyright LSP server works as expected with diagnostics, completion, etc.

Instead, this happened:

  • The editor immediately crashes out with a backtrace.

Helix log

~/.cache/helix/helix.log
2022-03-31T10:04:28.414 helix_view::theme [WARN] Theme: invalid style attribute: modifier
2022-03-31T10:04:28.447 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE | WRITABLE
2022-03-31T10:04:28.447 mio::poll [TRACE] registering event source with poller: token=Token(2), interests=READABLE | WRITABLE
2022-03-31T10:04:28.447 mio::poll [TRACE] registering event source with poller: token=Token(3), interests=READABLE | WRITABLE
2022-03-31T10:04:28.447 mio::poll [TRACE] registering event source with poller: token=Token(4), interests=READABLE | WRITABLE
2022-03-31T10:04:28.447 mio::poll [TRACE] registering event source with poller: token=Token(5), interests=READABLE | WRITABLE
2022-03-31T10:04:28.447 helix_lsp::client [INFO] Using custom LSP config: "{\n  \"python\": {\n    \"analysis\": {\n      \"autoSearchPaths\": true,\n      \"diagnosticMode\": \"workspace\",\n      \"useLibraryCodeForTypes\": true\n    }\n  }\n}\n"
2022-03-31T10:04:28.447 mio::poll [TRACE] registering event source with poller: token=Token(0), interests=READABLE
2022-03-31T10:04:28.447 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE
2022-03-31T10:04:28.447 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":false}},"window":{"workDoneProgress":true},"workspace":{"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false}}},"initializationOptions":"{\n  \"python\": {\n    \"analysis\": {\n      \"autoSearchPaths\": true,\n      \"diagnosticMode\": \"workspace\",\n      \"useLibraryCodeForTypes\": true\n    }\n  }\n}\n","processId":33075,"rootUri":"file:///home/me/work/code/project"},"id":0}
2022-03-31T10:04:28.668 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Pyright language server 1.1.234 starting"}}
2022-03-31T10:04:28.668 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server root directory: /usr/lib/node_modules/pyright/dist/"}}
2022-03-31T10:04:28.669 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "Pyright language server 1.1.234 starting" }
2022-03-31T10:04:28.670 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "Server root directory: /usr/lib/node_modules/pyright/dist/" }
2022-03-31T10:04:28.672 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":0,"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},"signatureHelpProvider":{"triggerCharacters":["(",",",")"],"workDoneProgress":true},"codeActionProvider":{"codeActionKinds":["quickfix","source.organizeImports"],"workDoneProgress":true},"executeCommandProvider":{"commands":[],"workDoneProgress":true},"callHierarchyProvider":true}}}
2022-03-31T10:04:28.672 helix_lsp::transport [INFO] <- {"capabilities":{"callHierarchyProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","source.organizeImports"],"workDoneProgress":true},"completionProvider":{"resolveProvider":true,"triggerCharacters":[".","["],"workDoneProgress":true},"declarationProvider":{"workDoneProgress":true},"definitionProvider":{"workDoneProgress":true},"documentHighlightProvider":{"workDoneProgress":true},"documentSymbolProvider":{"workDoneProgress":true},"executeCommandProvider":{"commands":[],"workDoneProgress":true},"hoverProvider":{"workDoneProgress":true},"referencesProvider":{"workDoneProgress":true},"renameProvider":{"prepareProvider":true,"workDoneProgress":true},"signatureHelpProvider":{"triggerCharacters":["(",",",")"],"workDoneProgress":true},"textDocumentSync":2,"typeDefinitionProvider":{"workDoneProgress":true},"workspaceSymbolProvider":{"workDoneProgress":true}}}
2022-03-31T10:04:28.672 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialized","params":{}}
2022-03-31T10:04:28.672 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":"{\n  \"python\": {\n    \"analysis\": {\n      \"autoSearchPaths\": true,\n      \"diagnosticMode\": \"workspace\",\n      \"useLibraryCodeForTypes\": true\n    }\n  }\n}\n"}}
2022-03-31T10:04:28.672 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"python","text":"","uri":"file:///home/me/work/code/project/project/causes/models.py","version":0}}}
2022-03-31T10:04:28.679 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":0,"method":"workspace/configuration","params":{"items":[{"scopeUri":"","section":"python"}]}}
2022-03-31T10:04:28.680 mio::poll [TRACE] deregistering event source from poller
2022-03-31T10:04:28.681 mio::poll [TRACE] deregistering event source from poller
2022-03-31T10:04:28.681 mio::poll [TRACE] deregistering event source from poller
2022-03-31T10:04:28.681 mio::poll [TRACE] deregistering event source from poller
2022-03-31T10:04:28.681 mio::poll [TRACE] deregistering event source from poller

config.toml:

[[language]]
name = "python"
language-server = { command = "pyright-langserver", args = ["--stdio"] }
auto-format = false
config = """
{
  "python": {
    "analysis": {
      "autoSearchPaths": true,
      "diagnosticMode": "workspace",
      "useLibraryCodeForTypes": true
    }
  }
}
"""

Platform

Linux arch

Terminal Emulator

foot 1.11.0

Helix Version

helix 22.03 (d4e45fd4)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 3
  • Comments: 29 (20 by maintainers)

Commits related to this issue

Most upvoted comments

this is my config for pyright , it’s work for me.

[[language]]
name = "python"
file-types = ["py", "pyi"]
roots = ["pyproject.toml","pyrightconfig.json"]
language-server = { command = "pyright-langserver", args = ["--stdio"] }
# config = { "analysis" = { "autoSearchPaths" = true, "diagnosticMode" = "workspace", "useLibraryCodeForTypes" = true } }
# or
config = {}

I don’t kown why that just have config = {} or config have any value , pyright can be run.

I’m using the latest main branch (helix 23.05 (57e538d0)). Pyright settings in languages.toml don’t work. It does work using pyproject.toml and pyrightconfig.json.

If I create a directory foo containing run.py (below), and call either hx foo or hx foo/run.py, I am able to control pyright configs from a foo/pyrightconfig.json. I can also do this with pyproject.toml. If pyrightconfig.json exists, no settings in pyproject.toml take effect. Edit: This behavior is all the pyright server, I can tell that from the logs.

I am not able to control the settings from languages.toml at all. Edit: The logs tell me that the settings are being sent, at least. Log at the end of this post.

Here’s a dummy run.py file to test if the configs take effect

# run.py
import library_that_doesnt_exist # raises a reportMissingImports error
a: str = 42 # should raise a type error when typeCheckingMode is `"basic"` or `"strict"`, not if its `"off"`

Here’s the languages.toml I’ve tried.

[[language]]
name = "python"
scope = "source.python"
injection-regex = "python"
file-types = ["py","pyi","py3","pyw",".pythonstartup",".pythonrc"]
shebangs = ["python"]
roots = ["pyproject.toml", "pyrightconfig.json", "."]
comment-token = "#"
language-servers = [ "pyright" ]
indent = { tab-width = 4, unit = "    " }

[language-server.pyright]
command = "pyright-langserver"
args = ["--stdio"]
# config = {} 

# The following title with values commented out is equivalent to `config = {}` above.
[language-server.pyright.config]
typeCheckingMode = "off"
reportMissingImports = false

# I don't think this one should work, but I tested it anyway
# [language-server.pyright.config.analysis]
# typeCheckingMode = "off"
# reportMissingImports = false

This is the pyproject.toml I’ve tried:

[tool.pyright]
# typeCheckingMode = "off"
reportMissingImports = "none"

and the pyrightconfig.json:

{
  "typeCheckingMode": "off"
}

I’d appreciate anyone else’s input on this!

  • Log showing that typeCheckingMode: "off" is being sent: 2023-07-06T15:31:16.987 helix_lsp::transport [INFO] pyright -> {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"typeCheckingMode":"off"}}} (I triggered the verbose logging with hx --vvv run.py, then opened the log with :log-open, then turned on soft wrap with :set soft-wrap.enable true)

Just tried it, it doesn’t work. I tried copy-pasting different configs I found on the internet, nothing works

Is it even possible to configure pyright? In my languages.toml I have:

[[language]]
name = "python"
language-server = { command = "pyright-langserver", args = ["--stdio"] }
config = """
{
  "python": {
    "analisys": {
      "autoSearchPaths": true, 
      "diagnosticMode": "workspace",
      "useLibraryCodeForTypes": true,
      "typeCheckingMode": "off"
    }
  }
}
"""

I just want to turn off type checking. But it doesn’t do anything. No matter what I put in config property is doesn’t do anything, and without it it doesn’t work.

@schneiderfelipe, the following config makes pyright type check in strict mode:

[language-server.pyright]
command = "pyright-langserver"
args = ["--stdio"]

[language-server.pyright.config.python.analysis]
typeCheckingMode = "strict"
image

Figured it out from looking at some vim setups: You have to specify the full pyright.config.python.analysis path in the config: 😅

[language-server.pyright.config.python.analysis]
typeCheckingMode = "off"

Concur with above, on Helix 22.12 pyright-langserver is nonfunctional even with the empty config section. Have tried a bunch of configs with no success.

Using @the-mikedavis’s config (pyright==1.1.293):

2023-02-09T23:54:52.784 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","result":[null],"id":1}
2023-02-09T23:54:52.785 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Starting service instance \"<default>\""}}
2023-02-09T23:54:52.785 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":2,"method":"workspace/configuration","params":{"items":[{"scopeUri":"","section":"python"}]}}
2023-02-09T23:54:52.785 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "Starting service instance \"<default>\"" }
2023-02-09T23:54:52.785 helix_term::application [ERROR] received malformed method call from Language Server: workspace/configuration: protocol error: InvalidParams: Invalid params: invalid value: string "", expected relative URL without a base.

Related: https://github.com/microsoft/pyright/discussions/4602

@HarshilPatel007

I have the same crash. I think I managed to work around it with the following config. Basically setting the current directory “.” as one of the roots. I’m not sure how this behaves, but I’m hoping it falls back to using the current directory as the root if it can’t find any of the other files listed. This is useful for when creating one-off scripts and the like.

Note there is also the chance that I’ve made it so that it always uses the current directory, I don’t really understand the priority of the values listed after roots.

[[language]]
name = "python"
roots = ["pyproject.toml", "setup.py", "Poetry.lock", "."]
language-server = { command = "pyright-langserver", args = ["--stdio"] }
auto-format = false
config = {}

Yeah, we mention it in the installation docs.

https://aur.archlinux.org/packages/helix-git