fix: use treesitter language name instead of ft if available (#801)

* fix: use treesitter language name if available

This will fix the problem where the filetype is different than the
treesitter lang name. Eg., filetyep -> "sh", langname -> "bash"

* refactor: use treesitter only if the query object is available

* refactor: ok -> parser_ok ;)
This commit is contained in:
Dhruv Manilawala
2021-04-28 19:59:28 +05:30
committed by GitHub
parent 1675d370bf
commit 28ae702682

View File

@@ -368,10 +368,14 @@ files.current_buffer_fuzzy_find = function(opts)
})
end
local ok, parser = pcall(vim.treesitter.get_parser, bufnr, filetype)
if ok then
local query = vim.treesitter.get_query(filetype, "highlights")
local ts_ok, ts_parsers = pcall(require, 'nvim-treesitter.parsers')
if ts_ok then
filetype = ts_parsers.ft_to_lang(filetype)
end
local parser_ok, parser = pcall(vim.treesitter.get_parser, bufnr, filetype)
local query_ok, query = pcall(vim.treesitter.get_query, filetype, "highlights")
if parser_ok and query_ok then
local root = parser:parse()[1]:root()
local highlighter = vim.treesitter.highlighter.new(parser)