Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config to specify parser for filetypes #18

Conversation

davidatsurge
Copy link

@davidatsurge davidatsurge commented Jul 19, 2022

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.

@mfussenegger
Copy link
Owner

Looks good to me as a workaround

@cfbender
Copy link

cfbender commented Aug 31, 2022

Any update on this? After f1ffa06 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

@mfussenegger
Copy link
Owner

See #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No parser for typescriptreact language (when treesitter parser name is different from filetype)
3 participants