Compare commits

..

No commits in common. "ea3ee477fa1814352b30d114f31bf4895eed053e" and "3e48f13c3ce8372d00be2e27f313f2ed8da5bc82" have entirely different histories.

3 changed files with 32 additions and 56 deletions

View file

@ -115,9 +115,6 @@
- Add [hunk.nvim], Neovim plugin & tool for splitting diffs in Neovim. Available
as `vim.git.hunk-nvim`
- Move `crates.nvim` into `languages.rust.extensions and support` `setupOpts`
for the plugin. Deprecates the top level "crates" option in `languages.rust`.
[sjcobb2022](https://github.com/sjcobb2022):
- Migrate all current lsp configurations to `vim.lsp.server` and remove internal
@ -304,7 +301,6 @@
`helmfile`s when both are enabled.
- Fix YAML language module not activating LSP keybinds if the Helm language
module was also enabled.
- Fix `json` language module (default) language server not activating.
[TheColorman](https://github.com/TheColorman):

View file

@ -17,7 +17,7 @@
defaultServers = ["jsonls"];
servers = {
jsonls = {
cmd = [(getExe' pkgs.vscode-langservers-extracted "vscode-json-language-server") "--stdio"];
cmd = [(getExe' pkgs.vscode-langservers-extracted "vscode-json-languageserver") "--stdio"];
filetypes = ["json" "jsonc"];
init_options = {provideFormatter = true;};
root_markers = [".git"];

View file

@ -4,15 +4,16 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.meta) getExe;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.options) mkOption mkEnableOption literalMD;
inherit (lib.strings) optionalString;
inherit (lib.trivial) boolToString;
inherit (lib.lists) isList;
inherit (lib.attrsets) attrNames;
inherit (lib.types) bool package str listOf either enum;
inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption;
inherit (lib.nvim.lua) expToLua toLuaObject;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryAfter entryAnywhere;
cfg = config.vim.languages.rust;
@ -32,6 +33,15 @@ 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.lsp.enable;};
package = mkOption {
@ -93,32 +103,25 @@ in {
default = pkgs.lldb;
};
};
extensions = {
crates-nvim = {
enable = mkEnableOption "crates.io dependency management [crates-nvim]";
setupOpts = mkPluginSetupOption "crates-nvim" {
completion.enable = mkOption {
type = bool;
default = config.vim.autocomplete.nvim-cmp.enable;
defaultText = "{option}`config.vim.autocomplete.nvim-cmp.enable`";
description = ''
Whether to add crates.nvim as a source for completion plugins. The following
plugins are supported by crates.nvim:
* nvim-cmp
* coq.nvim
However nvf only supports auto-setup for nvim-cmp.
'';
};
};
};
};
};
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];
@ -137,6 +140,7 @@ in {
(mkIf (cfg.lsp.enable || cfg.dap.enable) {
vim = {
startPlugins = ["rustaceanvim"];
pluginRC.rustaceanvim = entryAfter ["lsp-setup"] ''
vim.g.rustaceanvim = {
${optionalString cfg.lsp.enable ''
@ -149,14 +153,13 @@ 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 = {
${cfg.lsp.opts}
},
on_attach = function(client, bufnr)
default_on_attach(client, bufnr)
local opts = { noremap=true, silent=true, buffer = bufnr }
vim.keymap.set("n", "<localleader>rr", ":RustLsp runnables<CR>", opts)
vim.keymap.set("n", "<localleader>rp", ":RustLsp parentModule<CR>", opts)
@ -195,28 +198,5 @@ in {
'';
};
})
(mkIf cfg.extensions.crates-nvim.enable {
vim = let
withCompletion = cfg.extensions.crates-nvim.withCmpSource;
in
mkMerge [
{
startPlugins = ["crates-nvim"];
pluginRC.rust-crates = entryAnywhere ''
require("crates").setup(${toLuaObject cfg.extensions.crates-nvim.setupOpts})
'';
}
# FIXME: this will not be necessary once crates.nvim creates a new release that
# ships improvements to the in-progress LSP module. If updating > 0.7.1, remember
# to update this section.
# See:
# <https://github.com/saecki/crates.nvim/wiki/Documentation-unstable#auto-completion>
(mkIf withCompletion {
autocomplete.nvim-cmp.sources = {crates = "[Crates]";};
})
];
})
]);
}