treesitter.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. -- 1. Use the configs module if it exists, otherwise use the new core
  2. local ok, configs = pcall(require, "nvim-treesitter.configs")
  3. if ok then
  4. -- If you are on a version that still has configs
  5. configs.setup({
  6. ensure_installed = {
  7. "c",
  8. "lua",
  9. "java",
  10. "python",
  11. "bash",
  12. "html",
  13. "css",
  14. "javascript",
  15. "bibtex",
  16. "cmake",
  17. "cpp",
  18. "latex",
  19. "perl",
  20. "regex",
  21. "toml",
  22. "yaml"
  23. },
  24. highlight = { enable = true },
  25. })
  26. else
  27. -- THE NEW WAY: If configs is missing, use the internal install module
  28. local install = require('nvim-treesitter.install')
  29. -- This replaces ensure_installed
  30. install.prefer_git = true
  31. -- To install specific parsers via code:
  32. -- require('nvim-treesitter.command').smart_install({ "lua", "python" })
  33. -- Enable highlighting globally the new Neovim way
  34. vim.api.nvim_create_autocmd('FileType', {
  35. callback = function()
  36. local lang = vim.treesitter.language.get_lang(vim.bo.filetype)
  37. if lang then
  38. pcall(vim.treesitter.start)
  39. end
  40. end,
  41. })
  42. end
  43. -- local ts = require('nvim-treesitter')
  44. -- -- 1. Manually install parsers (replaces ensure_installed)
  45. -- ts.install({
  46. -- "c",
  47. -- "lua",
  48. -- "java",
  49. -- "python",
  50. -- "bash",
  51. -- "html",
  52. -- "css",
  53. -- "javascript",
  54. -- "bibtex",
  55. -- "cmake",
  56. -- "cpp",
  57. -- "latex",
  58. -- "perl",
  59. -- "regex",
  60. -- "toml",
  61. -- "yaml"
  62. -- })
  63. -- -- 2. Enable Highlighting (Now done via Neovim API, not Treesitter setup)
  64. -- vim.api.nvim_create_autocmd('FileType', {
  65. -- callback = function()
  66. -- pcall(vim.treesitter.start)
  67. -- end,
  68. -- })
  69. -- require'nvim-treesitter.configs'.setup {
  70. -- ensure_installed = {
  71. -- "c",
  72. -- "lua",
  73. -- "java",
  74. -- "python",
  75. -- "bash",
  76. -- "html",
  77. -- "css",
  78. -- "javascript",
  79. -- "bibtex",
  80. -- "cmake",
  81. -- "cpp",
  82. -- "latex",
  83. -- "perl",
  84. -- "regex",
  85. -- "toml",
  86. -- "yaml"
  87. -- },
  88. -- -- Install parsers synchronously (only applied to `ensure_installed`)
  89. -- sync_install = false,
  90. -- highlight = {
  91. -- enable = true,
  92. -- disable = {"rust"},
  93. -- -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
  94. -- -- Using this option may slow down your editor, and you may see some duplicate highlights.
  95. -- additional_vim_regex_highlighting = false,
  96. -- },
  97. -- refactor = {
  98. -- highlight_definitions = {
  99. -- enable = true,
  100. -- -- Set to false if you have an `updatetime` of ~100.
  101. -- clear_on_cursor_move = false,
  102. -- },
  103. -- highlight_current_scope = {
  104. -- -- very annonying per default, maybe has its use when its unclear
  105. -- enable = false
  106. -- },
  107. -- smart_rename = {
  108. -- enable = true,
  109. -- keymaps = {
  110. -- smart_rename = "grr",
  111. -- },
  112. -- },
  113. -- navigation = {
  114. -- enable = true,
  115. -- keymaps = {
  116. -- goto_definition = "gnd",
  117. -- list_definitions = "gnD",
  118. -- list_definitions_toc = "gO",
  119. -- goto_next_usage = "<A-n>",
  120. -- goto_previous_usage = "<A-p>",
  121. -- },
  122. -- },
  123. -- },
  124. -- }