diff --git a/flake.nix b/flake.nix index 25d0e487..b98de1a5 100644 --- a/flake.nix +++ b/flake.nix @@ -49,6 +49,11 @@ }; plugins.gitgutter.enable = true; + + plugins.lsp = { + enable = true; + servers.clangd.enable = true; + }; }; }) ]; diff --git a/nixvim.nix b/nixvim.nix index 5241426f..5e3cc823 100644 --- a/nixvim.nix +++ b/nixvim.nix @@ -87,7 +87,7 @@ in extraPlugins = mkOption { type = with types; listOf (either package pluginWithConfigType); - default = []; + default = [ ]; description = "List of vim plugins to install."; }; @@ -110,7 +110,7 @@ in extraPackages = mkOption { type = types.listOf types.package; - default = []; + default = [ ]; example = "[ pkgs.shfmt ]"; description = "Extra packages to be made available to neovim"; }; @@ -128,7 +128,7 @@ in globals = mkOption { type = types.attrsOf types.anything; - default = {}; + default = { }; description = "Global variables"; }; @@ -149,7 +149,7 @@ in command = mapOptions "command-line"; }; }; - default = {}; + default = { }; description = '' Custom keybindings for any mode. diff --git a/plugins/default.nix b/plugins/default.nix index a2704de7..6e188d09 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -6,5 +6,7 @@ ./statuslines/airline.nix ./git/gitgutter.nix + + ./nvim-lsp ]; } diff --git a/plugins/nvim-lsp/clangd.nix b/plugins/nvim-lsp/clangd.nix new file mode 100644 index 00000000..f363e416 --- /dev/null +++ b/plugins/nvim-lsp/clangd.nix @@ -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" ]; + }; +} diff --git a/plugins/nvim-lsp/default.nix b/plugins/nvim-lsp/default.nix new file mode 100644 index 00000000..f3476403 --- /dev/null +++ b/plugins/nvim-lsp/default.nix @@ -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 + -- }}} + ''; + }; + }; +} diff --git a/plugins/nvim-lsp/rnix-lsp.nix b/plugins/nvim-lsp/rnix-lsp.nix new file mode 100644 index 00000000..a7c37e13 --- /dev/null +++ b/plugins/nvim-lsp/rnix-lsp.nix @@ -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" ]; + }; +} diff --git a/plugins/nvim-lsp/rust-analyzer.nix b/plugins/nvim-lsp/rust-analyzer.nix new file mode 100644 index 00000000..c55f7a48 --- /dev/null +++ b/plugins/nvim-lsp/rust-analyzer.nix @@ -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" ]; + }; +}