summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authormarcel <62728887+marcelarie@users.noreply.github.com>2022-07-01 22:58:05 +0200
committerGitHub <noreply@github.com>2022-07-01 22:58:05 +0200
commit5dd4b5291085d0a843a43c94c5880b513fd0f484 (patch)
tree2fb2e79b58f5ce09190672f1dbf851541a01c5c3 /lua
parent0621c1c6ba3e561dfb06f58a7b0aedfcd464b590 (diff)
break: cleanup preview.treesitter language setting (#1612)
this follows nvim-treesitter more closely but enable can also be a table of enabled languages The config now looks like this: ```lua defaults = { preview = { treesitter = { enable = false, -- or enable = { "c" }, -- disable can be set if enable isn't set disable = { "perl", "javascript" }, }, }, }, ```
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/config.lua13
-rw-r--r--lua/telescope/previewers/utils.lua26
2 files changed, 31 insertions, 8 deletions
diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua
index c5a9ebf..8198ee2 100644
--- a/lua/telescope/config.lua
+++ b/lua/telescope/config.lua
@@ -593,8 +593,17 @@ append(
highlighting, which falls back to regex-based highlighting.
`true`: treesitter highlighting for all available filetypes
`false`: regex-based highlighting for all filetypes
- `table`: table of filetypes for which to attach treesitter
- highlighting
+ `table`: following nvim-treesitters highlighting options:
+ It contains two keys:
+ - enable boolean|table: if boolean, enable all ts
+ highlighing with that flag,
+ disable still considered.
+ Containing a list of filetypes,
+ that are enabled, disabled
+ ignored because it doesnt make
+ any sense in this case.
+ - disable table: containing a list of filetypes
+ that are disabled
Default: true
- msg_bg_fillchar: Character to fill background of unpreviewable buffers with
Default: "╱"
diff --git a/lua/telescope/previewers/utils.lua b/lua/telescope/previewers/utils.lua
index d250894..b1d1d5e 100644
--- a/lua/telescope/previewers/utils.lua
+++ b/lua/telescope/previewers/utils.lua
@@ -82,12 +82,26 @@ end
utils.highlighter = function(bufnr, ft, opts)
opts = opts or {}
opts.preview = opts.preview or {}
- opts.preview.treesitter = vim.F.if_nil(
- opts.preview.treesitter,
- type(conf.preview) == "table" and conf.preview.treesitter
- )
- local ts_highlighting = opts.preview.treesitter == true
- or type(opts.preview.treesitter) == "table" and vim.tbl_contains(opts.preview.treesitter, ft)
+ opts.preview.treesitter = vim.F.if_nil(opts.preview.treesitter, conf.preview.treesitter)
+ if type(opts.preview.treesitter) == "boolean" then
+ local temp = { enable = opts.preview.treesitter }
+ opts.preview.treesitter = temp
+ end
+
+ local ts_highlighting = (function()
+ if type(opts.preview.treesitter.enable) == "table" then
+ if vim.tbl_contains(opts.preview.treesitter.enable, ft) then
+ return true
+ end
+ return false
+ end
+
+ if vim.tbl_contains(vim.F.if_nil(opts.preview.treesitter.disable, {}), ft) then
+ return false
+ end
+
+ return opts.preview.treesitter.enable == nil or opts.preview.treesitter.enable == true
+ end)()
local ts_success
if ts_highlighting then