From cf898d1fee783af3d5544834f637cef123e91216 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Sun, 12 Apr 2026 11:46:54 +0200 Subject: [PATCH] feat(treesitter): replace nvim-treesitter with pack-managed parsers --- after/lsp/lua_ls.lua | 2 +- init.lua | 131 +++++++- lua/core/commands.lua | 2 +- lua/pack.lua | 41 ++- lua/ts.lua | 159 +++++++++ nvim-pack-lock.json | 85 +++++ queries/apache-2.0.txt | 201 +++++++++++ queries/bash/folds.scm | 12 + queries/bash/highlights.scm | 281 ++++++++++++++++ queries/bash/indents.scm | 35 ++ queries/bash/injections.scm | 93 ++++++ queries/bash/locals.scm | 17 + queries/c/folds.scm | 26 ++ queries/c/highlights.scm | 344 +++++++++++++++++++ queries/c/indents.scm | 102 ++++++ queries/c/injections.scm | 131 ++++++++ queries/c/locals.scm | 70 ++++ queries/comment/highlights.scm | 52 +++ queries/cpp/folds.scm | 16 + queries/cpp/highlights.scm | 275 +++++++++++++++ queries/cpp/indents.scm | 10 + queries/cpp/injections.scm | 11 + queries/cpp/locals.scm | 80 +++++ queries/css/folds.scm | 13 + queries/css/highlights.scm | 112 +++++++ queries/css/indents.scm | 14 + queries/css/injections.scm | 5 + queries/dtd/folds.scm | 7 + queries/dtd/highlights.scm | 151 +++++++++ queries/dtd/injections.scm | 5 + queries/dtd/locals.scm | 14 + queries/ecma/folds.scm | 27 ++ queries/ecma/highlights.scm | 395 ++++++++++++++++++++++ queries/ecma/indents.scm | 85 +++++ queries/ecma/injections.scm | 222 +++++++++++++ queries/ecma/locals.scm | 54 +++ queries/gitcommit/highlights.scm | 52 +++ queries/gitcommit/injections.scm | 8 + queries/go/folds.scm | 22 ++ queries/go/highlights.scm | 249 ++++++++++++++ queries/go/indents.scm | 51 +++ queries/go/injections.scm | 45 +++ queries/go/locals.scm | 91 +++++ queries/gotmpl/folds.scm | 11 + queries/gotmpl/highlights.scm | 143 ++++++++ queries/gotmpl/injections.scm | 38 +++ queries/gotmpl/locals.scm | 15 + queries/html/folds.scm | 8 + queries/html/highlights.scm | 9 + queries/html/indents.scm | 3 + queries/html/injections.scm | 29 ++ queries/html/locals.scm | 4 + queries/html_tags/highlights.scm | 111 +++++++ queries/html_tags/indents.scm | 40 +++ queries/html_tags/injections.scm | 118 +++++++ queries/json/folds.scm | 8 + queries/json/highlights.scm | 43 +++ queries/json/indents.scm | 14 + queries/json/injections.scm | 5 + queries/json/locals.scm | 7 + queries/jsx/folds.scm | 4 + queries/jsx/highlights.scm | 160 +++++++++ queries/jsx/indents.scm | 24 ++ queries/jsx/injections.scm | 14 + queries/luadoc/highlights.scm | 200 +++++++++++ queries/python/folds.scm | 31 ++ queries/python/highlights.scm | 456 +++++++++++++++++++++++++ queries/python/indents.scm | 216 ++++++++++++ queries/python/injections.scm | 33 ++ queries/python/locals.scm | 127 +++++++ queries/rust/folds.scm | 28 ++ queries/rust/highlights.scm | 534 ++++++++++++++++++++++++++++++ queries/rust/indents.scm | 136 ++++++++ queries/rust/injections.scm | 92 +++++ queries/rust/locals.scm | 101 ++++++ queries/scss/folds.scm | 3 + queries/scss/highlights.scm | 89 +++++ queries/scss/indents.scm | 9 + queries/scss/injections.scm | 5 + queries/sql/folds.scm | 4 + queries/sql/highlights.scm | 462 ++++++++++++++++++++++++++ queries/sql/indents.scm | 32 ++ queries/sql/injections.scm | 8 + queries/svelte/folds.scm | 15 + queries/svelte/highlights.scm | 45 +++ queries/svelte/indents.scm | 36 ++ queries/svelte/injections.scm | 49 +++ queries/svelte/locals.scm | 3 + queries/typescript/folds.scm | 10 + queries/typescript/highlights.scm | 210 ++++++++++++ queries/typescript/indents.scm | 9 + queries/typescript/injections.scm | 30 ++ queries/typescript/locals.scm | 33 ++ queries/xml/folds.scm | 8 + queries/xml/highlights.scm | 201 +++++++++++ queries/xml/indents.scm | 19 ++ queries/xml/injections.scm | 35 ++ queries/xml/locals.scm | 38 +++ queries/yaml/folds.scm | 7 + queries/yaml/highlights.scm | 102 ++++++ queries/yaml/indents.scm | 10 + queries/yaml/injections.scm | 84 +++++ queries/yaml/locals.scm | 12 + queries/zsh/folds.scm | 12 + queries/zsh/highlights.scm | 329 ++++++++++++++++++ queries/zsh/injections.scm | 82 +++++ queries/zsh/locals.scm | 17 + 107 files changed, 8555 insertions(+), 13 deletions(-) create mode 100644 lua/ts.lua create mode 100644 queries/apache-2.0.txt create mode 100644 queries/bash/folds.scm create mode 100644 queries/bash/highlights.scm create mode 100644 queries/bash/indents.scm create mode 100644 queries/bash/injections.scm create mode 100644 queries/bash/locals.scm create mode 100644 queries/c/folds.scm create mode 100644 queries/c/highlights.scm create mode 100644 queries/c/indents.scm create mode 100644 queries/c/injections.scm create mode 100644 queries/c/locals.scm create mode 100644 queries/comment/highlights.scm create mode 100644 queries/cpp/folds.scm create mode 100644 queries/cpp/highlights.scm create mode 100644 queries/cpp/indents.scm create mode 100644 queries/cpp/injections.scm create mode 100644 queries/cpp/locals.scm create mode 100644 queries/css/folds.scm create mode 100644 queries/css/highlights.scm create mode 100644 queries/css/indents.scm create mode 100644 queries/css/injections.scm create mode 100644 queries/dtd/folds.scm create mode 100644 queries/dtd/highlights.scm create mode 100644 queries/dtd/injections.scm create mode 100644 queries/dtd/locals.scm create mode 100644 queries/ecma/folds.scm create mode 100644 queries/ecma/highlights.scm create mode 100644 queries/ecma/indents.scm create mode 100644 queries/ecma/injections.scm create mode 100644 queries/ecma/locals.scm create mode 100644 queries/gitcommit/highlights.scm create mode 100644 queries/gitcommit/injections.scm create mode 100644 queries/go/folds.scm create mode 100644 queries/go/highlights.scm create mode 100644 queries/go/indents.scm create mode 100644 queries/go/injections.scm create mode 100644 queries/go/locals.scm create mode 100644 queries/gotmpl/folds.scm create mode 100644 queries/gotmpl/highlights.scm create mode 100644 queries/gotmpl/injections.scm create mode 100644 queries/gotmpl/locals.scm create mode 100644 queries/html/folds.scm create mode 100644 queries/html/highlights.scm create mode 100644 queries/html/indents.scm create mode 100644 queries/html/injections.scm create mode 100644 queries/html/locals.scm create mode 100644 queries/html_tags/highlights.scm create mode 100644 queries/html_tags/indents.scm create mode 100644 queries/html_tags/injections.scm create mode 100644 queries/json/folds.scm create mode 100644 queries/json/highlights.scm create mode 100644 queries/json/indents.scm create mode 100644 queries/json/injections.scm create mode 100644 queries/json/locals.scm create mode 100644 queries/jsx/folds.scm create mode 100644 queries/jsx/highlights.scm create mode 100644 queries/jsx/indents.scm create mode 100644 queries/jsx/injections.scm create mode 100644 queries/luadoc/highlights.scm create mode 100644 queries/python/folds.scm create mode 100644 queries/python/highlights.scm create mode 100644 queries/python/indents.scm create mode 100644 queries/python/injections.scm create mode 100644 queries/python/locals.scm create mode 100644 queries/rust/folds.scm create mode 100644 queries/rust/highlights.scm create mode 100644 queries/rust/indents.scm create mode 100644 queries/rust/injections.scm create mode 100644 queries/rust/locals.scm create mode 100644 queries/scss/folds.scm create mode 100644 queries/scss/highlights.scm create mode 100644 queries/scss/indents.scm create mode 100644 queries/scss/injections.scm create mode 100644 queries/sql/folds.scm create mode 100644 queries/sql/highlights.scm create mode 100644 queries/sql/indents.scm create mode 100644 queries/sql/injections.scm create mode 100644 queries/svelte/folds.scm create mode 100644 queries/svelte/highlights.scm create mode 100644 queries/svelte/indents.scm create mode 100644 queries/svelte/injections.scm create mode 100644 queries/svelte/locals.scm create mode 100644 queries/typescript/folds.scm create mode 100644 queries/typescript/highlights.scm create mode 100644 queries/typescript/indents.scm create mode 100644 queries/typescript/injections.scm create mode 100644 queries/typescript/locals.scm create mode 100644 queries/xml/folds.scm create mode 100644 queries/xml/highlights.scm create mode 100644 queries/xml/indents.scm create mode 100644 queries/xml/injections.scm create mode 100644 queries/xml/locals.scm create mode 100644 queries/yaml/folds.scm create mode 100644 queries/yaml/highlights.scm create mode 100644 queries/yaml/indents.scm create mode 100644 queries/yaml/injections.scm create mode 100644 queries/yaml/locals.scm create mode 100644 queries/zsh/folds.scm create mode 100644 queries/zsh/highlights.scm create mode 100644 queries/zsh/injections.scm create mode 100644 queries/zsh/locals.scm diff --git a/after/lsp/lua_ls.lua b/after/lsp/lua_ls.lua index aa472b6..e149931 100644 --- a/after/lsp/lua_ls.lua +++ b/after/lsp/lua_ls.lua @@ -1,7 +1,7 @@ local lsp = require("lsp") local lua_library_paths = { vim.env.VIMRUNTIME } -vim.list_extend(lua_library_paths, require("pack").paths) +vim.list_extend(lua_library_paths, require("pack").get_paths()) ---@type vim.lsp.Config return { diff --git a/init.lua b/init.lua index 62098f4..f4061a4 100644 --- a/init.lua +++ b/init.lua @@ -21,6 +21,7 @@ for _, file in ipairs(files) do end end +local ts = require("ts") require("pack").setup({ "https://github.com/navarasu/onedark.nvim", "https://github.com/nvim-lua/plenary.nvim", @@ -40,7 +41,6 @@ require("pack").setup({ "https://github.com/owallb/mason-auto-install.nvim", "https://github.com/mfussenegger/nvim-dap", "https://github.com/igorlfs/nvim-dap-view", - "https://github.com/nvim-treesitter/nvim-treesitter", "https://github.com/numToStr/Comment.nvim", "https://github.com/j-hui/fidget.nvim", "https://github.com/rbong/vim-flog", @@ -50,4 +50,133 @@ require("pack").setup({ "https://github.com/nvim-tree/nvim-tree.lua", "https://github.com/stevearc/oil.nvim", "https://github.com/hedyhli/outline.nvim", + { + "https://github.com/tree-sitter/tree-sitter-bash", + ts_parser = "bash", + }, + -- required by cpp + { + "https://github.com/tree-sitter/tree-sitter-c", + ts_parser = "c", + }, + { + "https://github.com/stsewd/tree-sitter-comment", + ts_parser = "comment", + }, + { + "https://github.com/tree-sitter/tree-sitter-cpp", + ts_parser = "cpp", + }, + -- required by scss + { + "https://github.com/tree-sitter/tree-sitter-css", + ts_parser = "css", + }, + { + "https://github.com/gbprod/tree-sitter-gitcommit", + ts_parser = "gitcommit", + }, + { + "https://github.com/tree-sitter/tree-sitter-go", + ts_parser = "go", + }, + { + "https://github.com/ngalaiko/tree-sitter-go-template", + ts_parser = "gotmpl", + }, + { + "https://github.com/tree-sitter/tree-sitter-html", + ts_parser = "html", + }, + { + "https://github.com/tree-sitter/tree-sitter-json", + ts_parser = "json", + }, + { + "https://github.com/tree-sitter-grammars/tree-sitter-luadoc", + ts_parser = "luadoc", + }, + { + "https://github.com/tree-sitter/tree-sitter-php", + ts_parser = { + { lang = "php", location = "php" }, + { lang = "php_only", location = "php_only" }, + }, + }, + { + "https://github.com/tree-sitter/tree-sitter-python", + ts_parser = "python", + }, + { + "https://github.com/tree-sitter/tree-sitter-rust", + ts_parser = "rust", + }, + { + "https://github.com/serenadeai/tree-sitter-scss", + ts_parser = "scss", + }, + { + "https://github.com/derekstride/tree-sitter-sql", + version = "gh-pages", + ts_parser = "sql", + }, + { + "https://github.com/tree-sitter-grammars/tree-sitter-svelte", + ts_parser = "svelte", + }, + { + "https://github.com/tree-sitter/tree-sitter-typescript", + ts_parser = { + { lang = "typescript", location = "typescript" }, + { lang = "tsx", location = "tsx" }, + }, + }, + { + "https://github.com/tree-sitter-grammars/tree-sitter-xml", + ts_parser = { + { lang = "xml", location = "xml" }, + { lang = "dtd", location = "dtd" }, + }, + }, + { + "https://github.com/tree-sitter-grammars/tree-sitter-yaml", + ts_parser = "yaml", + }, + { + "https://github.com/georgeharker/tree-sitter-zsh", + ts_parser = "zsh", + }, +}) + +ts.setup({ + languages = { + "bash", + "c", -- builtin + "comment", + "cpp", + "css", + "gitcommit", + "go", + "gotmpl", + "html", + "json", + "lua", -- builtin + "luadoc", + "markdown", -- builtin + "markdown_inline", -- builtin + "php", + "python", + "query", -- builtin + "rust", + "scss", + "sql", + "svelte", + "tsx", + "typescript", + "vim", -- builtin + "vimdoc", -- builtin + "xml", + "yaml", + "zsh", + } }) diff --git a/lua/core/commands.lua b/lua/core/commands.lua index 83fd5c5..5514746 100644 --- a/lua/core/commands.lua +++ b/lua/core/commands.lua @@ -17,7 +17,7 @@ end, { complete = function(lead) return vim.tbl_filter(function(name) return name:find(lead, 1, true) == 1 - end, require("pack").names) + end, require("pack").get_names()) end, desc = "Reload a plugin config by name", }) diff --git a/lua/pack.lua b/lua/pack.lua index df102d8..4969d50 100644 --- a/lua/pack.lua +++ b/lua/pack.lua @@ -24,6 +24,7 @@ end ---@field name? string ---@field version? string | vim.VersionRange ---@field build? string[] | fun(self: ow.Pack.Plugin) +---@field ts_parser? ow.TS.ParserField ---@class ow.Pack.Plugin : ow.Pack.PluginSpec ---@field name string @@ -55,6 +56,7 @@ local function to_pack_spec(spec) version = spec.version, data = { build = spec.build, + ts_parser = spec.ts_parser, }, } end @@ -75,7 +77,15 @@ local function run_build(plugin) return end - log.error("invalid build parameter for %s", plugin.name) + log.error("Invalid build parameter for %s", plugin.name) +end + +---@param plugin ow.Pack.Plugin +local function run_ts_build(plugin) + local ts = require("ts") + for _, p in ipairs(ts.normalize(plugin.ts_parser)) do + ts.build(plugin, p) + end end ---@class ow.Pack.Event.Data @@ -90,7 +100,7 @@ end ---@param plugin ow.Pack.Plugin ---@param events ow.Pack.Event[] local function process_events(plugin, events) - if not plugin.build then + if not plugin.build and not plugin.ts_parser then return end @@ -99,7 +109,11 @@ local function process_events(plugin, events) and ev.event == "PackChanged" and (ev.data.kind == "install" or ev.data.kind == "update") then - run_build(plugin) + if plugin.ts_parser then + run_ts_build(plugin) + else + run_build(plugin) + end end end end @@ -111,15 +125,21 @@ local watcher = nil local timers = {} ---@class ow.Pack ----@field names string[] ----@field paths string[] ---@field plugins ow.Pack.Plugin[] local M = { - names = {}, - paths = {}, plugins = {}, } +---@return string[] +function M.get_names() + return vim.tbl_map(function(p) return p.name end, M.plugins) +end + +---@return string[] +function M.get_paths() + return vim.tbl_map(function(p) return p.path end, M.plugins) +end + ---@param name string function M.reload(name) local path = string.format("%s/lua/plugins/%s.lua", config_dir, name) @@ -247,12 +267,13 @@ function M.setup(specs) name = data.spec.name, version = data.spec.version, build = d.build, + ts_parser = d.ts_parser, path = data.path, } table.insert(M.plugins, plugin) - table.insert(M.names, plugin.name) - table.insert(M.paths, plugin.path) - vim.cmd.packadd(plugin.name) + if not d.ts_parser then + vim.cmd.packadd(plugin.name) + end end }) vim.api.nvim_del_autocmd(id) diff --git a/lua/ts.lua b/lua/ts.lua new file mode 100644 index 0000000..060136c --- /dev/null +++ b/lua/ts.lua @@ -0,0 +1,159 @@ +local log = require("log") + +local M = {} + +---@class ow.TS.ParserSpec +---@field lang string +---@field location? string +---@field generate? boolean +---@field from_json? boolean + +---@alias ow.TS.ParserField string | ow.TS.ParserSpec | ow.TS.ParserSpec[] + +---@param plugin ow.Pack.Plugin +---@param lang string +---@return string +local function parser_path(plugin, lang) + return vim.fs.joinpath(plugin.path, "parser", lang .. ".so") +end + +---@param buf integer +local function start_treesitter(buf) + local ok, err = pcall(vim.treesitter.start, buf) + if not ok then + log.error( + "Failed to enable treesitter for buffer %d: %s", + buf, + err + ) + return + end + for _, win in ipairs(vim.fn.win_findbuf(buf)) do + vim.wo[win].foldmethod = "expr" + vim.wo[win].foldexpr = "v:lua.vim.treesitter.foldexpr()" + end +end + +---@param lang string +local function activate_open_buffers(lang) + local fts = vim.treesitter.language.get_filetypes(lang) + for _, buf in ipairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_is_loaded(buf) + and vim.list_contains(fts, vim.bo[buf].filetype) + then + start_treesitter(buf) + end + end +end + +---@param plugin ow.Pack.Plugin +---@param spec ow.TS.ParserSpec +function M.build(plugin, spec) + local cwd = spec.location + and vim.fs.joinpath(plugin.path, spec.location) + or plugin.path + local out = parser_path(plugin, spec.lang) + vim.fn.mkdir(vim.fs.dirname(out), "p") + + local function on_build(r) + if r.code ~= 0 then + log.error( + "Failed to build parser for %s: %s", + spec.lang, + r.stderr or "" + ) + return + end + vim.treesitter.language.add(spec.lang, { path = out }) + activate_open_buffers(spec.lang) + end + + local function do_build() + vim.system( + { "tree-sitter", "build", "-o", out }, + { cwd = cwd }, + vim.schedule_wrap(on_build) + ) + end + + if spec.generate then + local cmd = { + "tree-sitter", "generate", + "--abi", tostring(vim.treesitter.language_version), + } + if spec.from_json ~= false then + table.insert(cmd, "src/grammar.json") + end + vim.system(cmd, { + cwd = cwd, + env = { TREE_SITTER_JS_RUNTIME = "native" }, + }, vim.schedule_wrap(function(r) + if r.code ~= 0 then + log.error( + "Failed to generate parser for %s: %s", + spec.lang, + r.stderr or "" + ) + return + end + do_build() + end)) + else + do_build() + end +end + +---@param field ow.TS.ParserField +---@return ow.TS.ParserSpec[] +function M.normalize(field) + if type(field) == "string" then + return { { lang = field } } + end + + if type(field) == "table" then + if type(field.lang) == "string" then + return { field } + end + if type(field[1]) == "table" then + return field + end + end + + error("invalid ts_parser value: " .. vim.inspect(field)) +end + +---@param languages string[] +local function collect_filetypes(languages) + local filetypes = {} + for _, lang in ipairs(languages) do + for _, ft in ipairs(vim.treesitter.language.get_filetypes(lang)) do + if not vim.list_contains(filetypes, ft) then + table.insert(filetypes, ft) + end + end + end + return filetypes +end + +---@param opts { languages: string[] } +function M.setup(opts) + for _, plugin in ipairs(require("pack").plugins) do + if plugin.ts_parser then + for _, p in ipairs(M.normalize(plugin.ts_parser)) do + local path = parser_path(plugin, p.lang) + if vim.uv.fs_stat(path) then + vim.treesitter.language.add(p.lang, { path = path }) + end + end + end + end + + vim.api.nvim_create_autocmd("FileType", { + pattern = collect_filetypes(opts.languages), + callback = function(ev) + start_treesitter(ev.buf) + end, + }) +end + +return M diff --git a/nvim-pack-lock.json b/nvim-pack-lock.json index ecebd8c..f4be95e 100644 --- a/nvim-pack-lock.json +++ b/nvim-pack-lock.json @@ -85,6 +85,91 @@ "rev": "7ef4d6dccb78ee71e552bbd866176762ad328afa", "src": "https://github.com/nvim-telescope/telescope.nvim" }, + "tree-sitter-bash": { + "rev": "a06c2e4415e9bc0346c6b86d401879ffb44058f7", + "src": "https://github.com/tree-sitter/tree-sitter-bash" + }, + "tree-sitter-c": { + "rev": "ae19b676b13bdcc13b7665397e6d9b14975473dd", + "src": "https://github.com/tree-sitter/tree-sitter-c" + }, + "tree-sitter-comment": { + "rev": "66272d2b6c73fb61157541b69dd0a7ce7b42a5ad", + "src": "https://github.com/stsewd/tree-sitter-comment" + }, + "tree-sitter-cpp": { + "rev": "8b5b49eb196bec7040441bee33b2c9a4838d6967", + "src": "https://github.com/tree-sitter/tree-sitter-cpp" + }, + "tree-sitter-css": { + "rev": "dda5cfc5722c429eaba1c910ca32c2c0c5bb1a3f", + "src": "https://github.com/tree-sitter/tree-sitter-css" + }, + "tree-sitter-gitcommit": { + "rev": "33fe8548abcc6e374feaac5724b5a2364bf23090", + "src": "https://github.com/gbprod/tree-sitter-gitcommit" + }, + "tree-sitter-go": { + "rev": "2346a3ab1bb3857b48b29d779a1ef9799a248cd7", + "src": "https://github.com/tree-sitter/tree-sitter-go" + }, + "tree-sitter-go-template": { + "rev": "aa71f63de226c5592dfbfc1f29949522d7c95fac", + "src": "https://github.com/ngalaiko/tree-sitter-go-template" + }, + "tree-sitter-html": { + "rev": "73a3947324f6efddf9e17c0ea58d454843590cc0", + "src": "https://github.com/tree-sitter/tree-sitter-html" + }, + "tree-sitter-json": { + "rev": "001c28d7a29832b06b0e831ec77845553c89b56d", + "src": "https://github.com/tree-sitter/tree-sitter-json" + }, + "tree-sitter-luadoc": { + "rev": "873612aadd3f684dd4e631bdf42ea8990c57634e", + "src": "https://github.com/tree-sitter-grammars/tree-sitter-luadoc" + }, + "tree-sitter-php": { + "rev": "3f2465c217d0a966d41e584b42d75522f2a3149e", + "src": "https://github.com/tree-sitter/tree-sitter-php" + }, + "tree-sitter-python": { + "rev": "26855eabccb19c6abf499fbc5b8dc7cc9ab8bc64", + "src": "https://github.com/tree-sitter/tree-sitter-python" + }, + "tree-sitter-rust": { + "rev": "77a3747266f4d621d0757825e6b11edcbf991ca5", + "src": "https://github.com/tree-sitter/tree-sitter-rust" + }, + "tree-sitter-scss": { + "rev": "c478c6868648eff49eb04a4df90d703dc45b312a", + "src": "https://github.com/serenadeai/tree-sitter-scss" + }, + "tree-sitter-sql": { + "rev": "851e9cb257ba7c66cc8c14214a31c44d2f1e954e", + "src": "https://github.com/derekstride/tree-sitter-sql", + "version": "'gh-pages'" + }, + "tree-sitter-svelte": { + "rev": "ae5199db47757f785e43a14b332118a5474de1a2", + "src": "https://github.com/tree-sitter-grammars/tree-sitter-svelte" + }, + "tree-sitter-typescript": { + "rev": "75b3874edb2dc714fb1fd77a32013d0f8699989f", + "src": "https://github.com/tree-sitter/tree-sitter-typescript" + }, + "tree-sitter-xml": { + "rev": "5000ae8f22d11fbe93939b05c1e37cf21117162d", + "src": "https://github.com/tree-sitter-grammars/tree-sitter-xml" + }, + "tree-sitter-yaml": { + "rev": "4463985dfccc640f3d6991e3396a2047610cf5f8", + "src": "https://github.com/tree-sitter-grammars/tree-sitter-yaml" + }, + "tree-sitter-zsh": { + "rev": "484e2889f3619b9da90c9b73a6f216a71947c09f", + "src": "https://github.com/georgeharker/tree-sitter-zsh" + }, "vim-flog": { "rev": "665b16ac8915f746bc43c9572b4581a5e9047216", "src": "https://github.com/rbong/vim-flog" diff --git a/queries/apache-2.0.txt b/queries/apache-2.0.txt new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/queries/apache-2.0.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/queries/bash/folds.scm b/queries/bash/folds.scm new file mode 100644 index 0000000..586ec7a --- /dev/null +++ b/queries/bash/folds.scm @@ -0,0 +1,12 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (function_definition) + (if_statement) + (case_statement) + (for_statement) + (while_statement) + (c_style_for_statement) + (heredoc_redirect) +] @fold diff --git a/queries/bash/highlights.scm b/queries/bash/highlights.scm new file mode 100644 index 0000000..06dec83 --- /dev/null +++ b/queries/bash/highlights.scm @@ -0,0 +1,281 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + "(" + ")" + "{" + "}" + "[" + "]" + "[[" + "]]" + "((" + "))" +] @punctuation.bracket + +[ + ";" + ";;" + ";&" + ";;&" + "&" +] @punctuation.delimiter + +[ + ">" + ">>" + "<" + "<<" + "&&" + "|" + "|&" + "||" + "=" + "+=" + "=~" + "==" + "!=" + "&>" + "&>>" + "<&" + ">&" + ">|" + "<&-" + ">&-" + "<<-" + "<<<" + ".." + "!" +] @operator + +; Do *not* spell check strings since they typically have some sort of +; interpolation in them, or, are typically used for things like filenames, URLs, +; flags and file content. +[ + (string) + (raw_string) + (ansi_c_string) + (heredoc_body) +] @string + +[ + (heredoc_start) + (heredoc_end) +] @label + +(variable_assignment + (word) @string) + +(command + argument: "$" @string) ; bare dollar + +(concatenation + (word) @string) + +[ + "if" + "then" + "else" + "elif" + "fi" + "case" + "in" + "esac" +] @keyword.conditional + +[ + "for" + "do" + "done" + "select" + "until" + "while" +] @keyword.repeat + +[ + "declare" + "typeset" + "readonly" + "local" + "unset" + "unsetenv" +] @keyword + +"export" @keyword.import + +"function" @keyword.function + +(special_variable_name) @constant + +(comment) @comment @spell + +(test_operator) @operator + +(command_substitution + "$(" @punctuation.special + ")" @punctuation.special) + +(process_substitution + [ + "<(" + ">(" + ] @punctuation.special + ")" @punctuation.special) + +(arithmetic_expansion + [ + "$((" + "((" + ] @punctuation.special + "))" @punctuation.special) + +(arithmetic_expansion + "," @punctuation.delimiter) + +(ternary_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(binary_expression + operator: _ @operator) + +(unary_expression + operator: _ @operator) + +(postfix_expression + operator: _ @operator) + +(function_definition + name: (word) @function) + +(command_name + (word) @function.call) + +(command_name + (word) @function.builtin + (#any-of? @function.builtin + "." ":" "alias" "bg" "bind" "break" "builtin" "caller" "cd" "command" "compgen" "complete" + "compopt" "continue" "coproc" "dirs" "disown" "echo" "enable" "eval" "exec" "exit" "false" "fc" + "fg" "getopts" "hash" "help" "history" "jobs" "kill" "let" "logout" "mapfile" "popd" "printf" + "pushd" "pwd" "read" "readarray" "return" "set" "shift" "shopt" "source" "suspend" "test" "time" + "times" "trap" "true" "type" "typeset" "ulimit" "umask" "unalias" "wait")) + +(command + argument: [ + (word) @variable.parameter + (concatenation + (word) @variable.parameter) + ]) + +; help trap +(command + name: (command_name + (word) @_command) + argument: (word) @string.special + (#eq? @_command "trap") + (#any-of? @string.special "EXIT" "DEBUG" "RETURN" "ERR")) + +; trap -l +(command + name: (command_name + (word) @_command) + argument: (word) @string.special + (#any-of? @_command "trap" "kill") + (#any-of? @string.special + "SIGHUP" "SIGINT" "SIGQUIT" "SIGILL" "SIGTRAP" "SIGABRT" "SIGBUS" "SIGFPE" "SIGKILL" "SIGUSR1" + "SIGSEGV" "SIGUSR2" "SIGPIPE" "SIGALRM" "SIGTERM" "SIGSTKFLT" "SIGCHLD" "SIGCONT" "SIGSTOP" + "SIGTSTP" "SIGTTIN" "SIGTTOU" "SIGURG" "SIGXCPU" "SIGXFSZ" "SIGVTALRM" "SIGPROF" "SIGWINCH" + "SIGIO" "SIGPWR" "SIGSYS" "SIGRTMIN" "SIGRTMIN+1" "SIGRTMIN+2" "SIGRTMIN+3" "SIGRTMIN+4" + "SIGRTMIN+5" "SIGRTMIN+6" "SIGRTMIN+7" "SIGRTMIN+8" "SIGRTMIN+9" "SIGRTMIN+10" "SIGRTMIN+11" + "SIGRTMIN+12" "SIGRTMIN+13" "SIGRTMIN+14" "SIGRTMIN+15" "SIGRTMAX-14" "SIGRTMAX-13" + "SIGRTMAX-12" "SIGRTMAX-11" "SIGRTMAX-10" "SIGRTMAX-9" "SIGRTMAX-8" "SIGRTMAX-7" "SIGRTMAX-6" + "SIGRTMAX-5" "SIGRTMAX-4" "SIGRTMAX-3" "SIGRTMAX-2" "SIGRTMAX-1" "SIGRTMAX")) + +(declaration_command + (word) @variable.parameter) + +(unset_command + (word) @variable.parameter) + +(number) @number + +(file_redirect + (word) @string.special.path) + +(herestring_redirect + (word) @string) + +(file_descriptor) @operator + +(simple_expansion + "$" @punctuation.special) @none + +(expansion + "${" @punctuation.special + "}" @punctuation.special) @none + +(expansion + operator: _ @punctuation.special) + +(expansion + "@" + . + operator: _ @character.special) + +((expansion + (subscript + index: (word) @character.special)) + (#any-of? @character.special "@" "*")) + +"``" @punctuation.special + +(variable_name) @variable + +((variable_name) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + +((variable_name) @variable.builtin + (#any-of? @variable.builtin + ; https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Variables.html + "CDPATH" "HOME" "IFS" "MAIL" "MAILPATH" "OPTARG" "OPTIND" "PATH" "PS1" "PS2" + ; https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html + "_" "BASH" "BASHOPTS" "BASHPID" "BASH_ALIASES" "BASH_ARGC" "BASH_ARGV" "BASH_ARGV0" "BASH_CMDS" + "BASH_COMMAND" "BASH_COMPAT" "BASH_ENV" "BASH_EXECUTION_STRING" "BASH_LINENO" + "BASH_LOADABLES_PATH" "BASH_REMATCH" "BASH_SOURCE" "BASH_SUBSHELL" "BASH_VERSINFO" + "BASH_VERSION" "BASH_XTRACEFD" "CHILD_MAX" "COLUMNS" "COMP_CWORD" "COMP_LINE" "COMP_POINT" + "COMP_TYPE" "COMP_KEY" "COMP_WORDBREAKS" "COMP_WORDS" "COMPREPLY" "COPROC" "DIRSTACK" "EMACS" + "ENV" "EPOCHREALTIME" "EPOCHSECONDS" "EUID" "EXECIGNORE" "FCEDIT" "FIGNORE" "FUNCNAME" + "FUNCNEST" "GLOBIGNORE" "GROUPS" "histchars" "HISTCMD" "HISTCONTROL" "HISTFILE" "HISTFILESIZE" + "HISTIGNORE" "HISTSIZE" "HISTTIMEFORMAT" "HOSTFILE" "HOSTNAME" "HOSTTYPE" "IGNOREEOF" "INPUTRC" + "INSIDE_EMACS" "LANG" "LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES" "LC_NUMERIC" "LC_TIME" + "LINENO" "LINES" "MACHTYPE" "MAILCHECK" "MAPFILE" "OLDPWD" "OPTERR" "OSTYPE" "PIPESTATUS" + "POSIXLY_CORRECT" "PPID" "PROMPT_COMMAND" "PROMPT_DIRTRIM" "PS0" "PS3" "PS4" "PWD" "RANDOM" + "READLINE_ARGUMENT" "READLINE_LINE" "READLINE_MARK" "READLINE_POINT" "REPLY" "SECONDS" "SHELL" + "SHELLOPTS" "SHLVL" "SRANDOM" "TIMEFORMAT" "TMOUT" "TMPDIR" "UID")) + +((command + name: (command_name + (word) @_printf) + . + argument: (word) @_v + . + argument: (word) @variable) + (#eq? @_printf "printf") + (#eq? @_v "-v") + (#lua-match? @variable "^[a-zA-Z_][a-zA-Z0-9_]*$")) + +(case_item + value: (word) @variable.parameter) + +[ + (regex) + (extglob_pattern) +] @string.regexp + +((program + . + (comment) @keyword.directive @nospell) + (#lua-match? @keyword.directive "^#![ \t]*/")) diff --git a/queries/bash/indents.scm b/queries/bash/indents.scm new file mode 100644 index 0000000..ac3e2af --- /dev/null +++ b/queries/bash/indents.scm @@ -0,0 +1,35 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (if_statement) + (for_statement) + (while_statement) + (case_statement) + (function_definition) + (compound_statement) + (subshell) + (command_substitution) + (do_group) + (case_item) +] @indent.begin + +[ + "fi" + "done" + "esac" + "}" + ")" + "then" + "do" + (elif_clause) + (else_clause) +] @indent.branch + +[ + "fi" + "done" + "esac" + "}" + ")" +] @indent.end diff --git a/queries/bash/injections.scm b/queries/bash/injections.scm new file mode 100644 index 0000000..364a572 --- /dev/null +++ b/queries/bash/injections.scm @@ -0,0 +1,93 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((comment) @injection.content + (#set! injection.language "comment")) + +((regex) @injection.content + (#set! injection.language "regex")) + +(heredoc_redirect + (heredoc_body) @injection.content + (heredoc_end) @injection.language) + +; printf 'format' +((command + name: (command_name) @_command + . + argument: [ + (string) @injection.content + (concatenation + (string) @injection.content) + (raw_string) @injection.content + (concatenation + (raw_string) @injection.content) + ]) + (#eq? @_command "printf") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "printf")) + +; printf -v var 'format' +((command + name: (command_name) @_command + argument: (word) @_arg + . + (_) + . + argument: [ + (string) @injection.content + (concatenation + (string) @injection.content) + (raw_string) @injection.content + (concatenation + (raw_string) @injection.content) + ]) + (#eq? @_command "printf") + (#eq? @_arg "-v") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "printf")) + +; printf -- 'format' +((command + name: (command_name) @_command + argument: (word) @_arg + . + argument: [ + (string) @injection.content + (concatenation + (string) @injection.content) + (raw_string) @injection.content + (concatenation + (raw_string) @injection.content) + ]) + (#eq? @_command "printf") + (#eq? @_arg "--") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "printf")) + +((command + name: (command_name) @_command + . + argument: [ + (string) + (raw_string) + ] @injection.content) + (#eq? @_command "bind") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "readline")) + +((command + name: (command_name) @_command + . + argument: [ + (string) + (raw_string) + ] @injection.content) + (#eq? @_command "trap") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.self)) diff --git a/queries/bash/locals.scm b/queries/bash/locals.scm new file mode 100644 index 0000000..02b48fb --- /dev/null +++ b/queries/bash/locals.scm @@ -0,0 +1,17 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +; Scopes +(function_definition) @local.scope + +; Definitions +(variable_assignment + name: (variable_name) @local.definition.var) + +(function_definition + name: (word) @local.definition.function) + +; References +(variable_name) @local.reference + +(word) @local.reference diff --git a/queries/c/folds.scm b/queries/c/folds.scm new file mode 100644 index 0000000..e27ba09 --- /dev/null +++ b/queries/c/folds.scm @@ -0,0 +1,26 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (for_statement) + (if_statement) + (while_statement) + (do_statement) + (switch_statement) + (case_statement) + (function_definition) + (struct_specifier) + (enum_specifier) + (comment) + (preproc_if) + (preproc_elif) + (preproc_else) + (preproc_ifdef) + (preproc_function_def) + (initializer_list) + (gnu_asm_expression) + (preproc_include)+ +] @fold + +(compound_statement + (compound_statement) @fold) diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm new file mode 100644 index 0000000..35f0401 --- /dev/null +++ b/queries/c/highlights.scm @@ -0,0 +1,344 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration. +((identifier) @variable + (#set! priority 95)) + +(preproc_def + (preproc_arg) @variable) + +[ + "default" + "goto" + "asm" + "__asm__" +] @keyword + +[ + "enum" + "struct" + "union" + "typedef" +] @keyword.type + +[ + "sizeof" + "offsetof" +] @keyword.operator + +(alignof_expression + . + _ @keyword.operator) + +"return" @keyword.return + +[ + "while" + "for" + "do" + "continue" + "break" +] @keyword.repeat + +[ + "if" + "else" + "case" + "switch" +] @keyword.conditional + +[ + "#if" + "#ifdef" + "#ifndef" + "#else" + "#elif" + "#endif" + "#elifdef" + "#elifndef" + (preproc_directive) +] @keyword.directive + +"#define" @keyword.directive.define + +"#include" @keyword.import + +[ + ";" + ":" + "," + "." + "::" +] @punctuation.delimiter + +"..." @punctuation.special + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "=" + "-" + "*" + "/" + "+" + "%" + "~" + "|" + "&" + "^" + "<<" + ">>" + "->" + "<" + "<=" + ">=" + ">" + "==" + "!=" + "!" + "&&" + "||" + "-=" + "+=" + "*=" + "/=" + "%=" + "|=" + "&=" + "^=" + ">>=" + "<<=" + "--" + "++" +] @operator + +; Make sure the comma operator is given a highlight group after the comma +; punctuator so the operator is highlighted properly. +(comma_expression + "," @operator) + +[ + (true) + (false) +] @boolean + +(conditional_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(string_literal) @string + +(system_lib_string) @string + +(escape_sequence) @string.escape + +(null) @constant.builtin + +(number_literal) @number + +(char_literal) @character + +(preproc_defined) @function.macro + +((field_expression + (field_identifier) @property) @_parent + (#not-has-parent? @_parent function_declarator call_expression)) + +(field_designator) @property + +((field_identifier) @property + (#has-ancestor? @property field_declaration) + (#not-has-ancestor? @property function_declarator)) + +(statement_identifier) @label + +(declaration + type: (type_identifier) @_type + declarator: (identifier) @label + (#eq? @_type "__label__")) + +[ + (type_identifier) + (type_descriptor) +] @type + +(storage_class_specifier) @keyword.modifier + +[ + (type_qualifier) + (gnu_asm_qualifier) + "__extension__" +] @keyword.modifier + +(linkage_specification + "extern" @keyword.modifier) + +(type_definition + declarator: (type_identifier) @type.definition) + +(primitive_type) @type.builtin + +(sized_type_specifier + _ @type.builtin + type: _?) + +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + +(preproc_def + (preproc_arg) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + +(enumerator + name: (identifier) @constant) + +(case_statement + value: (identifier) @constant) + +((identifier) @constant.builtin + ; format-ignore + (#any-of? @constant.builtin + "stderr" "stdin" "stdout" + "__FILE__" "__LINE__" "__DATE__" "__TIME__" + "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__" + "__cplusplus" "__OBJC__" "__ASSEMBLER__" + "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__" + "__TIMESTAMP__" "__clang__" "__clang_major__" + "__clang_minor__" "__clang_patchlevel__" + "__clang_version__" "__clang_literal_encoding__" + "__clang_wide_literal_encoding__" + "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" + "__VA_ARGS__" "__VA_OPT__")) + +(preproc_def + (preproc_arg) @constant.builtin + ; format-ignore + (#any-of? @constant.builtin + "stderr" "stdin" "stdout" + "__FILE__" "__LINE__" "__DATE__" "__TIME__" + "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__" + "__cplusplus" "__OBJC__" "__ASSEMBLER__" + "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__" + "__TIMESTAMP__" "__clang__" "__clang_major__" + "__clang_minor__" "__clang_patchlevel__" + "__clang_version__" "__clang_literal_encoding__" + "__clang_wide_literal_encoding__" + "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" + "__VA_ARGS__" "__VA_OPT__")) + +(attribute_specifier + (argument_list + (identifier) @variable.builtin)) + +(attribute_specifier + (argument_list + (call_expression + function: (identifier) @variable.builtin))) + +((call_expression + function: (identifier) @function.builtin) + (#lua-match? @function.builtin "^__builtin_")) + +((call_expression + function: (identifier) @function.builtin) + (#has-ancestor? @function.builtin attribute_specifier)) + +; Preproc def / undef +(preproc_def + name: (_) @constant.macro) + +(preproc_call + directive: (preproc_directive) @_u + argument: (_) @constant.macro + (#eq? @_u "#undef")) + +(preproc_ifdef + name: (identifier) @constant.macro) + +(preproc_elifdef + name: (identifier) @constant.macro) + +(preproc_defined + (identifier) @constant.macro) + +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (field_expression + field: (field_identifier) @function.call)) + +(function_declarator + declarator: (identifier) @function) + +(function_declarator + declarator: (parenthesized_declarator + (pointer_declarator + declarator: (field_identifier) @function))) + +(preproc_function_def + name: (identifier) @function.macro) + +(comment) @comment @spell + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) + +; Parameters +(parameter_declaration + declarator: (identifier) @variable.parameter) + +(parameter_declaration + declarator: (array_declarator) @variable.parameter) + +(parameter_declaration + declarator: (pointer_declarator) @variable.parameter) + +; K&R functions +; To enable support for K&R functions, +; add the following lines to your own query config and uncomment them. +; They are commented out as they'll conflict with C++ +; Note that you'll need to have `; extends` at the top of your query file. +; +; (parameter_list (identifier) @variable.parameter) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (identifier) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (array_declarator) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (pointer_declarator) @variable.parameter)) +(preproc_params + (identifier) @variable.parameter) + +[ + "__attribute__" + "__declspec" + "__based" + "__cdecl" + "__clrcall" + "__stdcall" + "__fastcall" + "__thiscall" + "__vectorcall" + (ms_pointer_modifier) + (attribute_declaration) +] @attribute diff --git a/queries/c/indents.scm b/queries/c/indents.scm new file mode 100644 index 0000000..6bc3217 --- /dev/null +++ b/queries/c/indents.scm @@ -0,0 +1,102 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (compound_statement) + (field_declaration_list) + (case_statement) + (enumerator_list) + (compound_literal_expression) + (initializer_list) + (init_declarator) +] @indent.begin + +; With current indent logic, if we capture expression_statement with @indent.begin +; It will be affected by _parent_ node with error subnodes deep down the tree +; So narrow indent capture to check for error inside expression statement only, +(expression_statement + (_) @indent.begin + ";" @indent.end) + +(ERROR + "for" + "(" @indent.begin + ";" + ";" + ")" @indent.end) + +((for_statement + body: (_) @_body) @indent.begin + (#not-kind-eq? @_body "compound_statement")) + +(while_statement + condition: (_) @indent.begin) + +((while_statement + body: (_) @_body) @indent.begin + (#not-kind-eq? @_body "compound_statement")) + +((if_statement) + . + (ERROR + "else" @indent.begin)) + +(if_statement + condition: (_) @indent.begin) + +; Supports if without braces (but not both if-else without braces) +(if_statement + consequence: (_ + ";" @indent.end) @_consequence + (#not-kind-eq? @_consequence "compound_statement") + alternative: (else_clause + "else" @indent.branch + [ + (if_statement + (compound_statement) @indent.dedent)? @indent.dedent + (compound_statement)? @indent.dedent + (_)? @indent.dedent + ])?) @indent.begin + +(else_clause + (_ + . + "{" @indent.branch)) + +(compound_statement + "}" @indent.end) + +[ + ")" + "}" + (statement_identifier) +] @indent.branch + +[ + "#define" + "#ifdef" + "#ifndef" + "#elif" + "#if" + "#else" + "#endif" +] @indent.zero + +[ + (preproc_arg) + (string_literal) +] @indent.ignore + +((ERROR + (parameter_declaration)) @indent.align + (#set! indent.open_delimiter "(") + (#set! indent.close_delimiter ")")) + +([ + (argument_list) + (parameter_list) +] @indent.align + (#set! indent.open_delimiter "(") + (#set! indent.close_delimiter ")")) + +(comment) @indent.auto diff --git a/queries/c/injections.scm b/queries/c/injections.scm new file mode 100644 index 0000000..a880d34 --- /dev/null +++ b/queries/c/injections.scm @@ -0,0 +1,131 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((preproc_arg) @injection.content + (#set! injection.self)) + +((comment) @injection.content + (#set! injection.language "comment")) + +((comment) @injection.content + (#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c") + (#set! injection.language "re2c")) + +((comment) @injection.content + (#lua-match? @injection.content "/[*/][!*/]" @operator + +"::" @punctuation.delimiter + +(template_argument_list + [ + "<" + ">" + ] @punctuation.bracket) + +(template_parameter_list + [ + "<" + ">" + ] @punctuation.bracket) + +(literal_suffix) @operator diff --git a/queries/cpp/indents.scm b/queries/cpp/indents.scm new file mode 100644 index 0000000..b03d7af --- /dev/null +++ b/queries/cpp/indents.scm @@ -0,0 +1,10 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) +; inherits: c + +(condition_clause) @indent.begin + +((field_initializer_list) @indent.begin + (#set! indent.start_at_same_line 1)) + +(access_specifier) @indent.branch diff --git a/queries/cpp/injections.scm b/queries/cpp/injections.scm new file mode 100644 index 0000000..86ac225 --- /dev/null +++ b/queries/cpp/injections.scm @@ -0,0 +1,11 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) +; inherits: c + +((comment) @injection.content + (#lua-match? @injection.content "/[*/][!*/] +(type_parameter_declaration + (type_identifier) @local.definition.type) + +(template_declaration) @local.scope + +; Namespaces +(namespace_definition + name: (namespace_identifier) @local.definition.namespace + body: (_) @local.scope) + +(namespace_definition + name: (nested_namespace_specifier) @local.definition.namespace + body: (_) @local.scope) + +((namespace_identifier) @local.reference + (#set! reference.kind "namespace")) + +; Function definitions +(template_function + name: (identifier) @local.definition.function) @local.scope + +(template_method + name: (field_identifier) @local.definition.method) @local.scope + +(function_declarator + declarator: (qualified_identifier + name: (identifier) @local.definition.function)) @local.scope + +(field_declaration + declarator: (function_declarator + (field_identifier) @local.definition.method)) + +(lambda_expression) @local.scope + +; Control structures +(try_statement + body: (_) @local.scope) + +(catch_clause) @local.scope + +(requires_expression) @local.scope diff --git a/queries/css/folds.scm b/queries/css/folds.scm new file mode 100644 index 0000000..9979559 --- /dev/null +++ b/queries/css/folds.scm @@ -0,0 +1,13 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + ; top-level block statements from https://github.com/tree-sitter/tree-sitter-css/blob/master/grammar.js + ; note: (block) is not used due to unideal behavior when node before block node spans multiple lines + (rule_set) + (at_rule) + (supports_statement) + (media_statement) + (keyframe_block) + (import_statement)+ +] @fold diff --git a/queries/css/highlights.scm b/queries/css/highlights.scm new file mode 100644 index 0000000..75f9fd7 --- /dev/null +++ b/queries/css/highlights.scm @@ -0,0 +1,112 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + "@media" + "@charset" + "@namespace" + "@supports" + "@keyframes" + (at_keyword) +] @keyword.directive + +"@import" @keyword.import + +[ + (to) + (from) +] @keyword + +(comment) @comment @spell + +(tag_name) @tag + +(class_name) @type + +(id_name) @constant + +[ + (property_name) + (feature_name) +] @property + +(function_name) @function + +[ + "~" + ">" + "+" + "-" + "*" + "/" + "=" + "^=" + "|=" + "~=" + "$=" + "*=" +] @operator + +[ + "and" + "or" + "not" + "only" +] @keyword.operator + +(important) @keyword.modifier + +[ + (nesting_selector) + (universal_selector) +] @character.special + +(attribute_selector + (plain_value) @string) + +(pseudo_element_selector + "::" + (tag_name) @attribute) + +(pseudo_class_selector + (class_name) @attribute) + +(attribute_name) @tag.attribute + +(namespace_name) @module + +(keyframes_name) @variable + +((property_name) @variable + (#lua-match? @variable "^[-][-]")) + +((plain_value) @variable + (#lua-match? @variable "^[-][-]")) + +[ + (string_value) + (color_value) + (unit) +] @string + +(integer_value) @number + +(float_value) @number.float + +[ + "#" + "," + "." + ":" + "::" + ";" +] @punctuation.delimiter + +[ + "{" + ")" + "(" + "}" + "[" + "]" +] @punctuation.bracket diff --git a/queries/css/indents.scm b/queries/css/indents.scm new file mode 100644 index 0000000..a282745 --- /dev/null +++ b/queries/css/indents.scm @@ -0,0 +1,14 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (block) + (declaration) +] @indent.begin + +(block + "}" @indent.branch) + +"}" @indent.dedent + +(comment) @indent.ignore diff --git a/queries/css/injections.scm b/queries/css/injections.scm new file mode 100644 index 0000000..fe41f1a --- /dev/null +++ b/queries/css/injections.scm @@ -0,0 +1,5 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((comment) @injection.content + (#set! injection.language "comment")) diff --git a/queries/dtd/folds.scm b/queries/dtd/folds.scm new file mode 100644 index 0000000..e62f6a2 --- /dev/null +++ b/queries/dtd/folds.scm @@ -0,0 +1,7 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (conditionalSect) + (Comment) +] @fold diff --git a/queries/dtd/highlights.scm b/queries/dtd/highlights.scm new file mode 100644 index 0000000..6c66bc6 --- /dev/null +++ b/queries/dtd/highlights.scm @@ -0,0 +1,151 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +; Text declaration +(TextDecl + "xml" @keyword.directive) + +(TextDecl + [ + "version" + "encoding" + ] @tag.attribute) + +(TextDecl + (EncName) @string.special) + +(TextDecl + (VersionNum) @number) + +; Processing instructions +(PI) @keyword.directive + +; Element declaration +(elementdecl + "ELEMENT" @keyword.directive.define + (Name) @tag) + +(contentspec + (_ + (Name) @tag.attribute)) + +"#PCDATA" @type.builtin + +[ + "EMPTY" + "ANY" +] @keyword.modifier + +[ + "*" + "?" + "+" +] @character.special + +; Entity declaration +(GEDecl + "ENTITY" @keyword.directive.define + (Name) @constant) + +(GEDecl + (EntityValue) @string) + +(NDataDecl + "NDATA" @keyword + (Name) @label) + +; Parsed entity declaration +(PEDecl + "ENTITY" @keyword.directive.define + "%" @operator + (Name) @function.macro) + +(PEDecl + (EntityValue) @string) + +; Notation declaration +(NotationDecl + "NOTATION" @keyword.directive + (Name) @label) + +; Attlist declaration +(AttlistDecl + "ATTLIST" @keyword.directive.define + (Name) @tag) + +(AttDef + (Name) @tag.attribute) + +(AttDef + (Enumeration + (Nmtoken) @string)) + +[ + (StringType) + (TokenizedType) +] @type.builtin + +(NotationType + "NOTATION" @type.builtin) + +[ + "#REQUIRED" + "#IMPLIED" + "#FIXED" +] @attribute + +; Entities +(EntityRef) @constant + +((EntityRef) @constant.builtin + (#any-of? @constant.builtin "&" "<" ">" """ "'")) + +(CharRef) @character + +(PEReference) @function.macro + +; External references +[ + "PUBLIC" + "SYSTEM" +] @keyword + +(PubidLiteral) @string.special + +(SystemLiteral + (URI) @string.special.url) + +; Delimiters & punctuation +[ + "" + "" + "" +] @tag.delimiter + +[ + "(" + ")" + "[" +] @punctuation.bracket + +[ + "\"" + "'" +] @punctuation.delimiter + +[ + "," + "|" + "=" +] @operator + +; Misc +[ + "INCLUDE" + "IGNORE" +] @keyword.import + +(Comment) @comment @spell diff --git a/queries/dtd/injections.scm b/queries/dtd/injections.scm new file mode 100644 index 0000000..9ccd793 --- /dev/null +++ b/queries/dtd/injections.scm @@ -0,0 +1,5 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((Comment) @injection.content + (#set! injection.language "comment")) diff --git a/queries/dtd/locals.scm b/queries/dtd/locals.scm new file mode 100644 index 0000000..b514d05 --- /dev/null +++ b/queries/dtd/locals.scm @@ -0,0 +1,14 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +(elementdecl + (Name) @local.definition.type) + +(elementdecl + (contentspec + (children + (Name) @local.reference))) + +(AttlistDecl + . + (Name) @local.reference) diff --git a/queries/ecma/folds.scm b/queries/ecma/folds.scm new file mode 100644 index 0000000..4d65c8d --- /dev/null +++ b/queries/ecma/folds.scm @@ -0,0 +1,27 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (arguments) + (for_in_statement) + (for_statement) + (while_statement) + (arrow_function) + (function_expression) + (function_declaration) + (class_declaration) + (method_definition) + (do_statement) + (with_statement) + (switch_statement) + (switch_case) + (switch_default) + (import_statement)+ + (if_statement) + (try_statement) + (catch_clause) + (array) + (object) + (generator_function) + (generator_function_declaration) +] @fold diff --git a/queries/ecma/highlights.scm b/queries/ecma/highlights.scm new file mode 100644 index 0000000..e082691 --- /dev/null +++ b/queries/ecma/highlights.scm @@ -0,0 +1,395 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +; Types +; Javascript +; Variables +;----------- +(identifier) @variable + +; Properties +;----------- +(property_identifier) @variable.member + +(shorthand_property_identifier) @variable.member + +(private_property_identifier) @variable.member + +(object_pattern + (shorthand_property_identifier_pattern) @variable) + +(object_pattern + (object_assignment_pattern + (shorthand_property_identifier_pattern) @variable)) + +; Special identifiers +;-------------------- +((identifier) @type + (#lua-match? @type "^[A-Z]")) + +((identifier) @constant + (#lua-match? @constant "^_*[A-Z][A-Z%d_]*$")) + +((shorthand_property_identifier) @constant + (#lua-match? @constant "^_*[A-Z][A-Z%d_]*$")) + +((identifier) @variable.builtin + (#any-of? @variable.builtin "arguments" "module" "console" "window" "document")) + +((identifier) @type.builtin + (#any-of? @type.builtin + "Object" "Function" "Boolean" "Symbol" "Number" "Math" "Date" "String" "RegExp" "Map" "Set" + "WeakMap" "WeakSet" "Promise" "Array" "Int8Array" "Uint8Array" "Uint8ClampedArray" "Int16Array" + "Uint16Array" "Int32Array" "Uint32Array" "Float32Array" "Float64Array" "ArrayBuffer" "DataView" + "Error" "EvalError" "InternalError" "RangeError" "ReferenceError" "SyntaxError" "TypeError" + "URIError")) + +(statement_identifier) @label + +; Function and method definitions +;-------------------------------- +(function_expression + name: (identifier) @function) + +(function_declaration + name: (identifier) @function) + +(generator_function + name: (identifier) @function) + +(generator_function_declaration + name: (identifier) @function) + +(method_definition + name: [ + (property_identifier) + (private_property_identifier) + ] @function.method) + +(method_definition + name: (property_identifier) @constructor + (#eq? @constructor "constructor")) + +(pair + key: (property_identifier) @function.method + value: (function_expression)) + +(pair + key: (property_identifier) @function.method + value: (arrow_function)) + +(assignment_expression + left: (member_expression + property: (property_identifier) @function.method) + right: (arrow_function)) + +(assignment_expression + left: (member_expression + property: (property_identifier) @function.method) + right: (function_expression)) + +(variable_declarator + name: (identifier) @function + value: (arrow_function)) + +(variable_declarator + name: (identifier) @function + value: (function_expression)) + +(assignment_expression + left: (identifier) @function + right: (arrow_function)) + +(assignment_expression + left: (identifier) @function + right: (function_expression)) + +; Function and method calls +;-------------------------- +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (member_expression + property: [ + (property_identifier) + (private_property_identifier) + ] @function.method.call)) + +(call_expression + function: (await_expression + (identifier) @function.call)) + +(call_expression + function: (await_expression + (member_expression + property: [ + (property_identifier) + (private_property_identifier) + ] @function.method.call))) + +; Builtins +;--------- +((identifier) @module.builtin + (#eq? @module.builtin "Intl")) + +((identifier) @function.builtin + (#any-of? @function.builtin + "eval" "isFinite" "isNaN" "parseFloat" "parseInt" "decodeURI" "decodeURIComponent" "encodeURI" + "encodeURIComponent" "require")) + +; Constructor +;------------ +(new_expression + constructor: (identifier) @constructor) + +; Decorators +;---------- +(decorator + "@" @attribute + (identifier) @attribute) + +(decorator + "@" @attribute + (call_expression + (identifier) @attribute)) + +(decorator + "@" @attribute + (member_expression + (property_identifier) @attribute)) + +(decorator + "@" @attribute + (call_expression + (member_expression + (property_identifier) @attribute))) + +; Literals +;--------- +[ + (this) + (super) +] @variable.builtin + +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) + +[ + (true) + (false) +] @boolean + +[ + (null) + (undefined) +] @constant.builtin + +[ + (comment) + (html_comment) +] @comment @spell + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) + +(hash_bang_line) @keyword.directive + +((string_fragment) @keyword.directive + (#eq? @keyword.directive "use strict")) + +(string) @string + +(template_string) @string + +(escape_sequence) @string.escape + +(regex_pattern) @string.regexp + +(regex_flags) @character.special + +(regex + "/" @punctuation.bracket) ; Regex delimiters + +(number) @number + +((identifier) @number + (#any-of? @number "NaN" "Infinity")) + +; Punctuation +;------------ +[ + ";" + "." + "," + ":" +] @punctuation.delimiter + +[ + "--" + "-" + "-=" + "&&" + "+" + "++" + "+=" + "&=" + "/=" + "**=" + "<<=" + "<" + "<=" + "<<" + "=" + "==" + "===" + "!=" + "!==" + "=>" + ">" + ">=" + ">>" + "||" + "%" + "%=" + "*" + "**" + ">>>" + "&" + "|" + "^" + "??" + "*=" + ">>=" + ">>>=" + "^=" + "|=" + "&&=" + "||=" + "??=" + "..." +] @operator + +(binary_expression + "/" @operator) + +(ternary_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(unary_expression + [ + "!" + "~" + "-" + "+" + ] @operator) + +(unary_expression + [ + "delete" + "void" + ] @keyword.operator) + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(template_substitution + [ + "${" + "}" + ] @punctuation.special) @none + +; Imports +;---------- +(namespace_import + "*" @character.special + (identifier) @module) + +(namespace_export + "*" @character.special + (identifier) @module) + +(export_statement + "*" @character.special) + +; Keywords +;---------- +[ + "if" + "else" + "switch" + "case" +] @keyword.conditional + +[ + "import" + "from" + "as" + "export" +] @keyword.import + +[ + "for" + "of" + "do" + "while" + "continue" +] @keyword.repeat + +[ + "break" + "const" + "debugger" + "extends" + "get" + "let" + "set" + "static" + "target" + "var" + "with" +] @keyword + +"class" @keyword.type + +[ + "async" + "await" +] @keyword.coroutine + +[ + "return" + "yield" +] @keyword.return + +"function" @keyword.function + +[ + "new" + "delete" + "in" + "instanceof" + "typeof" +] @keyword.operator + +[ + "throw" + "try" + "catch" + "finally" +] @keyword.exception + +(export_statement + "default" @keyword) + +(switch_default + "default" @keyword.conditional) diff --git a/queries/ecma/indents.scm b/queries/ecma/indents.scm new file mode 100644 index 0000000..cd78ed6 --- /dev/null +++ b/queries/ecma/indents.scm @@ -0,0 +1,85 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (arguments) + (array) + (binary_expression) + (class_body) + (export_clause) + (formal_parameters) + (named_imports) + (object) + (object_pattern) + (parenthesized_expression) + (return_statement) + (statement_block) + (switch_case) + (switch_default) + (switch_statement) + (template_substitution) + (ternary_expression) +] @indent.begin + +(arguments + (call_expression) @indent.begin) + +(binary_expression + (call_expression) @indent.begin) + +(expression_statement + (call_expression) @indent.begin) + +(arrow_function + body: (_) @_body + (#not-kind-eq? @_body "statement_block")) @indent.begin + +(assignment_expression + right: (_) @_right + (#not-kind-eq? @_right "arrow_function")) @indent.begin + +(variable_declarator + value: (_) @_value + (#not-kind-eq? @_value "arrow_function" "call_expression")) @indent.begin + +(arguments + ")" @indent.end) + +(object + "}" @indent.end) + +(statement_block + "}" @indent.end) + +[ + (arguments + (object)) + ")" + "}" + "]" +] @indent.branch + +(statement_block + "{" @indent.branch) + +((parenthesized_expression + "(" + (_) + ")" @indent.end) @_outer + (#not-has-parent? @_outer if_statement)) + +[ + "}" + "]" +] @indent.end + +(template_string) @indent.ignore + +[ + (comment) + (ERROR) +] @indent.auto + +(if_statement + consequence: (_) @indent.dedent + (#not-kind-eq? @indent.dedent statement_block)) @indent.begin diff --git a/queries/ecma/injections.scm b/queries/ecma/injections.scm new file mode 100644 index 0000000..c43fa81 --- /dev/null +++ b/queries/ecma/injections.scm @@ -0,0 +1,222 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +(((comment) @_jsdoc_comment + (#lua-match? @_jsdoc_comment "^/[*][*][^*].*[*]/$")) @injection.content + (#set! injection.language "jsdoc")) + +((comment) @injection.content + (#set! injection.language "comment")) + +; html(`...`), html`...`, sql(`...`), etc. +(call_expression + function: (identifier) @injection.language + arguments: [ + (arguments + (template_string) @injection.content) + (template_string) @injection.content + ] + (#lua-match? @injection.language "^[a-zA-Z][a-zA-Z0-9]*$") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + ; Languages excluded from auto-injection due to special rules + ; - svg uses the html parser + ; - css uses the styled parser + (#not-any-of? @injection.language "svg" "css")) + +; svg`...` or svg(`...`) +(call_expression + function: (identifier) @_name + (#eq? @_name "svg") + arguments: [ + (arguments + (template_string) @injection.content) + (template_string) @injection.content + ] + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "html")) + +; Vercel PostgreSQL +; foo.sql`...` or foo.sql(`...`) +(call_expression + function: (member_expression + property: (property_identifier) @injection.language) + arguments: [ + (arguments + (template_string) @injection.content) + (template_string) @injection.content + ] + (#eq? @injection.language "sql") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children)) + +; Sanity CMS GROQ query +; defineQuery(`...`) +(call_expression + function: (identifier) @_name + (#eq? @_name "defineQuery") + arguments: (arguments + (template_string) @injection.content) + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "groq")) + +; gql`...` or gql(`...`) +(call_expression + function: (identifier) @_name + (#eq? @_name "gql") + arguments: [ + (arguments + (template_string) @injection.content) + (template_string) @injection.content + ] + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "graphql")) + +(call_expression + function: (identifier) @_name + (#eq? @_name "hbs") + arguments: (template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "glimmer")) + +; css``, keyframes`` +(call_expression + function: (identifier) @_name + (#any-of? @_name "css" "keyframes") + arguments: (template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled")) + +; styled.div`` +(call_expression + function: (member_expression + object: (identifier) @_name + (#eq? @_name "styled")) + arguments: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled"))) + +; styled(Component)`` +(call_expression + function: (call_expression + function: (identifier) @_name + (#eq? @_name "styled")) + arguments: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled"))) + +; styled.div.attrs({ prop: "foo" })`` +(call_expression + function: (call_expression + function: (member_expression + object: (member_expression + object: (identifier) @_name + (#eq? @_name "styled")))) + arguments: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled"))) + +; styled(Component).attrs({ prop: "foo" })`` +(call_expression + function: (call_expression + function: (member_expression + object: (call_expression + function: (identifier) @_name + (#eq? @_name "styled")))) + arguments: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled"))) + +((regex_pattern) @injection.content + (#set! injection.language "regex")) + +; ((comment) @_gql_comment +; (#eq? @_gql_comment "/* GraphQL */") +; (template_string) @injection.content +; (#set! injection.language "graphql")) +((template_string) @injection.content + (#lua-match? @injection.content "^`#graphql") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "graphql")) + +; el.innerHTML = `` +(assignment_expression + left: (member_expression + property: (property_identifier) @_prop + (#any-of? @_prop "outerHTML" "innerHTML")) + right: (template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "html")) + +; el.innerHTML = '' +(assignment_expression + left: (member_expression + property: (property_identifier) @_prop + (#any-of? @_prop "outerHTML" "innerHTML")) + right: (string + (string_fragment) @injection.content) + (#set! injection.language "html")) + +;---- Angular injections ----- +; @Component({ +; template: `` +; }) +(decorator + (call_expression + function: ((identifier) @_name + (#eq? @_name "Component")) + arguments: (arguments + (object + (pair + key: ((property_identifier) @_prop + (#eq? @_prop "template")) + value: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "angular"))))))) + +; @Component({ +; styles: [``] +; }) +(decorator + (call_expression + function: ((identifier) @_name + (#eq? @_name "Component")) + arguments: (arguments + (object + (pair + key: ((property_identifier) @_prop + (#eq? @_prop "styles")) + value: (array + ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "css")))))))) + +; @Component({ +; styles: `` +; }) +(decorator + (call_expression + function: ((identifier) @_name + (#eq? @_name "Component")) + arguments: (arguments + (object + (pair + key: ((property_identifier) @_prop + (#eq? @_prop "styles")) + value: ((template_string) @injection.content + (#set! injection.include-children) + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "css"))))))) diff --git a/queries/ecma/locals.scm b/queries/ecma/locals.scm new file mode 100644 index 0000000..f0c82e3 --- /dev/null +++ b/queries/ecma/locals.scm @@ -0,0 +1,54 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +; Scopes +;------- +(statement_block) @local.scope + +(function_expression) @local.scope + +(arrow_function) @local.scope + +(function_declaration) @local.scope + +(method_definition) @local.scope + +(for_statement) @local.scope + +(for_in_statement) @local.scope + +(catch_clause) @local.scope + +; Definitions +;------------ +(variable_declarator + name: (identifier) @local.definition.var) + +(variable_declarator + name: (object_pattern + (shorthand_property_identifier_pattern) @local.definition.var)) + +(variable_declarator + (object_pattern + (pair_pattern + (identifier) @local.definition.var))) + +(import_specifier + (identifier) @local.definition.import) + +(namespace_import + (identifier) @local.definition.import) + +(function_declaration + (identifier) @local.definition.function + (#set! definition.var.scope parent)) + +(method_definition + (property_identifier) @local.definition.function + (#set! definition.var.scope parent)) + +; References +;------------ +(identifier) @local.reference + +(shorthand_property_identifier) @local.reference diff --git a/queries/gitcommit/highlights.scm b/queries/gitcommit/highlights.scm new file mode 100644 index 0000000..b933f53 --- /dev/null +++ b/queries/gitcommit/highlights.scm @@ -0,0 +1,52 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +(comment) @comment + +(generated_comment) @comment + +(title) @markup.heading + +; (text) @none +(branch) @markup.link + +(change) @keyword + +(filepath) @string.special.path + +(arrow) @punctuation.delimiter + +(subject) @markup.heading @spell + +(subject + (subject_prefix) @function @nospell) + +(prefix + (type) @keyword @nospell) + +(prefix + (scope) @variable.parameter @nospell) + +(prefix + [ + "(" + ")" + ":" + ] @punctuation.delimiter) + +(prefix + "!" @punctuation.special) + +(message) @spell + +(trailer + (token) @label) + +; (trailer (value) @none) +(breaking_change + (token) @comment.error) + +(breaking_change + (value) @none @spell) + +(scissor) @comment diff --git a/queries/gitcommit/injections.scm b/queries/gitcommit/injections.scm new file mode 100644 index 0000000..ad16614 --- /dev/null +++ b/queries/gitcommit/injections.scm @@ -0,0 +1,8 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((diff) @injection.content + (#set! injection.language "diff")) + +((rebase_command) @injection.content + (#set! injection.language "git_rebase")) diff --git a/queries/go/folds.scm b/queries/go/folds.scm new file mode 100644 index 0000000..85c434f --- /dev/null +++ b/queries/go/folds.scm @@ -0,0 +1,22 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (const_declaration) + (expression_switch_statement) + (expression_case) + (default_case) + (type_switch_statement) + (type_case) + (for_statement) + (func_literal) + (function_declaration) + (if_statement) + (import_declaration) + (method_declaration) + (type_declaration) + (var_declaration) + (composite_literal) + (literal_element) + (block) +] @fold diff --git a/queries/go/highlights.scm b/queries/go/highlights.scm new file mode 100644 index 0000000..0251f3b --- /dev/null +++ b/queries/go/highlights.scm @@ -0,0 +1,249 @@ +; Forked from tree-sitter-go +; Copyright (c) 2014 Max Brunsfeld (The MIT License) +; +; Identifiers +(type_identifier) @type + +(type_spec + name: (type_identifier) @type.definition) + +(field_identifier) @property + +(identifier) @variable + +(package_identifier) @module + +(parameter_declaration + (identifier) @variable.parameter) + +(variadic_parameter_declaration + (identifier) @variable.parameter) + +(label_name) @label + +(const_spec + name: (identifier) @constant) + +; Function calls +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (selector_expression + field: (field_identifier) @function.method.call)) + +; Function definitions +(function_declaration + name: (identifier) @function) + +(method_declaration + name: (field_identifier) @function.method) + +(method_elem + name: (field_identifier) @function.method) + +; Constructors +((call_expression + (identifier) @constructor) + (#lua-match? @constructor "^[nN]ew.+$")) + +((call_expression + (identifier) @constructor) + (#lua-match? @constructor "^[mM]ake.+$")) + +; Operators +[ + "--" + "-" + "-=" + ":=" + "!" + "!=" + "..." + "*" + "*=" + "/" + "/=" + "&" + "&&" + "&=" + "&^" + "&^=" + "%" + "%=" + "^" + "^=" + "+" + "++" + "+=" + "<-" + "<" + "<<" + "<<=" + "<=" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "|" + "|=" + "||" + "~" +] @operator + +; Keywords +[ + "break" + "const" + "continue" + "default" + "defer" + "goto" + "range" + "select" + "var" + "fallthrough" +] @keyword + +[ + "type" + "struct" + "interface" +] @keyword.type + +"func" @keyword.function + +"return" @keyword.return + +"go" @keyword.coroutine + +"for" @keyword.repeat + +[ + "import" + "package" +] @keyword.import + +[ + "else" + "case" + "switch" + "if" +] @keyword.conditional + +; Builtin types +[ + "chan" + "map" +] @type.builtin + +((type_identifier) @type.builtin + (#any-of? @type.builtin + "any" "bool" "byte" "comparable" "complex128" "complex64" "error" "float32" "float64" "int" + "int16" "int32" "int64" "int8" "rune" "string" "uint" "uint16" "uint32" "uint64" "uint8" + "uintptr")) + +; Builtin functions +((identifier) @function.builtin + (#any-of? @function.builtin + "append" "cap" "clear" "close" "complex" "copy" "delete" "imag" "len" "make" "max" "min" "new" + "panic" "print" "println" "real" "recover")) + +; Delimiters +[ + "." + "," + ":" + ";" +] @punctuation.delimiter + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +; Literals +(interpreted_string_literal) @string + +(raw_string_literal) @string + +(rune_literal) @character + +(escape_sequence) @string.escape + +(int_literal) @number + +(float_literal) @number.float + +(imaginary_literal) @number + +[ + (true) + (false) +] @boolean + +[ + (nil) + (iota) +] @constant.builtin + +(keyed_element + . + (literal_element + (identifier) @variable.member)) + +(field_declaration + name: (field_identifier) @variable.member) + +; Comments +(comment) @comment @spell + +; Doc Comments +(source_file + . + (comment)+ @comment.documentation) + +(source_file + (comment)+ @comment.documentation + . + (const_declaration)) + +(source_file + (comment)+ @comment.documentation + . + (function_declaration)) + +(source_file + (comment)+ @comment.documentation + . + (type_declaration)) + +(source_file + (comment)+ @comment.documentation + . + (var_declaration)) + +; Spell +((interpreted_string_literal) @spell + (#not-has-parent? @spell import_spec)) + +; Regex +(call_expression + (selector_expression) @_function + (#any-of? @_function + "regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX" + "regexp.MustCompile" "regexp.MustCompilePOSIX") + (argument_list + . + [ + (raw_string_literal + (raw_string_literal_content) @string.regexp) + (interpreted_string_literal + (interpreted_string_literal_content) @string.regexp) + ])) diff --git a/queries/go/indents.scm b/queries/go/indents.scm new file mode 100644 index 0000000..d5fcb3b --- /dev/null +++ b/queries/go/indents.scm @@ -0,0 +1,51 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (import_declaration) + (const_declaration) + (var_declaration) + (type_declaration) + (func_literal) + (literal_value) + (expression_case) + (communication_case) + (type_case) + (default_case) + (block) + (call_expression) + (parameter_list) + (field_declaration_list) + (interface_type) +] @indent.begin + +(literal_value + "}" @indent.branch) + +(block + "}" @indent.branch) + +(field_declaration_list + "}" @indent.branch) + +(interface_type + "}" @indent.branch) + +(const_declaration + ")" @indent.branch) + +(import_spec_list + ")" @indent.branch) + +(var_spec_list + ")" @indent.branch) + +[ + "}" + ")" +] @indent.end + +(parameter_list + ")" @indent.branch) + +(comment) @indent.ignore diff --git a/queries/go/injections.scm b/queries/go/injections.scm new file mode 100644 index 0000000..649a56b --- /dev/null +++ b/queries/go/injections.scm @@ -0,0 +1,45 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((comment) @injection.content + (#set! injection.language "comment")) + +(call_expression + (selector_expression) @_function + (#any-of? @_function + "regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX" + "regexp.MustCompile" "regexp.MustCompilePOSIX") + (argument_list + . + [ + (raw_string_literal + (raw_string_literal_content) @injection.content) + (interpreted_string_literal + (interpreted_string_literal_content) @injection.content) + ] + (#set! injection.language "regex"))) + +((comment) @injection.content + (#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c") + (#set! injection.language "re2c")) + +((call_expression + function: (selector_expression + field: (field_identifier) @_method) + arguments: (argument_list + . + (interpreted_string_literal + (interpreted_string_literal_content) @injection.content))) + (#any-of? @_method "Printf" "Sprintf" "Fatalf" "Scanf" "Errorf" "Skipf" "Logf") + (#set! injection.language "printf")) + +((call_expression + function: (selector_expression + field: (field_identifier) @_method) + arguments: (argument_list + (_) + . + (interpreted_string_literal + (interpreted_string_literal_content) @injection.content))) + (#any-of? @_method "Fprintf" "Fscanf" "Appendf" "Sscanf") + (#set! injection.language "printf")) diff --git a/queries/go/locals.scm b/queries/go/locals.scm new file mode 100644 index 0000000..9d312b6 --- /dev/null +++ b/queries/go/locals.scm @@ -0,0 +1,91 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((function_declaration + name: (identifier) @local.definition.function) ; @function + ) + +((method_declaration + name: (field_identifier) @local.definition.method) ; @function.method + ) + +(short_var_declaration + left: (expression_list + (identifier) @local.definition.var)) + +(var_spec + name: (identifier) @local.definition.var) + +(parameter_declaration + (identifier) @local.definition.var) + +(variadic_parameter_declaration + (identifier) @local.definition.var) + +(for_statement + (range_clause + left: (expression_list + (identifier) @local.definition.var))) + +(const_declaration + (const_spec + name: (identifier) @local.definition.var)) + +(type_declaration + (type_spec + name: (type_identifier) @local.definition.type)) + +; reference +(identifier) @local.reference + +(type_identifier) @local.reference + +(field_identifier) @local.reference + +((package_identifier) @local.reference + (#set! reference.kind "namespace")) + +(package_clause + (package_identifier) @local.definition.namespace) + +(import_spec_list + (import_spec + name: (package_identifier) @local.definition.namespace)) + +; Call references +((call_expression + function: (identifier) @local.reference) + (#set! reference.kind "call")) + +((call_expression + function: (selector_expression + field: (field_identifier) @local.reference)) + (#set! reference.kind "call")) + +((call_expression + function: (parenthesized_expression + (identifier) @local.reference)) + (#set! reference.kind "call")) + +((call_expression + function: (parenthesized_expression + (selector_expression + field: (field_identifier) @local.reference))) + (#set! reference.kind "call")) + +; Scopes +(func_literal) @local.scope + +(source_file) @local.scope + +(function_declaration) @local.scope + +(if_statement) @local.scope + +(block) @local.scope + +(expression_switch_statement) @local.scope + +(for_statement) @local.scope + +(method_declaration) @local.scope diff --git a/queries/gotmpl/folds.scm b/queries/gotmpl/folds.scm new file mode 100644 index 0000000..4bea6e5 --- /dev/null +++ b/queries/gotmpl/folds.scm @@ -0,0 +1,11 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (if_action) + (range_action) + (block_action) + (with_action) + (define_action) + (comment) +] @fold diff --git a/queries/gotmpl/highlights.scm b/queries/gotmpl/highlights.scm new file mode 100644 index 0000000..b23d909 --- /dev/null +++ b/queries/gotmpl/highlights.scm @@ -0,0 +1,143 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +; Priorities of the highlight queries are raised, so that they overrule the +; often surrounding and overlapping highlights from the non-gotmpl injections. +; +; Identifiers +([ + (field) + (field_identifier) +] @variable.member + (#set! priority 110)) + +((variable) @variable + (#set! priority 110)) + +; Function calls +(function_call + function: (identifier) @function + (#set! priority 110)) + +(method_call + method: (selector_expression + field: (field_identifier) @function + (#set! priority 110))) + +; Builtin functions +(function_call + function: (identifier) @function.builtin + (#set! priority 110) + (#any-of? @function.builtin + "and" "call" "html" "index" "slice" "js" "len" "not" "or" "print" "printf" "println" "urlquery" + "eq" "ne" "lt" "ge" "gt" "ge")) + +; Operators +([ + "|" + "=" + ":=" +] @operator + (#set! priority 110)) + +; Delimiters +([ + "." + "," +] @punctuation.delimiter + (#set! priority 110)) + +([ + "{{" + "}}" + "{{-" + "-}}" + ")" + "(" +] @punctuation.bracket + (#set! priority 110)) + +; Actions +(if_action + [ + "if" + "else" + "end" + ] @keyword.conditional + (#set! priority 110)) + +(range_action + [ + "range" + "else" + "end" + ] @keyword.repeat + (#set! priority 110)) + +(template_action + "template" @function.builtin + (#set! priority 110)) + +(block_action + [ + "block" + "end" + ] @keyword.directive + (#set! priority 110)) + +(define_action + [ + "define" + "end" + ] @keyword.directive.define + (#set! priority 110)) + +(with_action + [ + "with" + "else" + "end" + ] @keyword.conditional + (#set! priority 110)) + +(continue_action + "continue" @keyword.repeat + (#set! priority 110)) + +(break_action + "break" @keyword.repeat + (#set! priority 110)) + +; Literals +([ + (interpreted_string_literal) + (raw_string_literal) +] @string + (#set! priority 110)) + +((rune_literal) @string.special.symbol + (#set! priority 110)) + +((escape_sequence) @string.escape + (#set! priority 110)) + +([ + (int_literal) + (imaginary_literal) +] @number + (#set! priority 110)) + +((float_literal) @number.float + (#set! priority 110)) + +([ + (true) + (false) +] @boolean + (#set! priority 110)) + +((nil) @constant.builtin + (#set! priority 110)) + +((comment) @comment @spell + (#set! priority 110)) diff --git a/queries/gotmpl/injections.scm b/queries/gotmpl/injections.scm new file mode 100644 index 0000000..a0f0716 --- /dev/null +++ b/queries/gotmpl/injections.scm @@ -0,0 +1,38 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((comment) @injection.content + (#set! injection.language "comment")) + +; {{"put" | printf "%s%s" "out" | printf "%q"}} +(function_call + function: (identifier) @_function + arguments: (argument_list + . + (interpreted_string_literal) @injection.content) + (#eq? @_function "printf") + (#set! injection.language "printf")) + +; {{ js "var a = 1 + 1" }} +(function_call + function: (identifier) @_function + arguments: (argument_list + . + (interpreted_string_literal) @injection.content) + (#eq? @_function "js") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "javascript")) + +; {{ html "

hello

" }} +(function_call + function: (identifier) @_function + arguments: (argument_list + . + (interpreted_string_literal) @injection.content) + (#eq? @_function "html") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "html")) + +((text) @injection.content + (#set! injection.language "html") + (#set! injection.combined)) diff --git a/queries/gotmpl/locals.scm b/queries/gotmpl/locals.scm new file mode 100644 index 0000000..48d21e0 --- /dev/null +++ b/queries/gotmpl/locals.scm @@ -0,0 +1,15 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (if_action) + (range_action) + (block_action) + (with_action) + (define_action) +] @local.scope + +(variable_definition + variable: (variable) @local.definition.var) + +(variable) @local.reference diff --git a/queries/html/folds.scm b/queries/html/folds.scm new file mode 100644 index 0000000..07bc280 --- /dev/null +++ b/queries/html/folds.scm @@ -0,0 +1,8 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +[ + (element) + (style_element) + (script_element) +] @fold diff --git a/queries/html/highlights.scm b/queries/html/highlights.scm new file mode 100644 index 0000000..aa94385 --- /dev/null +++ b/queries/html/highlights.scm @@ -0,0 +1,9 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) +; inherits: html_tags + +(doctype) @constant + +"" + "" +] @tag.delimiter + +"=" @operator diff --git a/queries/html_tags/indents.scm b/queries/html_tags/indents.scm new file mode 100644 index 0000000..4fdc0ef --- /dev/null +++ b/queries/html_tags/indents.scm @@ -0,0 +1,40 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((element + (start_tag + (tag_name) @_not_void_element)) + (#not-any-of? @_not_void_element + "area" "base" "basefont" "bgsound" "br" "col" "command" "embed" "frame" "hr" "image" "img" + "input" "isindex" "keygen" "link" "menuitem" "meta" "nextid" "param" "source" "track" "wbr")) @indent.begin + +(element + (self_closing_tag)) @indent.begin + +((start_tag + (tag_name) @_void_element) + (#any-of? @_void_element + "area" "base" "basefont" "bgsound" "br" "col" "command" "embed" "frame" "hr" "image" "img" + "input" "isindex" "keygen" "link" "menuitem" "meta" "nextid" "param" "source" "track" "wbr")) @indent.begin + +; These are the nodes that will be captured when we do `normal o` +; But last element has already been ended, so capturing this +; to mark end of last element +(element + (end_tag + ">" @indent.end)) + +(element + (self_closing_tag + "/>" @indent.end)) + +; Script/style elements aren't indented, so only branch the end tag of other elements +(element + (end_tag) @indent.branch) + +[ + ">" + "/>" +] @indent.branch + +(comment) @indent.ignore diff --git a/queries/html_tags/injections.scm b/queries/html_tags/injections.scm new file mode 100644 index 0000000..a52beb0 --- /dev/null +++ b/queries/html_tags/injections.scm @@ -0,0 +1,118 @@ +; SPDX-License-Identifier: Apache-2.0 +; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter) + +((comment) @injection.content + (#set! injection.language "comment")) + +; +; +; Add "lang" to predicate check so that vue/svelte can inherit this +; without having this element being captured twice +((style_element + (start_tag) @_no_type_lang + (raw_text) @injection.content) + (#not-lua-match? @_no_type_lang "%slang%s*=") + (#not-lua-match? @_no_type_lang "%stype%s*=") + (#set! injection.language "css")) + +((style_element + (start_tag + (attribute + (attribute_name) @_type + (quoted_attribute_value + (attribute_value) @_css))) + (raw_text) @injection.content) + (#eq? @_type "type") + (#eq? @_css "text/css") + (#set! injection.language "css")) + +; +; +((script_element + (start_tag) @_no_type_lang + (raw_text) @injection.content) + (#not-lua-match? @_no_type_lang "%slang%s*=") + (#not-lua-match? @_no_type_lang "%stype%s*=") + (#set! injection.language "javascript")) + +;