Add NeoVim test runner
For the queries that can't be tested with `tree-sitter` itself.
This commit is contained in:
parent
cb932811c5
commit
cabd5f6a20
4 changed files with 95 additions and 0 deletions
2
Makefile
2
Makefile
|
|
@ -5,10 +5,12 @@ all:
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: all
|
test: all
|
||||||
tree-sitter test --apply-all-captures
|
tree-sitter test --apply-all-captures
|
||||||
|
nvim-test-runner
|
||||||
|
|
||||||
.PHONY: update-tests
|
.PHONY: update-tests
|
||||||
update-tests: all
|
update-tests: all
|
||||||
tree-sitter test -u --apply-all-captures
|
tree-sitter test -u --apply-all-captures
|
||||||
|
nvim-test-runner
|
||||||
|
|
||||||
.PHONY: playground
|
.PHONY: playground
|
||||||
playground:
|
playground:
|
||||||
|
|
|
||||||
28
flake.nix
28
flake.nix
|
|
@ -37,6 +37,7 @@
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (flake-utils.lib) eachDefaultSystem;
|
inherit (flake-utils.lib) eachDefaultSystem;
|
||||||
|
inherit (nixpkgs) lib;
|
||||||
in
|
in
|
||||||
eachDefaultSystem
|
eachDefaultSystem
|
||||||
(system:
|
(system:
|
||||||
|
|
@ -46,6 +47,25 @@
|
||||||
overlays = [ self.overlays.default ];
|
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" ''
|
bump-version = pkgs.writeShellScriptBin "bump-version" ''
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
|
@ -90,6 +110,13 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
nvim-test-runner = {
|
||||||
|
enable = true;
|
||||||
|
name = "nvim tests";
|
||||||
|
entry = "${lib.getExe nvim-test-runner}";
|
||||||
|
pass_filenames = false;
|
||||||
|
};
|
||||||
|
|
||||||
tree-sitter = {
|
tree-sitter = {
|
||||||
enable = true;
|
enable = true;
|
||||||
name = "tree-sitter tests";
|
name = "tree-sitter tests";
|
||||||
|
|
@ -112,6 +139,7 @@
|
||||||
nativeBuildInputs = with pkgs; [
|
nativeBuildInputs = with pkgs; [
|
||||||
bump-version
|
bump-version
|
||||||
nodejs
|
nodejs
|
||||||
|
nvim-test-runner
|
||||||
# FIXME: waiting on #301336
|
# FIXME: waiting on #301336
|
||||||
# (tree-sitter.override { webUISupport = true; })
|
# (tree-sitter.override { webUISupport = true; })
|
||||||
tree-sitter
|
tree-sitter
|
||||||
|
|
|
||||||
22
queries/indents.scm
Normal file
22
queries/indents.scm
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
; Expressions {{{
|
||||||
|
(list_expression) @indent.begin
|
||||||
|
|
||||||
|
(list_expression
|
||||||
|
"]" @indent.branch)
|
||||||
|
|
||||||
|
(map_expression) @indent.begin
|
||||||
|
|
||||||
|
(map_expression
|
||||||
|
"}" @indent.end)
|
||||||
|
|
||||||
|
(assignment) @indent.begin ; FIXME: do I need it?
|
||||||
|
; }}}
|
||||||
|
|
||||||
|
; Declarations {{{
|
||||||
|
(module) @indent.begin
|
||||||
|
|
||||||
|
(module
|
||||||
|
")" @indent.end)
|
||||||
|
(module
|
||||||
|
"}" @indent.end)
|
||||||
|
; }}}
|
||||||
43
scripts/minimal_init.lua
Normal file
43
scripts/minimal_init.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
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 },
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Add queries, overriding potential `nvim-treesitter`-provided ones
|
||||||
|
local scan_dir = require("plenary.scandir").scan_dir
|
||||||
|
local queries_dir = project_root / "queries"
|
||||||
|
for _, name in ipairs(scan_dir(queries_dir.filename)) do
|
||||||
|
local content = Path:new(name):read()
|
||||||
|
local basename = name:gsub(".*/", "")
|
||||||
|
vim.treesitter.query.set("bp", basename:gsub(".scm$", ""), content)
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue