nvim-lsp: create nvim LSP plugin

This commit is contained in:
Pedro Alves 2021-02-01 15:54:53 +00:00
parent 9c13cb407b
commit ba79ba0652
7 changed files with 134 additions and 4 deletions

View file

@ -49,6 +49,11 @@
}; };
plugins.gitgutter.enable = true; plugins.gitgutter.enable = true;
plugins.lsp = {
enable = true;
servers.clangd.enable = true;
};
}; };
}) })
]; ];

View file

@ -87,7 +87,7 @@ in
extraPlugins = mkOption { extraPlugins = mkOption {
type = with types; listOf (either package pluginWithConfigType); type = with types; listOf (either package pluginWithConfigType);
default = []; default = [ ];
description = "List of vim plugins to install."; description = "List of vim plugins to install.";
}; };
@ -110,7 +110,7 @@ in
extraPackages = mkOption { extraPackages = mkOption {
type = types.listOf types.package; type = types.listOf types.package;
default = []; default = [ ];
example = "[ pkgs.shfmt ]"; example = "[ pkgs.shfmt ]";
description = "Extra packages to be made available to neovim"; description = "Extra packages to be made available to neovim";
}; };
@ -128,7 +128,7 @@ in
globals = mkOption { globals = mkOption {
type = types.attrsOf types.anything; type = types.attrsOf types.anything;
default = {}; default = { };
description = "Global variables"; description = "Global variables";
}; };
@ -149,7 +149,7 @@ in
command = mapOptions "command-line"; command = mapOptions "command-line";
}; };
}; };
default = {}; default = { };
description = '' description = ''
Custom keybindings for any mode. Custom keybindings for any mode.

View file

@ -6,5 +6,7 @@
./statuslines/airline.nix ./statuslines/airline.nix
./git/gitgutter.nix ./git/gitgutter.nix
./nvim-lsp
]; ];
} }

View file

@ -0,0 +1,18 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.lsp.servers.clangd;
in
{
options = {
programs.nixvim.plugins.lsp.servers.clangd = {
enable = mkEnableOption "Enable clangd LSP, for C/C++.";
};
};
config = mkIf cfg.enable {
programs.nixvim.extraPackages = [ pkgs.clang-tools ];
programs.nixvim.plugins.lsp.enabledServers = [ "clangd" ];
};
}

View file

@ -0,0 +1,69 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.lsp;
helpers = (import ../helpers.nix { inherit lib; });
in
{
imports = [
./clangd.nix
./rust-analyzer.nix
./rnix-lsp.nix
];
options = {
programs.nixvim.plugins.lsp = {
enable = mkEnableOption "Enable neovim's built-in LSP";
enabledServers = mkOption {
type = with types; listOf (oneOf [str (submodule {
options = {
name = mkOption {
type = str;
description = "The server's name";
};
extraOptions = mkOption {
type = attrs;
description = "Extra options for the server";
};
};
})]);
description = "A list of enabled LSP servers. Don't use this directly.";
default = [];
};
onAttach = mkOption {
type = types.lines;
description = "A lua function to be run when a new LSP buffer is attached. The argument `client` is provided.";
default = "";
};
};
};
config = mkIf cfg.enable {
programs.nixvim = {
extraPlugins = [ pkgs.vimPlugins.nvim-lspconfig ];
# Enable all LSP servers
extraConfigLua = ''
-- LSP {{{
local __lspServers = ${helpers.toLuaObject cfg.enabledServers}
local __lspOnAttach = function(client)
${cfg.onAttach}
end
for i,server in ipairs(__lspServers) do
if type(server) == "string" then
require('lspconfig')[server].setup {
on_attach = __lspOnAttach
}
else
require('lspconfig')[server.name].setup(server.extraOptions)
end
end
-- }}}
'';
};
};
}

View file

@ -0,0 +1,18 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.lsp.servers.rnix-lsp;
in
{
options = {
programs.nixvim.plugins.lsp.servers.rnix-lsp = {
enable = mkEnableOption "Enable rnix LSP, for Nix";
};
};
config = mkIf cfg.enable {
programs.nixvim.extraPackages = [ pkgs.rnix-lsp ];
programs.nixvim.lsp.plugins.enabledServers = [ "rnix" ];
};
}

View file

@ -0,0 +1,18 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.lsp.servers.rust-analyzer;
in
{
options = {
programs.nixvim.plugins.lsp.servers.rust-analyzer = {
enable = mkEnableOption "Enable rust-analyzer, for Rust.";
};
};
config = mkIf cfg.enable {
programs.nixvim.extraPackages = [ pkgs.rust-analyzer ];
programs.nixvim.plugins.lsp.enabledServers = [ "rust_analyzer" ];
};
}