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 02154f3 commit 9605caa
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 122 deletions.
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
81 changes: 27 additions & 54 deletions queries/haskell/hspec-positions.scm
Original file line number Diff line number Diff line change
@@ -1,55 +1,28 @@
;; 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 (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
52 changes: 26 additions & 26 deletions queries/haskell/tasty-positions.scm
Original file line number Diff line number Diff line change
@@ -1,115 +1,115 @@
;; NOTE: The tasty runner inclides all queries for hspec, too.

(_
(exp_name) @func_name
(#lua-match? @func_name "^.*testGroup")
(exp_name) @_func_name
(#lua-match? @_func_name "^.*testGroup")
(exp_literal (string) @namespace.name)
(exp_list (_))
) @namespace.definition

;; describe (unqualified)
(_ (_ (exp_apply
(exp_name (variable) @func_name)
(exp_name (variable) @_func_name)
(exp_literal) @namespace.name
)
(#match? @func_name
(#match? @_func_name
"testSpec"
)
)) @namespace.definition

;; describe (qualified)
(_ (_ (exp_apply
(exp_name (qualified_variable (variable) @func_name))
(exp_name (qualified_variable (variable) @_func_name))
(exp_literal) @namespace.name
)
(#match? @func_name
(#match? @_func_name
"testSpec"
)
)) @namespace.definition

;; smallcheck/quickcheck/hedgehog (qualified or unqualified)
(
(exp_apply
(exp_name) @func_name
(exp_name) @_func_name
(exp_literal) @test.name
) @test.definition
(#lua-match? @func_name "^.*testProperty.*")
(#lua-match? @_func_name "^.*testProperty.*")
)

;; expectFail (qualified or unqualified)
(
(exp_name) @func_name
(exp_name) @_func_name
(exp_apply
(exp_name)
(exp_literal) @test.name
) @test.definition
(#lua-match? @func_name "^.*expectFail")
(#lua-match? @_func_name "^.*expectFail")
)

;; HUnit (qualified or unqualified)
(_
(exp_apply
(exp_name) @func_name
(#lua-match? @func_name "^.*testCase")
(exp_name) @_func_name
(#lua-match? @_func_name "^.*testCase")
(exp_literal) @test.name
) @test.definition
)

;; Program (qualified or unqualified)
(_
(exp_apply
(exp_name) @func_name
(#lua-match? @func_name "^.*testProgram")
(exp_name) @_func_name
(#lua-match? @_func_name "^.*testProgram")
(exp_literal) @test.name
) @test.definition
)

;; Wai (qualified or unqualified)
(_
(exp_apply
(exp_name) @func_name
(#lua-match? @func_name "^.*testWai")
(exp_name) @_func_name
(#lua-match? @_func_name "^.*testWai")
(exp_literal) @test.name
) @test.definition
)

;; tasty-golden goldenVsFile (qualified or unqualified)
(_
(exp_apply
(exp_name) @func_name
(#lua-match? @func_name "^.*goldenVsFile")
(exp_name) @_func_name
(#lua-match? @_func_name "^.*goldenVsFile")
(exp_literal) @test.name
) @test.definition
)
;; tasty-golden goldenVsFileDiff (qualified or unqualified)
(_
(exp_apply
(exp_name) @func_name
(#lua-match? @func_name "^.*goldenVsFileDiff")
(exp_name) @_func_name
(#lua-match? @_func_name "^.*goldenVsFileDiff")
(exp_literal) @test.name
) @test.definition
)
;; tasty-golden goldenVsString (qualified or unqualified)
(_
(exp_apply
(exp_name) @func_name
(#lua-match? @func_name "^.*goldenVsString")
(exp_name) @_func_name
(#lua-match? @_func_name "^.*goldenVsString")
(exp_literal) @test.name
) @test.definition
)
;; tasty-golden goldenVsStringDiff (qualified or unqualified)
(_
(exp_apply
(exp_name) @func_name
(#lua-match? @func_name "^.*goldenVsStringDiff")
(exp_name) @_func_name
(#lua-match? @_func_name "^.*goldenVsStringDiff")
(exp_literal) @test.name
) @test.definition
)
;; tasty-golden postCleanup (qualified or unqualified)
(_
(exp_apply
(exp_name) @func_name
(#lua-match? @func_name "^.*postCleanup")
(exp_name) @_func_name
(#lua-match? @_func_name "^.*postCleanup")
(exp_literal) @test.name
) @test.definition
)
31 changes: 31 additions & 0 deletions spec/fixtures/tree-sitter-haskell-scm-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local git_ref = 'e29c59236283198d93740a796c50d1394bccbef5'
local modrev = 'scm'
local specrev = '1'

local repo_url = 'https://github.com/tree-sitter/tree-sitter-haskell'

rockspec_format = '3.0'
package = 'tree-sitter-haskell'
version = modrev ..'-'.. specrev

description = {
summary = 'tree-sitter parser and Neovim queries for haskell',
labels = { 'neovim', 'tree-sitter' } ,
homepage = 'https://github.com/tree-sitter/tree-sitter-haskell',
license = 'MIT'
}

build_dependencies = {
'luarocks-build-treesitter-parser >= 1.3.0',
}

source = {
url = repo_url .. '/archive/' .. git_ref .. '.zip',
dir = 'tree-sitter-haskell-' .. 'e29c59236283198d93740a796c50d1394bccbef5',
}

build = {
type = "treesitter-parser",
lang = "haskell",
sources = { "src/parser.c", "src/scanner.c" },
}

0 comments on commit 9605caa

Please sign in to comment.