Skip to content

Commit 387d4b7

Browse files
author
Marc Jakobi
committed
feat: don't depend on nvim-treesitter for tree-sitter features
1 parent 3bf5de6 commit 387d4b7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## Unreleased
10+
11+
### Added
12+
13+
- Use tree-sitter if the parser for Haskell is installed,
14+
without requiring the nvim-treesitter plugin.
15+
916
## [1.1.0] - 2023-11-05
1017

1118
### Added

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ Use luarocks or your favourite plugin manager.
4949
- [`haskell-language-server`](https://haskell-language-server.readthedocs.io/en/latest/installation.html)
5050
and [`haskell-tools.nvim`](https://github.com/mrcjkb/haskell-tools.nvim)
5151
(some snippets work better with LSP).
52-
- [`nvim-treesitter`](https://github.com/nvim-treesitter/nvim-treesitter)
52+
- A Haskell tree-sitter parser or
53+
[`nvim-treesitter`](https://github.com/nvim-treesitter/nvim-treesitter)
5354
and the parser for haskell.
5455

5556
## Quick setup

lua/haskell-snippets/module.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ local choice = ls.choice_node
2424
local dynamic = ls.dynamic_node
2525

2626
local has_treesitter, parsers = pcall(require, 'nvim-treesitter.parsers')
27-
local hs_lang = has_treesitter and parsers.ft_to_lang('haskell')
27+
local hs_lang = has_treesitter and parsers.ft_to_lang('haskell') or 'haskell'
28+
local has_haskell_parser = pcall(vim.treesitter.get_string_parser, '', 'haskell')
2829

2930
local function get_module_name_node()
3031
local module_name = util.lsp_get_module_name()
@@ -77,7 +78,7 @@ local function get_qualified_name_node(args)
7778
end
7879
local import_stmt = 'import qualified ' .. module_name
7980
local choices = { insert(1) }
80-
if hs_lang then
81+
if has_haskell_parser then
8182
local module_query = vim.treesitter.query.parse(hs_lang, '(module) @mod')
8283
local lang_tree = vim.treesitter.get_string_parser(import_stmt, hs_lang, { injections = { [hs_lang] = '' } })
8384
local root = fast_parse(lang_tree):root()

0 commit comments

Comments
 (0)