diff --git a/flake.lock b/flake.lock index 6cc5e9a..f76438e 100644 --- a/flake.lock +++ b/flake.lock @@ -242,6 +242,22 @@ "type": "github" } }, + "neodev-nvim": { + "flake": false, + "locked": { + "lastModified": 1698559518, + "narHash": "sha256-UEneC6yd+EqlmQ9T00N1XOP4/xyhDhPB0rZ5fV9d8Us=", + "owner": "folke", + "repo": "neodev.nvim", + "rev": "f3f5d756f4043180523bb69072a104f7216b5f42", + "type": "github" + }, + "original": { + "owner": "folke", + "repo": "neodev.nvim", + "type": "github" + } + }, "neotest": { "flake": false, "locked": { @@ -430,6 +446,7 @@ "inputs": { "flake-compat": "flake-compat", "flake-utils": "flake-utils", + "neodev-nvim": "neodev-nvim", "neotest": "neotest", "neovim-nightly-overlay": "neovim-nightly-overlay", "nixpkgs": "nixpkgs_3", diff --git a/flake.nix b/flake.nix index 2f093d3..3509b5d 100644 --- a/flake.nix +++ b/flake.nix @@ -25,6 +25,12 @@ flake = false; }; + # inputs for tests and lints + neodev-nvim = { + url = "github:folke/neodev.nvim"; + flake = false; + }; + neotest = { url = "github:nvim-neotest/neotest"; flake = false; @@ -37,6 +43,7 @@ flake-utils, neovim-nightly-overlay, pre-commit-hooks, + neodev-nvim, plenary-nvim, neotest, ... @@ -50,7 +57,7 @@ "x86_64-linux" ]; - ci-overlay = import ./nix/ci-overlay.nix {inherit (inputs) self plenary-nvim neotest;}; + ci-overlay = import ./nix/ci-overlay.nix {inherit (inputs) self neodev-nvim plenary-nvim neotest;}; nvim-plugin-overlay = import ./nix/nvim-plugin-overlay.nix { inherit name; @@ -67,52 +74,86 @@ ]; }; + mkTypeCheck = { + nvim-api ? [], + disabled-diagnostics ? [], + }: + pre-commit-hooks.lib.${system}.run { + src = self; + hooks = { + lua-ls.enable = true; + }; + settings = { + lua-ls = { + config = { + runtime.version = "LuaJIT"; + Lua = { + workspace = { + library = + nvim-api + ++ (with pkgs; [ + "${neotest-plugin}/lua" + # FIXME: + # "${pkgs.luajitPackages.busted}" + ]); + checkThirdParty = false; + ignoreDir = [ + ".git" + ".github" + ".direnv" + "result" + "nix" + "doc" + "tests" # neotest's types are not well-defined + ]; + }; + diagnostics = { + globals = [ + "vim" + "describe" + "it" + "assert" + ]; + libraryFiles = "Disable"; + disable = disabled-diagnostics; + }; + }; + }; + }; + }; + }; + + type-check-stable = mkTypeCheck { + nvim-api = [ + "${pkgs.neovim}/share/nvim/runtime/lua" + "${pkgs.neodev-plugin}/types/stable" + ]; + disabled-diagnostics = [ + "duplicate-set-field" # neotest + "undefined-doc-name" + "redundant-parameter" + "invisible" + ]; + }; + + type-check-nightly = mkTypeCheck { + nvim-api = [ + "${pkgs.neovim-nightly}/share/nvim/runtime/lua" + "${pkgs.neodev-plugin}/types/nightly" + ]; + disabled-diagnostics = [ + "duplicate-set-field" # neotest + ]; + }; + pre-commit-check = pre-commit-hooks.lib.${system}.run { src = self; hooks = { alejandra.enable = true; stylua.enable = true; - lua-ls.enable = true; editorconfig-checker.enable = true; markdownlint.enable = true; }; - settings = { - lua-ls.config = { - Lua = { - diagnostics = { - globals = [ - "vim" - "describe" - "it" - "assert" - ]; - libraryFiles = "Disable"; - disable = [ - "duplicate-set-field" - ]; - }; - workspace = { - library = with pkgs; [ - "${neovim-nightly}/share/nvim/runtime/lua" - "${plenary-plugin}/lua" - "${nvim-treesitter-plugin}/lua" - "${neotest-plugin}/lua" - ]; - checkThirdParty = false; - ignoreDir = [ - ".git" - ".github" - ".direnv" - "result" - "nix" - "doc" - "tests" # neotest's types are not well-defined - ]; - }; - runtime.version = "LuaJIT"; - }; - }; - }; }; devShell = pkgs.mkShell { @@ -145,7 +186,11 @@ }; checks = { - inherit pre-commit-check; + inherit + pre-commit-check + type-check-stable + type-check-nightly + ; inherit (pkgs) nvim-stable-test diff --git a/nix/ci-overlay.nix b/nix/ci-overlay.nix index 5617fa7..0f789e4 100644 --- a/nix/ci-overlay.nix +++ b/nix/ci-overlay.nix @@ -1,6 +1,7 @@ # Add flake.nix test inputs as arguments here { self, + neodev-nvim, plenary-nvim, neotest, }: final: prev: @@ -8,6 +9,11 @@ with final.lib; with final.stdenv; let nvim-nightly = final.neovim-nightly; + neodev-plugin = final.pkgs.vimUtils.buildVimPlugin { + name = "neodev.nvim"; + src = neodev-nvim; + }; + plenary-plugin = final.pkgs.vimUtils.buildVimPlugin { name = "plenary.nvim"; src = plenary-nvim; @@ -79,6 +85,7 @@ in { nvim = nvim-nightly; }; inherit + neodev-plugin plenary-plugin neotest-plugin nvim-treesitter-plugin