Skip to content

Commit

Permalink
chore!(queries): adjust queries for tree-sitter-haskell rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed May 12, 2024
1 parent 8241124 commit 5e28790
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 202 deletions.
4 changes: 2 additions & 2 deletions lua/neotest-haskell/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ local function mk_module_query(modules)
for i, module_name in ipairs(modules) do
local filter = ([[
;;query
(module) @mod%d
(module_id) @mod%d
(#eq? @mod%d "%s")
]]):format(i, i, module_name)
table.insert(filters, filter)
end
return [[
;;query
(qualified_module
(module
]] .. table.concat(filters, '\n') .. [[
;;query
)
Expand Down
57 changes: 56 additions & 1 deletion nix/ci-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,55 @@
disabled = luaOlder "5.1";
propagatedBuildInputs = [lua nvim-nio plenary-nvim];
}) {};

luarocks-build-treesitter-parser = luaself.callPackage ({
buildLuarocksPackage,
luaOlder,
luafilesystem,
fetchurl,
fetchzip,
lua,
...
}:
buildLuarocksPackage {
pname = "luarocks-build-treesitter-parser";
version = "2.0.0-1";
knownRockspec =
(fetchurl {
url = "mirror://luarocks/luarocks-build-treesitter-parser-2.0.0-1.rockspec";
sha256 = "0ylax1r0yl5k742p8n0fq5irs2r632npigqp1qckfx7kwi89gxhb";
})
.outPath;
src = fetchzip {
url = "https://github.com/nvim-neorocks/luarocks-build-treesitter-parser/archive/v2.0.0.zip";
sha256 = "0gqiwk7dk1xn5n2m0iq5c7xkrgyaxwyd1spb573l289gprvlrbn5";
};

disabled = luaOlder "5.1";
propagatedBuildInputs = [lua luafilesystem];
}) {};

tree-sitter-haskell = luaself.callPackage (
{
buildLuarocksPackage,
fetchurl,
fetchzip,
luarocks-build-treesitter-parser,
...
}:
buildLuarocksPackage {
pname = "tree-sitter-haskell";
version = "scm-1";
knownRockspec = self + "/spec/fixtures/tree-sitter-haskell-scm-1.rockspec";
src = fetchzip {
url = "https://github.com/tree-sitter/tree-sitter-haskell/archive/e29c59236283198d93740a796c50d1394bccbef5.zip";
sha256 = "03mk4jvlg2l33xfd8p2xk1q0xcansij2sfa98bdnhsh8ac1jm30h";
};
propagatedBuildInputs = [
luarocks-build-treesitter-parser
];
}
) {};
};

lua5_1 = prev.lua5_1.override {
Expand All @@ -63,6 +112,12 @@

lua51Packages = prev.lua51Packages // final.lua5_1.pkgs;

tree-sitter-haskell-plugin = final.neovimUtils.buildNeovimPlugin {
pname = "tree-sitter-haskell";
version = "scm";
src = final.lua51Packages.tree-sitter-haskell.src;
};

mkNeorocksTest = {
name,
nvim ? final.neovim-unwrapped,
Expand All @@ -73,7 +128,7 @@
start = with final.vimPlugins; [
final.neotest-haskell-dev # Queries need to be on the rtp
plenary-nvim # XXX: This needs to be on the nvim rtp
(nvim-treesitter.withPlugins (p: [p.haskell])) # TODO: replace with tree-sitter-haskell
tree-sitter-haskell-plugin
];
};
};
Expand Down
94 changes: 41 additions & 53 deletions queries/haskell/hspec-positions.scm
Original file line number Diff line number Diff line change
@@ -1,55 +1,43 @@
;; describe (unqualified)
(_ (_ (exp_apply
(exp_name (variable) @func_name)
(exp_literal) @namespace.name
)
(#any-of? @func_name
"describe"
"xdescribe"
"context"
"xcontext"
)
)) @namespace.definition
;; describe
(_ (_ (expression/apply
function: [
(variable) @_func_name
(qualified id: (variable) @_func_name)
]
argument: (expression/literal) @namespace.name)
(#any-of? @_func_name
"describe"
"xdescribe"
"context"
"xcontext"
))) @namespace.definition

;; describe (qualified)
(_ (_ (exp_apply
(exp_name (qualified_variable (variable) @func_name))
(exp_literal) @namespace.name
)
(#any-of? @func_name
"describe"
"xdescribe"
"context"
"xcontext"
)
)) @namespace.definition
;; test
((expression/apply
function: [
(variable) @_func_name
(qualified id: (variable) @_func_name)
]
argument: (expression/literal) @test.name)
(#any-of? @_func_name
"it"
"xit"
"prop"
"xprop"
"specify"
"xspecify")) @test.definition

;; test (unqualified)
((exp_apply
(exp_name (variable) @func_name)
(exp_literal) @test.name
)
(#any-of? @func_name
"it"
"xit"
"prop"
"xprop"
"specify"
"xspecify"
)
) @test.definition

;; test (qualified)
((exp_apply
(exp_name (qualified_variable (variable) @func_name))
(exp_literal) @test.name
)
(#any-of? @func_name
"it"
"xit"
"prop"
"xprop"
"specify"
"xspecify"
)
) @test.definition
;; test
(_ (expression/apply
function: [
(variable) @_func_name
(qualified id: (variable) @_func_name)
]
argument: (expression/literal) @test.name)
(#any-of? @_func_name
"it"
"xit"
"prop"
"xprop"
"specify"
"xspecify")) @test.definition
61 changes: 20 additions & 41 deletions queries/haskell/sydtest-positions.scm
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
;; NOTE: The sydtest runner inclides all queries for hspec, too.
;; NOTE: The sydtest runner includes all queries for hspec, too.

;; test (unqualified)
((exp_apply
(exp_name (variable) @func_name)
(exp_literal) @test.name
)
(#any-of? @func_name
"itWithOuter"
"xitWithOuter"
"itWithBoth"
"xitWithBoth"
"itWithAll"
"xitWithAll"
"specifyWithOuter"
"xspecifyWithOuter"
"specifyWithBoth"
"xspecifyWithBoth"
"specifyWithAll"
"xspecifyWithAll"
)
) @test.definition

;; test (qualified)
((exp_apply
(exp_name (qualified_variable (variable) @func_name))
(exp_literal) @test.name
)
(#any-of? @func_name
"itWithOuter"
"xitWithOuter"
"itWithBoth"
"xitWithBoth"
"itWithAll"
"xitWithAll"
"specifyWithOuter"
"xspecifyWithOuter"
"specifyWithBoth"
"xspecifyWithBoth"
"specifyWithAll"
"xspecifyWithAll"
)
) @test.definition
((expression/apply
function: [
(variable) @_func_name
(qualified id: (variable) @_func_name)
]
argument: (expression/literal) @test.name)
(#any-of? @_func_name
"itWithOuter"
"xitWithOuter"
"itWithBoth"
"xitWithBoth"
"itWithAll"
"xitWithAll"
"specifyWithOuter"
"xspecifyWithOuter"
"specifyWithBoth"
"xspecifyWithBoth"
"specifyWithAll"
"xspecifyWithAll")) @test.definition
Loading

0 comments on commit 5e28790

Please sign in to comment.