mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-11-10 07:25:30 +00:00
feat: refactor and separate LSP/language configurations
This commit is contained in:
parent
7a71f06763
commit
6b512f132a
30 changed files with 1266 additions and 522 deletions
71
modules/languages/go.nix
Normal file
71
modules/languages/go.nix
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
with builtins; let
|
||||
cfg = config.vim.languages.go;
|
||||
|
||||
defaultServer = "gopls";
|
||||
servers = {
|
||||
gopls = {
|
||||
package = pkgs.gopls;
|
||||
lspConfig = ''
|
||||
lspconfig.gopls.setup {
|
||||
capabilities = capabilities;
|
||||
on_attach = default_on_attach;
|
||||
cmd = {"${cfg.lsp.package}/bin/gopls", "serve"},
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
in {
|
||||
options.vim.languages.go = {
|
||||
enable = mkEnableOption "Go language support";
|
||||
|
||||
treesitter = {
|
||||
enable = mkOption {
|
||||
description = "Enable Go treesitter";
|
||||
type = types.bool;
|
||||
default = config.vim.languages.enableTreesitter;
|
||||
};
|
||||
package = mkOption {
|
||||
description = "Go treesitter grammar to use";
|
||||
type = types.package;
|
||||
default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.go;
|
||||
};
|
||||
};
|
||||
|
||||
lsp = {
|
||||
enable = mkOption {
|
||||
description = "Enable Go LSP support";
|
||||
type = types.bool;
|
||||
default = config.vim.languages.enableLSP;
|
||||
};
|
||||
server = mkOption {
|
||||
description = "Go LSP server to use";
|
||||
type = with types; enum (attrNames servers);
|
||||
default = defaultServer;
|
||||
};
|
||||
package = mkOption {
|
||||
description = "Go LSP server package";
|
||||
type = types.package;
|
||||
default = servers.${cfg.lsp.server}.package;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
(mkIf cfg.treesitter.enable {
|
||||
vim.treesitter.enable = true;
|
||||
vim.treesitter.grammars = [cfg.treesitter.package];
|
||||
})
|
||||
|
||||
(mkIf cfg.lsp.enable {
|
||||
vim.lsp.lspconfig.enable = true;
|
||||
vim.lsp.lspconfig.sources.go-lsp = servers.${cfg.lsp.server}.lspConfig;
|
||||
})
|
||||
]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue