languages/lua: add luacheck and stylua support (#763)
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions

* Add lint(luacheck), format(stylua) support for lua

* fix comments for PR#763

* Update rl-0.8.md

---------

Co-authored-by: raf <raf@notashelf.dev>
This commit is contained in:
Venkatesan Ravi 2025-03-30 20:07:18 -07:00 committed by GitHub
parent fa7fb83315
commit b92d9e7e26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 69 additions and 2 deletions

View file

@ -284,6 +284,10 @@
- Add F# support under `vim.languages.fsharp`.
[venkyr77](https://github.com/venkyr77):
- Add lint (luacheck) and formatting (stylua) support for Lua.
[tebuevd](https://github.com/tebuevd):
- Fix `pickers` configuration for `telescope` by nesting it under `setupOpts`

View file

@ -4,16 +4,30 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
inherit (lib.lists) isList;
inherit (lib.types) either listOf package str;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.types) bool either enum listOf package str;
inherit (lib.nvim.types) diagnostics mkGrammarOption;
inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.dag) entryBefore;
cfg = config.vim.languages.lua;
defaultFormat = "stylua";
formats = {
stylua = {
package = pkgs.stylua;
};
};
defaultDiagnosticsProvider = ["luacheck"];
diagnosticsProviders = {
luacheck = {
package = pkgs.luajitPackages.luacheck;
};
};
in {
imports = [
(lib.mkRemovedOptionModule ["vim" "languages" "lua" "lsp" "neodev"] ''
@ -39,6 +53,34 @@ in {
lazydev.enable = mkEnableOption "lazydev.nvim integration, useful for neovim plugin developers";
};
format = {
enable = mkOption {
type = bool;
default = config.vim.languages.enableFormat;
description = "Enable Lua formatting";
};
type = mkOption {
type = enum (attrNames formats);
default = defaultFormat;
description = "Lua formatter to use";
};
package = mkOption {
type = package;
default = formats.${cfg.format.type}.package;
description = "Lua formatter package";
};
};
extraDiagnostics = {
enable = mkEnableOption "extra Lua diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
types = diagnostics {
langDesc = "Lua";
inherit diagnosticsProviders;
inherit defaultDiagnosticsProvider;
};
};
};
config = mkMerge [
@ -74,6 +116,27 @@ in {
})
'';
})
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts.formatters_by_ft.lua = [cfg.format.type];
setupOpts.formatters.${cfg.format.type} = {
command = getExe cfg.format.package;
};
};
})
(mkIf cfg.extraDiagnostics.enable {
vim.diagnostics.nvim-lint = {
enable = true;
linters_by_ft.lua = cfg.extraDiagnostics.types;
linters = mkMerge (map (name: {
${name}.cmd = getExe diagnosticsProviders.${name}.package;
})
cfg.extraDiagnostics.types);
};
})
]))
];
}