Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylsp never gets configured #655

Closed
clarfonthey opened this issue Dec 4, 2022 · 7 comments
Closed

pylsp never gets configured #655

clarfonthey opened this issue Dec 4, 2022 · 7 comments

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Dec 4, 2022

So, I've read the logs for my own runs of pylsp, and I poked around on the issues for both pylsp and kak-lsp, and found this conundrum.

pylsp doesn't want to use initializationOptions, since per their comments, it's not very standardized: python-lsp/python-lsp-server#195

But from everything I can see, and my own local tests, kak-lsp doesn't send workspace/configuration unless requested, which pylsp never does. It would be nice to be able to ensure that the configuration is also sent via this, at least maybe via a config option.

Essentially, from everything I can see, pylsp isn't loading the configuration from kak-lsp since it ignores the initialization options and kak-lsp doesn't send a separate workspace/configuration message.

When I check the logs, I see calls for textDocument/didOpen, textDocument/codeLens, and initialized sent to the server, but no workspace/configuration.

@krobelus
Copy link
Member

krobelus commented Dec 4, 2022

But from everything I can see, and my own local tests, kak-lsp doesn't send workspace/configuration unless requested, which pylsp never does.

This is expected behavior, the spec says

The workspace/configuration request is sent from the server to the client to fetch configuration settings from the client.

so we should not send this unless we're asked to.

pylsp configuration actually works fine, because we send workspace/didChangeConfiguration which essentially has the same information. This must be a problem in your configuration.

@krobelus
Copy link
Member

krobelus commented Dec 4, 2022

Here's how I confirmed it works:

  1. create this python file
def foo():
    if 1:
        if 1:
            if 1:
                if 1:
                    if 1:
                        if 1:
                            if 1:
                                pass
                            else:
                                pass
                        else:
                            pass
                    else:
                        pass
                else:
                    pass
            else:
                pass
        else:
            pass
    else:
        pass
    if 1:
        if 1:
            if 1:
                if 1:
                    if 1:
                        if 1:
                            if 1:
                                pass
                            else:
                                pass
                        else:
                            pass
                    else:
                        pass
                else:
                    pass
            else:
                pass
        else:
            pass
    else:
        pass
  1. observe that by default pylsp will send a diagnostic (Cyclomatic complexity too high: 15 (threshold 15)).
    This should show up as ! in the gutter next to def foo

  2. create this tox.ini in the same dir as the python ile

[flake8]
max-complexity = 300
  1. use flake8 as config source, for example by using this config
[language.python]
filetypes = ["python"]
roots = ["requirements.txt", "setup.py", ".git", ".hg"]
command = "pylsp"
settings_section = "_"
[language.python.settings._]
# See https://github.com/python-lsp/python-lsp-server#configuration
pylsp.configurationSources = ["flake8"]
  1. observe that the diagnostic about cyclomatic complexity is no longer sent.

Logs should show that we send {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"pylsp":{"configurationSources":["flake8"]}}}} to the server.

@krobelus
Copy link
Member

krobelus commented Dec 4, 2022

if you see a panic in logs (search for ERRO) then upgrading would help if it's #654

@clarfonthey
Copy link
Contributor Author

clarfonthey commented Dec 4, 2022

So, I saw #654 and thought it was totally separate to my case, but it might be. I thought I looked for errors in the log but this ERRO was sneaky:

Dec 04 06:58:58.451 ERRO Failed to parse header, module: kak_lsp::language_server_transport:79

Will use latest commit and see if that fixes it. Until then, here's the current log I have: .kak-lsp.log

Also kak-lsp.toml (the relevant section):

[language.python]
filetypes = ["python"]
roots = ["pyproject.toml", ".git"]
command = "poetry"
args = ["run", "pylsp", "--verbose", "--check-parent-process"]
settings_section = "pylsp"

[language.python.settings.pylsp.pylsp]
configurationSources = ["flake8"]

[language.python.settings.pylsp.pylsp.plugins]
autopep8.enabled = false
black.enabled = true
flake8.enabled = true
isort.enabled = true
mccabe.enabled = false
preload.enabled = true
pycodestyle.enabled = false
pydocstyle.enabled = true
pyflakes.enabled = false
pylint.enabled = true
rope.enabled = true
yapf.enabled = false

[language.python.settings.pylsp.pylsp.plugins.mypy]
enabled = true
live_mode = true
strict = false

@clarfonthey
Copy link
Contributor Author

Okay, the latest commit definitely adds in the didChangeConfiguration call, whereas the previous version I was on (14.1.0) didn't. Will let you decide if you want to keep this open or track this in the other issue, depending on whether you think they're sufficiently different. And attaching the new log:

.kak-lsp.log

@krobelus
Copy link
Member

krobelus commented Dec 4, 2022

"Language server error" means pylsp terminated due to an error. Your latest log says it can't find the flake8 module.
You explicitly asked for flake8, so that makes sense. You probably just need to install it.
I don't think there's a kak-lsp issue left here but LMK if otherwise

@clarfonthey
Copy link
Contributor Author

Yeah, I'll close this. Thanks for helping with the debug since I seem to just not be able to read logs. ><

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants