feat: add neodev plugin

This commit is contained in:
Ching Pei Yang 2023-09-23 15:36:26 +02:00
parent bdebf01a67
commit 456295b46e
5 changed files with 59 additions and 38 deletions

View file

@ -762,6 +762,22 @@
"type": "github" "type": "github"
} }
}, },
"neodev-nvim": {
"flake": false,
"locked": {
"lastModified": 1695449121,
"narHash": "sha256-WisbNLKEz0IgO7gLDA2quNzK69hJaHzmvWkZSUPQb6k=",
"owner": "folke",
"repo": "neodev.nvim",
"rev": "c8e126393a34939fb448d48eeddb510971739e3a",
"type": "github"
},
"original": {
"owner": "folke",
"repo": "neodev.nvim",
"type": "github"
}
},
"nil": { "nil": {
"inputs": { "inputs": {
"flake-utils": [ "flake-utils": [
@ -1445,6 +1461,7 @@
"mind-nvim": "mind-nvim", "mind-nvim": "mind-nvim",
"minimap-vim": "minimap-vim", "minimap-vim": "minimap-vim",
"modes-nvim": "modes-nvim", "modes-nvim": "modes-nvim",
"neodev-nvim": "neodev-nvim",
"nil": "nil", "nil": "nil",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nmd": "nmd", "nmd": "nmd",

View file

@ -133,6 +133,11 @@
flake = false; flake = false;
}; };
neodev-nvim = {
url = "github:folke/neodev.nvim";
flake = false;
};
elixir-ls = { elixir-ls = {
url = "github:elixir-lsp/elixir-ls"; url = "github:elixir-lsp/elixir-ls";
flake = false; flake = false;

View file

@ -80,6 +80,7 @@ with lib; let
"vim-repeat" "vim-repeat"
"smartcolumn" "smartcolumn"
"project-nvim" "project-nvim"
"neodev-nvim"
"elixir-ls" "elixir-ls"
"elixir-tools" "elixir-tools"
"nvim-colorizer-lua" "nvim-colorizer-lua"

View file

@ -24,6 +24,7 @@ in {
./html.nix ./html.nix
./svelte.nix ./svelte.nix
./java.nix ./java.nix
./lua.nix
]; ];
options.vim.languages = { options.vim.languages = {

View file

@ -6,16 +6,40 @@
}: }:
with lib; with lib;
with builtins; let with builtins; let
cfg = config.vim.languages.go; cfg = config.vim.languages.lua;
in {
options.vim.languages.lua = {
enable = mkEnableOption "Lua language support";
treesitter = {
enable = mkEnableOption "Enable Lua Treesitter support" // {default = config.vim.languages.enableTreesitter;};
package = nvim.types.mkGrammarOption pkgs "lua";
};
lsp = {
enable = mkEnableOption "Enable Lua LSP support via LuaLS" // {default = config.vim.languages.enableLSP;};
defaultServer = "lua-ls"; package = mkOption {
servers = { description = "LuaLS package, or the command to run as a list of strings";
lua-ls = { type = with types; either package (listOf str);
package = pkgs.lua-language-server; default = pkgs.lua-language-server;
lspConfig = '' };
neodev.enable = mkEnableOption "Enable neodev.nvim integration";
};
};
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.lua-lsp = ''
lspconfig.lua_ls.setup { lspconfig.lua_ls.setup {
capabilities = capabilities; capabilities = capabilities;
on_attach = default_on_attach; on_attach = default_on_attach;
${optionalString cfg.lsp.neodev.enable "before_init = require('neodev.lsp').before_init;"}
cmd = ${ cmd = ${
if isList cfg.lsp.package if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package then nvim.lua.expToLua cfg.lsp.package
@ -23,40 +47,13 @@ with builtins; let
}; };
} }
''; '';
};
};
in {
options.vim.languages.lua = {
treesitter = {
enable = mkOption "Enable Lua Treesitter support" // {default = config.vim.languages.enableTreesitter;};
package = nvim.types.mkGrammarOption pkgs "lua";
};
lsp = {
enable = mkOption "Enable Lua LSP support" // {default = config.vim.languages.enableLSP;};
server = mkOption {
description = "Lua LSP server to use";
type = with types; enum (attrNames servers);
default = defaultServer;
};
package = mkOption {
description = "Lua LSP server package, or the command to run as a list of strings";
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.lua-lsp = servers.${cfg.lsp.server}.lspConfig;
}) })
(mkIf cfg.treesitter.enable { (mkIf cfg.lsp.neodev.enable {
vim.treesitter.enable = true; vim.startPlugins = ["neodev-nvim"];
vim.treesitter.grammars = [cfg.treesitter.package]; vim.luaConfigRC.neodev = nvim.dag.entryBefore ["lua-lsp"] ''
require("neodev").setup({})
'';
}) })
]); ]);
} }