diff options
Diffstat (limited to '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 |
