-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add pylsp as the python LSP #857
Conversation
Generated the module via `flatpak-pip-generator` on my host with python 3.12. When building with this module, it complains about the package `maturin` missing. I suspect, that it is missing due to the difference in python versions.
It is not working as intendet and we decided to use pylsp instead.
LSPs, who exit early, trigger a lot of errors, because they do not send any headers. This patch fixes the access of undefined headers to prevent runtime exceptions. Furthermore, it adds a timeout to not overwhelm the garbage collection sweeping phase of GTK and adds debug output for non-JSON LSP responses.
To not slow down the diagnoses, the LSPClient, should only wait for GC, if it doesn't do any message processing.
As decided, this commit changes the executed LSP to pyslp and adds the missing code to it up. Furthermore, it adds a missing return in the LSP's setup function, which doesn't seem to have triggered any issues, yet. Although, a locally installed version of pylsp, initializes, it doesn't yet work, because it quit's after sending it's firsts message.
This change packages pylsp as a flatpak module, so it can be included in the flatpak.
I just forgot this before.
Run eslint on python.js and fix formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start thanks!
I rebased and pushed - makes sure to pull my changes.
I'm observing the same result as you - no diagnostics.
From the logs it looks like modules are missing and that is why the plugins are disabled ?
2024-02-13 21:32:51,864 CET - INFO - pylsp.python_lsp - Starting PythonLSPServer IO language server
2024-02-13 21:32:51,877 CET - INFO - pylsp.config.config - Failed to load pylsp entry point 'autopep8': No module named 'pycodestyle'
2024-02-13 21:32:51,888 CET - INFO - pylsp.config.config - Failed to load pylsp entry point 'mccabe': No module named 'mccabe'
2024-02-13 21:32:51,889 CET - INFO - pylsp.config.config - Failed to load pylsp entry point 'pycodestyle': No module named 'pycodestyle'
2024-02-13 21:32:51,890 CET - INFO - pylsp.config.config - Failed to load pylsp entry point 'pydocstyle': No module named 'pydocstyle'
2024-02-13 21:32:51,891 CET - INFO - pylsp.config.config - Failed to load pylsp entry point 'pyflakes': No module named 'pyflakes'
2024-02-13 21:32:51,893 CET - INFO - pylsp.config.config - Failed to load pylsp entry point 'rope_autoimport': No module named 'rope'
2024-02-13 21:32:51,894 CET - INFO - pylsp.config.config - Failed to load pylsp entry point 'rope_completion': No module named 'rope'
2024-02-13 21:32:51,895 CET - INFO - pylsp.config.config - Failed to load pylsp entry point 'rope_rename': No module named 'rope'
2024-02-13 21:32:51,895 CET - INFO - pylsp.config.config - Failed to load pylsp entry point 'yapf': No module named 'yapf'
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin flake8 from <module 'pylsp.plugins.flake8_lint' from '/app/lib/python3.11/site-packages/pylsp/plugins/flake8_lint.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin folding from <module 'pylsp.plugins.folding' from '/app/lib/python3.11/site-packages/pylsp/plugins/folding.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin jedi_completion from <module 'pylsp.plugins.jedi_completion' from '/app/lib/python3.11/site-packages/pylsp/plugins/jedi_completion.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin jedi_definition from <module 'pylsp.plugins.definition' from '/app/lib/python3.11/site-packages/pylsp/plugins/definition.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin jedi_highlight from <module 'pylsp.plugins.highlight' from '/app/lib/python3.11/site-packages/pylsp/plugins/highlight.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin jedi_hover from <module 'pylsp.plugins.hover' from '/app/lib/python3.11/site-packages/pylsp/plugins/hover.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin jedi_references from <module 'pylsp.plugins.references' from '/app/lib/python3.11/site-packages/pylsp/plugins/references.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin jedi_rename from <module 'pylsp.plugins.jedi_rename' from '/app/lib/python3.11/site-packages/pylsp/plugins/jedi_rename.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin jedi_signature_help from <module 'pylsp.plugins.signature' from '/app/lib/python3.11/site-packages/pylsp/plugins/signature.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin jedi_symbols from <module 'pylsp.plugins.symbols' from '/app/lib/python3.11/site-packages/pylsp/plugins/symbols.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin preload from <module 'pylsp.plugins.preload_imports' from '/app/lib/python3.11/site-packages/pylsp/plugins/preload_imports.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Loaded pylsp plugin pylint from <module 'pylsp.plugins.pylint_lint' from '/app/lib/python3.11/site-packages/pylsp/plugins/pylint_lint.py'>
2024-02-13 21:32:51,898 CET - INFO - pylsp.config.config - Disabled plugins: [<module 'pylsp.plugins.flake8_lint' from '/app/lib/python3.11/site-packages/pylsp/plugins/flake8_lint.py'>, <module 'pylsp.plugins.pylint_lint' from '/app/lib/python3.11/site-packages/pylsp/plugins/pylint_lint.py'>]
2024-02-13 21:32:51,902 CET - INFO - pylsp.python_lsp - Server capabilities: {'codeActionProvider': True, 'codeLensProvider': {'resolveProvider': False}, 'completionProvider': {'resolveProvider': True, 'triggerCharacters': ['.']}, 'documentFormattingProvider': True, 'documentHighlightProvider': True, 'documentRangeFormattingProvider': True, 'documentSymbolProvider': True, 'definitionProvider': True, 'executeCommandProvider': {'commands': []}, 'hoverProvider': True, 'referencesProvider': True, 'renameProvider': True, 'foldingRangeProvider': True, 'signatureHelpProvider': {'triggerCharacters': ['(', ',', '=']}, 'textDocumentSync': {'change': 2, 'save': {'includeText': True}, 'openClose': True}, 'notebookDocumentSync': {'notebookSelector': [{'cells': [{'language': 'python'}]}]}, 'workspace': {'workspaceFolders': {'supported': True, 'changeNotifications': True}}, 'experimental': {}}
Which capabilities do we want? From the README:
My concern is that this seems to use other tools for code formatting than we currently use. I think the idea is to combine it with python-lsp:
So should we for now only install Rope for completions and add Ruff to replace Black in a new PR where we would also add ruff-lsp? |
I guess Workbench currently doesn't use completions. I'll still add Rope in case we want that in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me this looks good for now! See my comments above for questions on how to extend this.
Since I had time, I started creating a possible follow-up PR that would add Ruff: #902 |
I removed rope again for now, since we don't support completions anyway yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome team work!
@janvhs thanks for doing the heavy lifting, feel free to add yourself to contributors in about.js
const lspc = createLSPClient({ | ||
lang: getLanguage("python"), | ||
root_uri: file.get_parent().get_uri(), | ||
quiet: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quiet: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theCapypara if you debug while working on LSP, make sure to use this flag to see stdout
@theCapypara thanks for moving it forward! ^^ @sonnyp I'm glad to do so :) |
This commit adds my name to the contributor list for #857 Thanks so much for the patience and help I received from you @sonnyp @theCapypara
Co-authored-by: Sonny Piers <[email protected]> Co-authored-by: Marco Capypara Köpcke <[email protected]>
This commit adds my name to the contributor list for #857 Thanks so much for the patience and help I received from you @sonnyp @theCapypara
This PR, lays the foundation to introduce an LSP for the python language.
Pylsp is packaged as a flatpak module and included in the build tree for the Devel version of Workbench.
Currently, pylsp responds to file input changing, but doesn't publish any diagnostics and I can not figure out why.
It seems to support the same capabilities as the JS client, yet only responds with empty diagnostics on the
notification::textDocument/publishDiagnostics
event.Another thing, that raised my attention, is the usage of booth
python
andpython3
, when referencing to the language ID throughout the codebase. I don't think it is part of the problem, tho.Can someone take a look at this and help to figure out, why it does not work?