-
-
Notifications
You must be signed in to change notification settings - Fork 189
languages/python: add ruff as lsp #575
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
base: main
Are you sure you want to change the base?
Conversation
visuals/rainbow-delimiters: init
NotAShelf
left a comment
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.
Requested changes to remain consistent with the rest of the codebase, and to conform to our code styles.
To be honest, I don't quite like how this is handled. Not to say I can think of anything better at the moment, but this is entirely different from other language modules and might cause confusion.
I'll probably merge this after the requested changes are implemented, but I think a cleanup is due in the language module.
docs/release-notes/rl-0.8.md
Outdated
|
|
||
| [QuiNzX](https://github.com/QuiNzX): | ||
|
|
||
| [ruff lsp]: (https://github.com/astral-sh/ruff) |
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.
This reference is not used anywhere. You can remove it if you do not intend to refer to it as [ruff lsp] inline
modules/plugins/languages/python.nix
Outdated
| example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]''; | ||
| type = either package (listOf str); | ||
| default = servers.${cfg.lsp.server}.package; | ||
| type = lib.types.attrsOf (either package (listOf str)); |
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.
Please don't access lib inline
| type = lib.types.attrsOf (either package (listOf str)); | |
| type = attrsOf (either package (listOf str)); |
where attrsOf is inherited from types in the top-level let in.
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.
Thanks for the feedback!
I've made the necessary changes. However I have yet to find a way to stay consistent with the rest of the codebase. I'm looking forward to the language module cleanup so that my diabolical change will be resolved.
modules/plugins/languages/python.nix
Outdated
| (mkIf cfg.lsp.enable { | ||
| vim.lsp.lspconfig.enable = true; | ||
| vim.lsp.lspconfig.sources.python-lsp = servers.${cfg.lsp.server}.lspConfig; | ||
| vim.lsp.lspconfig.sources = lib.genAttrs (lib.toList cfg.lsp.server) (name: servers.${name}.lspConfig); |
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.
Move toList from an inherit at the top.
02ee4cc to
bc978c4
Compare
|
Looking forward to this landing in some form or fashion! Using multiple LSPs (Ruff + something else) is very common in modern Python development and is the preferred workflow for tons of devs. |
|
Thanks @QuiNzX, I've just managed to get nvf setup for the first time. Really exciting to be able to migrate to a purely Nix based config. However without ruff + pyright (or pyerfly) support it's completely unusable for python development, so unfortunately I'm going to have to go back to my non Nix config for the moment. Is there an update on this PR? It seems to have stalled for quite a while now. Is there any chance of this getting merged soon, or is there a fundamental issue? Is there something we can do to help? @NotAShelf |
|
In case anyone else finds this and wonders what the current state is. At the time of writing the Support for I've managed to get Ruff + pyright (as well as pyrefly and ty) working by disabling the python module LSP option and using the lsp = {
enable = true;
inlayHints.enable = true;
formatOnSave = true;
lspkind.enable = true;
lightbulb.enable = true;
trouble.enable = true;
servers = {
"*" = {
root_markers = [".git"];
capabilities = {
textDocument = {
semanticTokens = {
multilineTokenSupport = true;
};
};
};
};
"typos_lsp" = {};
"ruff" = {
root_markers = [".git" "pyproject.toml" "setup.py"];
filetypes = ["python"];
};
"pyright" = {
root_markers = [".git" "pyproject.toml" "setup.py"];
filetypes = ["python"];
};
#"pyrefly" = {
# root_markers = [".git" "pyproject.toml" "setup.py"];
# filetypes = ["python"];
#};
#"ty" = {
# root_markers = [".git" "pyproject.toml" "setup.py"];
# filetypes = ["python"];
#};
};
mappings = {
previousDiagnostic = "[d";
nextDiagnostic = "]d";
};
};
# Disable the LSP option here as it conflicts with the above settings.
languages = {
enableFormat = true;
enableTreesitter = true;
enableExtraDiagnostics = true;
python = {
enable = true;
lsp.enable = false; # use `lsp.servers` instead
format.type = "ruff"; # default is black and conflicts with ruff
};
};
# Make sure the extra LSPs are installed - this is normally done in the language modules so you don't have to do it explicitly.
extraPackages = [pkgs.pyright pkgs.ruff pkgs.ty]; |
|
This is a little late, but we're currently working on multiple formatters & multiple LSPs via the language modules in the v0.8 branch, which is set to be released soon. If this PR can be rebased on v0.8, we should be able to merge it with minimal changes to follow the new API imposed in the language modules. Of course |
|
I'd really like this, but this PR seems stale. So I've opened up #1320 which uses the new multiple LSP servers option. Which means the manual version described above (#575 (comment)) is no longer required. |
In this PR I've added ruff as lsp.
Breaking change:
What has changed is that before
cfg.lsp.serverexpected a single value but now it expects a list.So that ruff can work in conjuction with basedpyright(or any other lsp) which is recommended according to the ruff docs.
I might going to add more granular options for the lsp if you like unless you have something else in mind that will do so. ruff lsp
This is my first nix pr so let me know if I made any mistakes!
EDIT: because of the
toListfunction the breaking change isn't the case anymore forcfg.lsp.server.Let me know if there is a better approach to it!
However the breaking change is still in the case of
python.lsp.packagewhich now requires each lsp server specified as an attribute set . On the bright side you can now set arguments for each lsp.Like so:
nix fmt).#nix(default package).#maximal.#docs-html(manual, must build)x86_64-linuxaarch64-linuxx86_64-darwinaarch64-darwin