mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-04-13 16:18:36 +00:00
languages/rust: move crates-nvim setup to languages.rust.extensions
This commit is contained in:
parent
64fbc41f29
commit
205b464a26
1 changed files with 43 additions and 32 deletions
|
@ -4,17 +4,15 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) attrNames;
|
||||
inherit (builtins) isList attrNames;
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.modules) mkIf mkMerge mkRenamedOptionModule;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.trivial) boolToString;
|
||||
inherit (lib.lists) isList;
|
||||
inherit (lib.types) bool package str listOf either enum;
|
||||
inherit (lib.nvim.languages) lspOptions;
|
||||
inherit (lib.nvim.types) mkGrammarOption;
|
||||
inherit (lib.nvim.lua) expToLua;
|
||||
inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (lib.nvim.dag) entryAfter entryAnywhere;
|
||||
|
||||
cfg = config.vim.languages.rust;
|
||||
|
@ -26,6 +24,10 @@
|
|||
};
|
||||
};
|
||||
in {
|
||||
imports = [
|
||||
(mkRenamedOptionModule ["vim" "languages" "rust" "crates"] ["vim" "languages" "rust" "extensions" "crates-nvim"])
|
||||
];
|
||||
|
||||
options.vim.languages.rust = {
|
||||
enable = mkEnableOption "Rust language support";
|
||||
|
||||
|
@ -34,15 +36,6 @@ in {
|
|||
package = mkGrammarOption pkgs "rust";
|
||||
};
|
||||
|
||||
crates = {
|
||||
enable = mkEnableOption "crates-nvim, tools for managing dependencies";
|
||||
codeActions = mkOption {
|
||||
description = "Enable code actions through null-ls";
|
||||
type = bool;
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
|
||||
lsp = {
|
||||
enable = mkEnableOption "Rust LSP support (rust-analyzer with extra tools)" // {default = config.vim.languages.enableLSP;};
|
||||
package = mkOption {
|
||||
|
@ -97,25 +90,26 @@ in {
|
|||
default = pkgs.lldb;
|
||||
};
|
||||
};
|
||||
|
||||
extensions = {
|
||||
crates-nvim = {
|
||||
enable =
|
||||
mkEnableOption ""
|
||||
// {
|
||||
default = true;
|
||||
description = ''
|
||||
[crates.nvim]: https://github.com/Saecki/crates.nvim/
|
||||
|
||||
Helper plugin for managing crates.io dependencies [crates.nvim]
|
||||
'';
|
||||
};
|
||||
|
||||
setupOpts = mkPluginSetupOption "crates-nvim" {};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
(mkIf cfg.crates.enable {
|
||||
vim = {
|
||||
startPlugins = ["crates-nvim"];
|
||||
lsp.null-ls.enable = mkIf cfg.crates.codeActions true;
|
||||
autocomplete.nvim-cmp.sources = {crates = "[Crates]";};
|
||||
pluginRC.rust-crates = entryAnywhere ''
|
||||
require('crates').setup {
|
||||
null_ls = {
|
||||
enabled = ${boolToString cfg.crates.codeActions},
|
||||
name = "crates.nvim",
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
})
|
||||
|
||||
(mkIf cfg.treesitter.enable {
|
||||
vim.treesitter.enable = true;
|
||||
vim.treesitter.grammars = [cfg.treesitter.package];
|
||||
|
@ -147,7 +141,7 @@ in {
|
|||
server = {
|
||||
cmd = ${
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
then toLuaObject cfg.lsp.package
|
||||
else ''{"${cfg.lsp.package}/bin/rust-analyzer"}''
|
||||
},
|
||||
default_settings = {
|
||||
|
@ -193,5 +187,22 @@ in {
|
|||
'';
|
||||
};
|
||||
})
|
||||
|
||||
# Extensions
|
||||
(mkIf cfg.extensions.crates.enable {
|
||||
vim = {
|
||||
startPlugins = ["crates-nvim"];
|
||||
autocomplete.nvim-cmp.sources = {crates = "[Crates]";};
|
||||
|
||||
pluginRC.rust-crates-nvim = entryAnywhere ''
|
||||
require('crates').setup {
|
||||
null_ls = {
|
||||
enabled = ${boolToString cfg.crates.codeActions},
|
||||
name = "crates.nvim",
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue