treesitter.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. local M = {}
  2. local Log = require "lvim.core.log"
  3. M.config = function()
  4. lvim.builtin.treesitter = {
  5. on_config_done = nil,
  6. ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages
  7. ignore_install = {},
  8. matchup = {
  9. enable = false, -- mandatory, false will disable the whole extension
  10. -- disable = { "c", "ruby" }, -- optional, list of language that will be disabled
  11. },
  12. highlight = {
  13. enable = true, -- false will disable the whole extension
  14. additional_vim_regex_highlighting = false,
  15. disable = { "latex" },
  16. },
  17. context_commentstring = {
  18. enable = true,
  19. enable_autocmd = false,
  20. config = {
  21. -- Languages that have a single comment style
  22. typescript = "// %s",
  23. css = "/* %s */",
  24. scss = "/* %s */",
  25. html = "<!-- %s -->",
  26. svelte = "<!-- %s -->",
  27. vue = "<!-- %s -->",
  28. json = "",
  29. },
  30. },
  31. indent = { enable = true, disable = { "yaml", "python" } },
  32. autotag = { enable = false },
  33. textobjects = {
  34. swap = {
  35. enable = false,
  36. -- swap_next = textobj_swap_keymaps,
  37. },
  38. -- move = textobj_move_keymaps,
  39. select = {
  40. enable = false,
  41. -- keymaps = textobj_sel_keymaps,
  42. },
  43. },
  44. textsubjects = {
  45. enable = false,
  46. keymaps = { ["."] = "textsubjects-smart", [";"] = "textsubjects-big" },
  47. },
  48. playground = {
  49. enable = false,
  50. disable = {},
  51. updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
  52. persist_queries = false, -- Whether the query persists across vim sessions
  53. keybindings = {
  54. toggle_query_editor = "o",
  55. toggle_hl_groups = "i",
  56. toggle_injected_languages = "t",
  57. toggle_anonymous_nodes = "a",
  58. toggle_language_display = "I",
  59. focus_language = "f",
  60. unfocus_language = "F",
  61. update = "R",
  62. goto_node = "<cr>",
  63. show_help = "?",
  64. },
  65. },
  66. rainbow = {
  67. enable = false,
  68. extended_mode = true, -- Highlight also non-parentheses delimiters, boolean or table: lang -> boolean
  69. max_file_lines = 1000, -- Do not enable for files with more than 1000 lines, int
  70. },
  71. }
  72. end
  73. M.setup = function()
  74. -- avoid running in headless mode since it's harder to detect failures
  75. if #vim.api.nvim_list_uis() == 0 then
  76. Log:debug "headless mode detected, skipping running setup for treesitter"
  77. return
  78. end
  79. local status_ok, treesitter_configs = pcall(require, "nvim-treesitter.configs")
  80. if not status_ok then
  81. Log:error "Failed to load nvim-treesitter.configs"
  82. return
  83. end
  84. local opts = vim.deepcopy(lvim.builtin.treesitter)
  85. treesitter_configs.setup(opts)
  86. if lvim.builtin.treesitter.on_config_done then
  87. lvim.builtin.treesitter.on_config_done(treesitter_configs)
  88. end
  89. end
  90. return M