nvim-snappy/lua/plugins/editing/treesitter.lua

254 lines
4.5 KiB
Lua

-- nvim-treesitter
--- Interface to the AST-level parser generator 'tree-sitter', enabling operations on source code that intelligently understand the syntax.
--- Out of the box, grammer-aware code highlighting, indentation, etc. .
--- Base for a lot of other plugins that rely on these kinds of features.
--- TODO: Look into extensions for:
--- * Text Objects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
--- As always, consult <http://www.lazyvim.org/plugins/treesitter>
return {
'nvim-treesitter/nvim-treesitter',
commit = 'cfc6f2c117aaaa82f19bcce44deec2c194d900ab',
dependencies = {
{
'nvim-treesitter/nvim-treesitter-textobjects',
commit = 'ad8f0a472148c3e0ae9851e26a722ee4e29b1595',
},
},
build = ':TSUpdate all', -- Update lang parsers unconditionally on build
lazy = vim.fn.argc(-1) == 0, -- Load early only when opening file w/cmdline
event = {
'VeryLazy',
},
cmd = {
"TSUpdateSync",
"TSUpdate",
"TSInstall",
},
init = function(plugin)
--- Many plugins apparently no longer require("nvim-treesitter").
--- This messes with the lazy-loading logic.
--- However, such plugins only otherwise use custom queries (seems to be called "RTP").
--- We therefore register treesitter w/RTP, so such queries will load treesitter.
require("lazy.core.loader").add_to_rtp(plugin)
require("nvim-treesitter.query_predicates")
end,
opts = {
-- Grammer-Aware Syntax Highlighting
highlight = {
enable = true
},
-- Grammer-Aware Indentation
--- TODO: EXPERIMENTAL - CAREFUL!
--indent = { enable = true },
textobjects = {
select = {
enable = true,
lookahead = false,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = {
query = "@function.outer",
desc = "Select [A]round [F]unction",
},
["if"] = {
query = "@function.inner",
desc = "Select [I]nside [F]unction",
},
["al"] = {
query = "@class.outer",
desc = "Select [A]round C[L]ass",
},
["il"] = {
query = "@class.outer",
desc = "Select [I]nside C[L]ass",
},
["ac"] = {
query = "@cell.outer",
desc = "Select [A]round [C]ell",
},
["ic"] = {
query = "@cell.inner",
desc = "Select [I]nside [C]ell",
},
},
},
move = {
enable = true,
set_jumps = true,
}
},
-- Always Install Parsers for Languages
ensure_installed = {
"ada",
"arduino",
"asm",
"awk",
"bash",
"bibtex",
"c",
"c_sharp",
"clojure",
"cmake",
"comment",
"commonlisp",
"cpp",
"css",
"csv",
"cuda",
"d",
"dart",
"diff",
"disassembly",
"dockerfile",
"dot",
"doxygen",
"dtd",
"editorconfig",
"eex",
"elixir",
"elm",
"erlang",
"fennel",
"fish",
"forth",
"fortran",
"fsh",
"fsharp",
"gap",
"gdscript",
"gdshader",
"git_config",
"git_rebase",
"gitattributes",
"gitcommit",
"gitignore",
"gleam",
"glsl",
"gnuplot",
"go",
"gpg",
"graphql",
"haskell",
"hcl",
"hlsl",
"hlsplaylist",
"html",
"htmldjango",
"hyprlang",
"ini",
"java",
"javascript",
"jq",
"jsdoc",
"json",
"json5",
"jsonc",
"jsonnet",
"julia",
"just",
"kconfig",
"kdl",
"latex",
"llvm",
"lua",
"luadoc",
"luap",
"luau",
"m68k",
"make",
"markdown",
"markdown_inline",
"matlab",
"meson",
"mlir",
"nasm",
"nginx",
"nix",
"objc",
"objdump",
"ocaml",
"pascal",
"pem",
"perl",
"php",
"phpdoc",
"po",
"pod",
"powershell",
"printf",
"prisma",
"prolog",
"promql",
"proto",
"puppet",
"pymanifest",
"python",
"qmldir",
"qmljs",
"r",
"readline",
"regex",
"requirements",
"robots",
"rst",
"ruby",
"rust",
"scala",
"scss",
"sflog",
"smithy",
"sql",
"ssh_config",
"starlark",
"strace",
"svelte",
"swift",
"t32",
"tablegen",
"tcl",
"teal",
"terraform",
"tmux",
"todotxt",
"toml",
"tsv",
"tsx",
"turtle",
"typescript",
"typespec",
"typst",
"udev",
"unison",
"usd",
"vala",
"verilog",
"vim",
"vimdoc",
"vue",
"wgsl",
"wgsl_bevy",
"xml",
"xresources",
"yaml",
"zathurarc",
"zig",
},
},
config = function(_, opts)
require('nvim-treesitter.configs').setup(opts)
-- Use Treesitter as the Folding Method
--vim.opt.foldmethod = "expr"
--vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
end,
}