diff options
| author | fffed <47778360+fffed@users.noreply.github.com> | 2020-12-31 00:24:45 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-30 22:24:45 +0100 |
| commit | d72f73feebb1741e9acbd10ee23b3c1e0d5da5fa (patch) | |
| tree | 7027a2d726c81ffeda1e5e0865ed43a05f317fa0 /lua/telescope/previewers | |
| parent | e0705b5d4a10570b4b781a5ecfc4f026b2f2cd4e (diff) | |
fix: add ts_parsers.ft_to_lang to detect lang (#373)
Add detection of a proper buffer language by `ts_parsers.ft_to_lang` as `ts_parsers.has_parser` works with `language` but not with `filetype`
https://github.com/nvim-treesitter/nvim-treesitter/issues/796
Diffstat (limited to 'lua/telescope/previewers')
| -rw-r--r-- | lua/telescope/previewers/utils.lua | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lua/telescope/previewers/utils.lua b/lua/telescope/previewers/utils.lua index 475083a..ca41af5 100644 --- a/lua/telescope/previewers/utils.lua +++ b/lua/telescope/previewers/utils.lua @@ -49,31 +49,40 @@ utils.job_maker = function(cmd, bufnr, opts) end end +local function has_filetype(ft) + return ft and ft ~= '' +end + --- Attach default highlighter which will choose between regex and ts utils.highlighter = function(bufnr, ft) - if ft and ft ~= '' then - if has_ts and ts_parsers.has_parser(ft) then - ts_highlight.attach(bufnr, ft) - else - vim.cmd(':ownsyntax ' .. ft) - end + if not(utils.ts_highlighter(bufnr, ft)) then + utils.regex_highlighter(bufnr, ft) end end --- Attach regex highlighter utils.regex_highlighter = function(_, ft) - if ft and ft ~= '' then + if has_filetype(ft) then vim.cmd(':ownsyntax ' .. ft) + + return true end + + return false end -- Attach ts highlighter utils.ts_highlighter = function(bufnr, ft) - if ft and ft ~= '' then - if has_ts and ts_parsers.has_parser(ft) then - ts_highlight.attach(bufnr, ft) + if has_filetype(ft) then + local lang = ts_parsers.ft_to_lang(ft); + if has_ts and ts_parsers.has_parser(lang) then + ts_highlight.attach(bufnr, lang) + + return true end end + + return false end return utils |
