diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2021-07-20 19:20:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-20 19:20:22 +0200 |
| commit | 664690029fdb302bee8d3f27a458383e8477add7 (patch) | |
| tree | 4fc2e4443d4c7d3b25e53a233a244740968ff7d9 /lua/telescope/previewers/utils.lua | |
| parent | d057b105033eceb58ef21ec88e811db1d140f64e (diff) | |
fix: unknown filetype error message (#1034)
Diffstat (limited to 'lua/telescope/previewers/utils.lua')
| -rw-r--r-- | lua/telescope/previewers/utils.lua | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lua/telescope/previewers/utils.lua b/lua/telescope/previewers/utils.lua index 20762e2..5ede0e0 100644 --- a/lua/telescope/previewers/utils.lua +++ b/lua/telescope/previewers/utils.lua @@ -1,7 +1,7 @@ local context_manager = require('plenary.context_manager') local has_ts, _ = pcall(require, 'nvim-treesitter') -local _, ts_highlight = pcall(require, 'nvim-treesitter.highlight') +local _, ts_configs = pcall(require, 'nvim-treesitter.configs') local _, ts_parsers = pcall(require, 'nvim-treesitter.parsers') local Job = require('plenary.job') @@ -70,22 +70,39 @@ utils.regex_highlighter = function(bufnr, ft) return false end +local treesitter_attach = function(bufnr, ft) + local lang = ts_parsers.ft_to_lang(ft) + if ts_parsers.has_parser(lang) then + local config = ts_configs.get_module "highlight" + if vim.tbl_contains(config.disable, lang) then + return false + end + for k, v in pairs(config.custom_captures) do + vim.treesitter.highlighter.hl_map[k] = v + end + vim.treesitter.highlighter.new(ts_parsers.get_parser(bufnr, lang)) + local is_table = type(config.additional_vim_regex_highlighting) == "table" + if config.additional_vim_regex_highlighting and + (not is_table or vim.tbl_contains(config.additional_vim_regex_highlighting, lang)) then + vim.api.nvim_buf_set_option(bufnr, "syntax", ft) + end + return true + end + return false +end + -- Attach ts highlighter utils.ts_highlighter = function(bufnr, ft) if not has_ts then has_ts, _ = pcall(require, 'nvim-treesitter') if has_ts then - _, ts_highlight = pcall(require, 'nvim-treesitter.highlight') + _, ts_configs = pcall(require, 'nvim-treesitter.configs') _, ts_parsers = pcall(require, 'nvim-treesitter.parsers') end end if has_ts and has_filetype(ft) then - local lang = ts_parsers.ft_to_lang(ft); - if ts_parsers.has_parser(lang) then - ts_highlight.attach(bufnr, lang) - return true - end + return treesitter_attach(bufnr, ft) end return false end |
