mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-22 13:20:44 +00:00
languages/rust: add format
This commit is contained in:
parent
923481640e
commit
8a0cddd9bb
2 changed files with 40 additions and 1 deletions
|
@ -53,3 +53,5 @@ Release notes for release 0.7
|
|||
[diniamo](https://github.com/diniamo):
|
||||
|
||||
- Move the `theme` dag entry to before `luaScript`.
|
||||
|
||||
- Add rustfmt as the default formatter for Rust
|
||||
|
|
|
@ -4,17 +4,33 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) attrNames;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.trivial) boolToString;
|
||||
inherit (lib.lists) isList optionals;
|
||||
inherit (lib.types) bool package str listOf either;
|
||||
inherit (lib.types) bool package str listOf either enum;
|
||||
inherit (lib.nvim.types) mkGrammarOption;
|
||||
inherit (lib.nvim.lua) expToLua;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.languages.rust;
|
||||
|
||||
defaultFormat = "rustfmt";
|
||||
formats = {
|
||||
rustfmt = {
|
||||
package = pkgs.rustfmt;
|
||||
nullConfig = ''
|
||||
table.insert(
|
||||
ls_sources,
|
||||
null_ls.builtins.formatting.rustfmt.with({
|
||||
command = "${cfg.format.package}/bin/rustfmt",
|
||||
})
|
||||
)
|
||||
'';
|
||||
};
|
||||
};
|
||||
in {
|
||||
options.vim.languages.rust = {
|
||||
enable = mkEnableOption "Rust language support";
|
||||
|
@ -49,6 +65,22 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
format = {
|
||||
enable = mkEnableOption "Rust formatting" // {default = config.vim.languages.enableFormat;};
|
||||
|
||||
type = mkOption {
|
||||
description = "Rust formatter to use";
|
||||
type = enum (attrNames formats);
|
||||
default = defaultFormat;
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
description = "Rust formatter package";
|
||||
type = package;
|
||||
default = formats.${cfg.format.type}.package;
|
||||
};
|
||||
};
|
||||
|
||||
dap = {
|
||||
enable = mkOption {
|
||||
description = "Rust Debug Adapter support";
|
||||
|
@ -86,6 +118,11 @@ in {
|
|||
vim.treesitter.grammars = [cfg.treesitter.package];
|
||||
})
|
||||
|
||||
(mkIf cfg.format.enable {
|
||||
vim.lsp.null-ls.enable = true;
|
||||
vim.lsp.null-ls.sources.rust-format = formats.${cfg.format.type}.nullConfig;
|
||||
})
|
||||
|
||||
(mkIf (cfg.lsp.enable || cfg.dap.enable) {
|
||||
vim = {
|
||||
startPlugins = ["rust-tools"] ++ optionals cfg.dap.enable [cfg.dap.package];
|
||||
|
|
Loading…
Reference in a new issue