feat(ts)!: use upstream treesitter implementation (#2499)

bumps minimum required neovim version to 0.9, see `help telescope.changelog-2499`
This commit is contained in:
Christian Clason
2023-05-24 10:43:04 +02:00
committed by GitHub
parent 057ee0f878
commit d8c5ed4e40
11 changed files with 62 additions and 99 deletions

View File

@@ -3,10 +3,6 @@ local ts_utils = require "telescope.utils"
local strings = require "plenary.strings"
local conf = require("telescope.config").values
local has_ts, _ = pcall(require, "nvim-treesitter")
local _, ts_configs = pcall(require, "nvim-treesitter.configs")
local _, ts_parsers = pcall(require, "nvim-treesitter.parsers")
local Job = require "plenary.job"
local utils = {}
@@ -131,37 +127,14 @@ utils.regex_highlighter = function(bufnr, ft)
return false
end
local treesitter_attach = function(bufnr, ft)
local lang = ts_parsers.ft_to_lang(ft)
if not ts_configs.is_enabled("highlight", lang, bufnr) then
return false
end
local config = ts_configs.get_module "highlight"
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
-- 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_configs = pcall(require, "nvim-treesitter.configs")
_, ts_parsers = pcall(require, "nvim-treesitter.parsers")
if has_filetype(ft) then
local lang = vim.treesitter.language.get_lang(ft)
if lang and ts_utils.has_ts_parser(lang) then
return vim.treesitter.start(bufnr, lang)
end
end
if has_ts and has_filetype(ft) then
return treesitter_attach(bufnr, ft)
end
return false
end