diff --git a/docs/release-notes/rl-0.5.adoc b/docs/release-notes/rl-0.5.adoc index 31024f7..6e7b7db 100644 --- a/docs/release-notes/rl-0.5.adoc +++ b/docs/release-notes/rl-0.5.adoc @@ -16,6 +16,8 @@ https://github.com/horriblename[horriblename]: * Allow using command names in place of LSP packages to avoid automatic installation. +* Add lua LSP and treesitter support, and neodev.nvim plugin support. + https://github.com/amanse[amanse]: * Added daily notes options for obsidian plugin. diff --git a/flake.lock b/flake.lock index 6820ac4..f939c12 100644 --- a/flake.lock +++ b/flake.lock @@ -762,6 +762,22 @@ "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": { "inputs": { "flake-utils": [ @@ -1445,6 +1461,7 @@ "mind-nvim": "mind-nvim", "minimap-vim": "minimap-vim", "modes-nvim": "modes-nvim", + "neodev-nvim": "neodev-nvim", "nil": "nil", "nixpkgs": "nixpkgs", "nmd": "nmd", diff --git a/flake.nix b/flake.nix index ea91125..48a280f 100644 --- a/flake.nix +++ b/flake.nix @@ -133,6 +133,11 @@ flake = false; }; + neodev-nvim = { + url = "github:folke/neodev.nvim"; + flake = false; + }; + elixir-ls = { url = "github:elixir-lsp/elixir-ls"; flake = false; diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 03251de..7d8c95b 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -80,6 +80,7 @@ with lib; let "vim-repeat" "smartcolumn" "project-nvim" + "neodev-nvim" "elixir-ls" "elixir-tools" "nvim-colorizer-lua" diff --git a/modules/languages/default.nix b/modules/languages/default.nix index 2011971..e2d5b05 100644 --- a/modules/languages/default.nix +++ b/modules/languages/default.nix @@ -24,6 +24,7 @@ in { ./html.nix ./svelte.nix ./java.nix + ./lua.nix ]; options.vim.languages = { diff --git a/modules/languages/lua.nix b/modules/languages/lua.nix new file mode 100644 index 0000000..2e8d539 --- /dev/null +++ b/modules/languages/lua.nix @@ -0,0 +1,59 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; +with builtins; let + 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;}; + + package = mkOption { + description = "LuaLS package, or the command to run as a list of strings"; + type = with types; either package (listOf str); + default = pkgs.lua-language-server; + }; + + neodev.enable = mkEnableOption "Enable neodev.nvim integration, useful for neovim plugin developers"; + }; + }; + + 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 { + capabilities = capabilities; + on_attach = default_on_attach; + ${optionalString cfg.lsp.neodev.enable "before_init = require('neodev.lsp').before_init;"} + cmd = ${ + if isList cfg.lsp.package + then nvim.lua.expToLua cfg.lsp.package + else ''{"${getExe cfg.lsp.package}"}'' + }; + } + ''; + }) + + (mkIf cfg.lsp.neodev.enable { + vim.startPlugins = ["neodev-nvim"]; + vim.luaConfigRC.neodev = nvim.dag.entryBefore ["lua-lsp"] '' + require("neodev").setup({}) + ''; + }) + ]); +}