feat: add config to specify parser for filetypes
Basically, this PR allows one to do:
require("tsht").config.ft_to_parser.typescriptreact = "tsx"
where, typescriptreact and tsx can be substituted for the appropriate filetype, and treesitter parser, respectively (like one can do in nvim-treesitter). This PR closes #17. I realize that another solution was proposed in #14, but was rejected because it added a dependency on nvim-treesitter. This PR avoids that.
Just thought I'd share how I'm working around the issue. If this PR is acceptable, I can modify the README with docs too.
Looks good to me as a workaround
Any update on this? After https://github.com/mfussenegger/nvim-treehopper/commit/f1ffa06bcd1566a50c3122b34334d38f50e1d420 I believe this should just be
diff --git a/lua/tsht.lua b/lua/tsht.lua
index 39f53d7..da10485 100644
--- a/lua/tsht.lua
+++ b/lua/tsht.lua
@@ -4,7 +4,7 @@ local api = vim.api
local M = {}
local ns = api.nvim_create_namespace('me.tsnode')
-M.config = {hint_keys = {}}
+M.config = {hint_keys = {}, ft_to_parser = {}}
local function keys_iter()
local i = 0
@@ -99,7 +99,9 @@ end
local function get_parser(bufnr)
- local ok, parser = pcall(vim.treesitter.get_parser, bufnr)
+ local filetype = api.nvim_buf_get_option(bufnr, 'filetype')
+ local resolved_filetype = M.config.ft_to_parser[filetype]
+ local ok, parser = pcall(vim.treesitter.get_parser, bufnr, resolved_filetype)
local err
if ok then
return parser
See https://github.com/mfussenegger/nvim-treehopper/pull/30