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 ffc4d0e
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 55 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) @namespace.name)
(#any-of? @_func_name
"it"
"xit"
"prop"
"xprop"
"specify"
"xspecify")) @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 ffc4d0e

Please sign in to comment.