nvim-config11/lua/plugins/treesitter.lua

137 lines
5.9 KiB
Lua
Raw Permalink Normal View History

2025-03-27 08:18:20 +00:00
return {
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
-- dependencies = { 'nvim-treesitter/nvim-treesitter-textobjects' },
-- branch = 'main',
branch = 'master',
lazy = false,
2025-03-27 08:18:20 +00:00
config = function()
-- require 'nvim-treesitter'.setup {
-- -- Directory to install parsers and queries to
-- install_dir = vim.fn.stdpath('data') .. '/site'
-- }
--
--
-- local ensureInstalled = {
-- "c",
-- "lua",
-- "vim",
-- "vimdoc",
-- "query",
-- "elixir",
-- "heex",
-- "javascript",
-- "html",
-- "markdown",
-- "markdown_inline",
-- "html",
-- "jsdoc",
-- "hurl",
-- "typescript",
-- "json"
-- }
-- local alreadyInstalled = require("nvim-treesitter.config").get_installed()
-- local parsersToInstall = vim.iter(ensureInstalled)
-- :filter(function(parser) return not vim.tbl_contains(alreadyInstalled, parser) end)
-- :totable()
-- require("nvim-treesitter").install(parsersToInstall)
--
-- vim.api.nvim_create_autocmd("FileType", {
-- desc = "User: enable treesitter highlighting",
-- callback = function(ctx)
-- -- highlights
-- local hasStarted = pcall(vim.treesitter.start) -- errors for filetypes with no parser
--
-- -- indent
-- local noIndent = {}
-- if hasStarted and not vim.list_contains(noIndent, ctx.match) then
-- vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
-- end
-- end,
-- })
2025-03-28 16:13:27 +00:00
require("nvim-treesitter.configs").setup({
2025-03-27 08:18:20 +00:00
ensure_installed = {
"c",
"lua",
"vim",
"vimdoc",
"query",
"elixir",
"heex",
"javascript",
"html",
"markdown",
"markdown_inline",
"html",
"jsdoc",
"hurl",
2025-03-27 12:48:32 +00:00
"typescript",
"json"
2025-03-27 08:18:20 +00:00
},
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
auto_install = true,
2025-03-28 16:13:27 +00:00
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
["as"] = { query = "@local.scope", query_group = "locals", desc = "Select language scope" },
["=a"] = { query = "@assignment.outer", desc = "Select outer part of an assignment" },
["=i"] = { query = "@assignment.inner", desc = "Select inner part of an assignment" },
["=l"] = { query = "@assignment.lhs", desc = "Select left hand side of an assignment" },
["=r"] = { query = "@assignment.rhs", desc = "Select right hand side of an assignment" },
2025-03-28 16:13:27 +00:00
["aa"] = { query = "@parameter.outer", desc = "Select outer part of a parameter/argument" },
["ia"] = { query = "@parameter.inner", desc = "Select inner part of a parameter/argument" },
["ai"] = { query = "@conditional.outer", desc = "Select outer part of a conditional" },
["ii"] = { query = "@conditional.inner", desc = "Select inner part of a conditional" },
["al"] = { query = "@loop.outer", desc = "Select outer part of a loop" },
["il"] = { query = "@loop.inner", desc = "Select inner part of a loop" },
["af"] = { query = "@call.outer", desc = "Select outer part of a function call" },
["if"] = { query = "@call.inner", desc = "Select inner part of a function call" },
["am"] = { query = "@function.outer", desc = "Select outer part of a method/function definition" },
["im"] = { query = "@function.inner", desc = "Select inner part of a method/function definition" },
["ac"] = { query = "@class.outer", desc = "Select outer part of a class" },
["ic"] = { query = "@class.inner", desc = "Select inner part of a class" },
},
-- You can choose the select mode (default is charwise 'v')
--
-- Can also be a function which gets passed a table with the keys
-- * query_string: eg '@function.inner'
-- * method: eg 'v' or 'o'
-- and should return the mode ('v', 'V', or '<c-v>') or a table
-- mapping query_strings to modes.
selection_modes = {
['@parameter.outer'] = 'v', -- charwise
['@function.outer'] = 'V', -- linewise
['@class.outer'] = '<c-v>', -- blockwise
},
-- If you set this to `true` (default is `false`) then any textobject is
-- extended to include preceding or succeeding whitespace. Succeeding
-- whitespace has priority in order to act similarly to eg the built-in
-- `ap`.
--
-- Can also be a function which gets passed a table with the keys
-- * query_string: eg '@function.inner'
-- * selection_mode: eg 'v'
-- and should return true or false
include_surrounding_whitespace = true,
}
2025-03-28 16:13:27 +00:00
},
2025-03-27 08:18:20 +00:00
})
end
}