mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-30 12:24:28 +02:00
nvim-lsp: create nvim LSP plugin
This commit is contained in:
parent
9c13cb407b
commit
ba79ba0652
7 changed files with 134 additions and 4 deletions
|
@ -49,6 +49,11 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
plugins.gitgutter.enable = true;
|
plugins.gitgutter.enable = true;
|
||||||
|
|
||||||
|
plugins.lsp = {
|
||||||
|
enable = true;
|
||||||
|
servers.clangd.enable = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
|
@ -6,5 +6,7 @@
|
||||||
./statuslines/airline.nix
|
./statuslines/airline.nix
|
||||||
|
|
||||||
./git/gitgutter.nix
|
./git/gitgutter.nix
|
||||||
|
|
||||||
|
./nvim-lsp
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
18
plugins/nvim-lsp/clangd.nix
Normal file
18
plugins/nvim-lsp/clangd.nix
Normal 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" ];
|
||||||
|
};
|
||||||
|
}
|
69
plugins/nvim-lsp/default.nix
Normal file
69
plugins/nvim-lsp/default.nix
Normal 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
|
||||||
|
-- }}}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
18
plugins/nvim-lsp/rnix-lsp.nix
Normal file
18
plugins/nvim-lsp/rnix-lsp.nix
Normal 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" ];
|
||||||
|
};
|
||||||
|
}
|
18
plugins/nvim-lsp/rust-analyzer.nix
Normal file
18
plugins/nvim-lsp/rust-analyzer.nix
Normal 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" ];
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue