diff --git a/Makefile b/Makefile index 4d5ad28..d60784a 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,12 @@ all: .PHONY: test test: all tree-sitter test --apply-all-captures + nvim-test-runner .PHONY: update-tests update-tests: all tree-sitter test -u --apply-all-captures + nvim-test-runner .PHONY: playground playground: diff --git a/flake.nix b/flake.nix index 2ac4027..77fba0a 100644 --- a/flake.nix +++ b/flake.nix @@ -37,6 +37,7 @@ }: let inherit (flake-utils.lib) eachDefaultSystem; + inherit (nixpkgs) lib; in eachDefaultSystem (system: @@ -46,6 +47,25 @@ overlays = [ self.overlays.default ]; }; + nvim-test-runner = pkgs.writeShellApplication { + name = "nvim-test-runner"; + + runtimeInputs = with pkgs; [ + highlight-assertions + neovim + ]; + + text = '' + export NVIM_PLENARY='${pkgs.vimPlugins.plenary-nvim}' + export NVIM_TREESITTER='${pkgs.vimPlugins.nvim-treesitter}' + export NVIM_TREESITTER_TEXTOBJECTS='${pkgs.vimPlugins.nvim-treesitter-textobjects}' + export NVIM_TREESITTER_PARSER='${pkgs.vimPlugins.nvim-treesitter.grammarToPlugin self.packages.${system}.tree-sitter-bp}' + + nvim --headless --noplugin -u ${scripts/minimal_init.lua} \ + -c "PlenaryBustedDirectory test/ { minimal_init = '${./scripts/minimal_init.lua}' }" + ''; + }; + bump-version = pkgs.writeShellScriptBin "bump-version" '' set -eu @@ -90,6 +110,13 @@ enable = true; }; + nvim-test-runner = { + enable = true; + name = "nvim tests"; + entry = "${lib.getExe nvim-test-runner}"; + pass_filenames = false; + }; + tree-sitter = { enable = true; name = "tree-sitter tests"; @@ -112,6 +139,7 @@ nativeBuildInputs = with pkgs; [ bump-version nodejs + nvim-test-runner # FIXME: waiting on #301336 # (tree-sitter.override { webUISupport = true; }) tree-sitter diff --git a/scripts/dummy_plugin/queries/bp b/scripts/dummy_plugin/queries/bp new file mode 120000 index 0000000..4578310 --- /dev/null +++ b/scripts/dummy_plugin/queries/bp @@ -0,0 +1 @@ +../../../queries \ No newline at end of file diff --git a/scripts/minimal_init.lua b/scripts/minimal_init.lua new file mode 100644 index 0000000..3813249 --- /dev/null +++ b/scripts/minimal_init.lua @@ -0,0 +1,40 @@ +vim.opt.runtimepath:append(vim.env.NVIM_PLENARY) +vim.opt.runtimepath:append(vim.env.NVIM_TREESITTER) +vim.opt.runtimepath:append(vim.env.NVIM_TREESITTER_TEXTOBJECTS) +vim.opt.runtimepath:append(vim.env.NVIM_TREESITTER_PARSER) + +vim.cmd.runtime({ "plugin/plenary.vim", bang = true }) +vim.cmd.runtime({ "plugin/nvim-treesitter.lua", bang = true }) +vim.cmd.runtime({ "plugin/nvim-treesitter-textobjects.lua", bang = true }) + +local Path = require("plenary.path") + +local project_root = Path:new(".") -- FIXME: relies on current working directory + +vim.filetype.add({ + extension = { + bp = "bp", + }, +}) + +vim.o.swapfile = false +vim.bo.swapfile = false + +local parser_config = require("nvim-treesitter.parsers").get_parser_configs() +parser_config.bp = { + install_info = { + url = project_root.filename, + files = {"src/parser.c"}, + }, +} + +require("nvim-treesitter.configs").setup({ + indent = { enable = true }, + highlight = { enable = true }, +}) + +-- We need a hierarchy of `queries/bp/*.scm` in the runtimepath, otherwise +-- `nvim-treesitter` doesn't enable some of its features (e.g: folding). +-- The dummy plugin has a symlink following that format for our queries. +local dummy_plugin_path = project_root / "scripts" / "dummy_plugin" +vim.opt.runtimepath:append(dummy_plugin_path.filename)