2021-07-13 03:11:43 +02:00
|
|
|
local M = {}
|
2021-10-10 21:07:41 +02:00
|
|
|
local Log = require "lvim.core.log"
|
2021-08-22 20:03:19 +02:00
|
|
|
|
2021-07-13 03:11:43 +02:00
|
|
|
M.config = function()
|
2021-07-25 03:17:11 +02:00
|
|
|
lvim.builtin.treesitter = {
|
2021-08-22 20:03:19 +02:00
|
|
|
on_config_done = nil,
|
2021-07-13 03:11:43 +02:00
|
|
|
ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages
|
|
|
|
ignore_install = {},
|
|
|
|
matchup = {
|
|
|
|
enable = false, -- mandatory, false will disable the whole extension
|
|
|
|
-- disable = { "c", "ruby" }, -- optional, list of language that will be disabled
|
|
|
|
},
|
|
|
|
highlight = {
|
|
|
|
enable = true, -- false will disable the whole extension
|
|
|
|
additional_vim_regex_highlighting = true,
|
|
|
|
disable = { "latex" },
|
|
|
|
},
|
|
|
|
context_commentstring = {
|
2021-11-05 23:15:10 +01:00
|
|
|
enable = true,
|
|
|
|
config = {
|
|
|
|
-- Languages that have a single comment style
|
|
|
|
typescript = "// %s",
|
|
|
|
css = "/* %s */",
|
|
|
|
scss = "/* %s */",
|
|
|
|
html = "<!-- %s -->",
|
|
|
|
svelte = "<!-- %s -->",
|
|
|
|
vue = "<!-- %s -->",
|
|
|
|
json = "",
|
|
|
|
},
|
2021-07-13 03:11:43 +02:00
|
|
|
},
|
|
|
|
-- indent = {enable = true, disable = {"python", "html", "javascript"}},
|
|
|
|
-- TODO seems to be broken
|
2021-07-27 00:56:08 +02:00
|
|
|
indent = { enable = true, disable = { "yaml" } },
|
2021-07-13 03:11:43 +02:00
|
|
|
autotag = { enable = false },
|
|
|
|
textobjects = {
|
|
|
|
swap = {
|
|
|
|
enable = false,
|
|
|
|
-- swap_next = textobj_swap_keymaps,
|
|
|
|
},
|
|
|
|
-- move = textobj_move_keymaps,
|
|
|
|
select = {
|
|
|
|
enable = false,
|
|
|
|
-- keymaps = textobj_sel_keymaps,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
textsubjects = {
|
|
|
|
enable = false,
|
|
|
|
keymaps = { ["."] = "textsubjects-smart", [";"] = "textsubjects-big" },
|
|
|
|
},
|
|
|
|
playground = {
|
|
|
|
enable = false,
|
|
|
|
disable = {},
|
|
|
|
updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
|
|
|
|
persist_queries = false, -- Whether the query persists across vim sessions
|
|
|
|
keybindings = {
|
|
|
|
toggle_query_editor = "o",
|
|
|
|
toggle_hl_groups = "i",
|
|
|
|
toggle_injected_languages = "t",
|
|
|
|
toggle_anonymous_nodes = "a",
|
|
|
|
toggle_language_display = "I",
|
|
|
|
focus_language = "f",
|
|
|
|
unfocus_language = "F",
|
|
|
|
update = "R",
|
|
|
|
goto_node = "<cr>",
|
|
|
|
show_help = "?",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
rainbow = {
|
|
|
|
enable = false,
|
|
|
|
extended_mode = true, -- Highlight also non-parentheses delimiters, boolean or table: lang -> boolean
|
|
|
|
max_file_lines = 1000, -- Do not enable for files with more than 1000 lines, int
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.setup = function()
|
2021-12-28 09:48:42 +01:00
|
|
|
-- avoid running in headless mode since it's harder to detect failures
|
|
|
|
if #vim.api.nvim_list_uis() == 0 then
|
|
|
|
Log:debug "headless mode detected, skipping running setup for treesitter"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-07-13 03:11:43 +02:00
|
|
|
local status_ok, treesitter_configs = pcall(require, "nvim-treesitter.configs")
|
|
|
|
if not status_ok then
|
2021-12-28 09:48:42 +01:00
|
|
|
Log:error "Failed to load nvim-treesitter.configs"
|
2021-07-13 03:11:43 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-11-03 12:30:34 +01:00
|
|
|
local opts = vim.deepcopy(lvim.builtin.treesitter)
|
|
|
|
|
|
|
|
treesitter_configs.setup(opts)
|
2021-08-22 20:03:19 +02:00
|
|
|
|
|
|
|
if lvim.builtin.treesitter.on_config_done then
|
|
|
|
lvim.builtin.treesitter.on_config_done(treesitter_configs)
|
|
|
|
end
|
2021-07-13 03:11:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|