initial commit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
[main]
|
||||
terminal=foot
|
||||
width=30
|
||||
font=JetBrains Mono:size=16
|
||||
width=45
|
||||
lines=10
|
||||
anchor=center
|
||||
icons-enabled=yes
|
||||
icon-theme=hicolor
|
||||
fuzzy=yes
|
||||
|
||||
[colors]
|
||||
background=0a0a0aff
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
lazy-lock.json
|
||||
@@ -0,0 +1 @@
|
||||
globals = { "vim" }
|
||||
@@ -1,117 +0,0 @@
|
||||
# Neovim Keybinds Documentation
|
||||
|
||||
This document provides a simple and organized overview of all the custom keybinds defined in my Neovim configuration.
|
||||
|
||||
## General Keybinds
|
||||
|
||||
| Mode | Key | Action |
|
||||
|------|-----------------|---------------------------------------------------------------------------------------------|
|
||||
| `n` | `<leader>cd` | Open Ex mode (`:Ex`) |
|
||||
| `n` | `J` | Join lines while keeping the cursor in place |
|
||||
| `n` | `<C-d>` | Scroll half-page down and keep the cursor centered |
|
||||
| `n` | `<C-u>` | Scroll half-page up and keep the cursor centered |
|
||||
| `n` | `n` | Move to next search result and keep it centered |
|
||||
| `n` | `N` | Move to previous search result and keep it centered |
|
||||
| `n` | `Q` | Disable Ex mode |
|
||||
| `n` | `<C-k>` | Jump to next quickfix entry and keep it centered |
|
||||
| `n` | `<C-j>` | Jump to previous quickfix entry and keep it centered |
|
||||
| `n` | `<leader>k` | Jump to next location entry and keep it centered |
|
||||
| `n` | `<leader>j` | Jump to previous location entry and keep it centered |
|
||||
| `i` | `<C-c>` | Exit insert mode (acts like `Esc`) |
|
||||
| `n` | `<leader>x` | Make current file executable (`chmod +x`) |
|
||||
| `n` | `<leader>u` | Toggle Undotree |
|
||||
| `n` | `<leader>rl` | Reload the Neovim config (`~/.config/nvim/init.lua`) |
|
||||
| `n` | `<leader><leader>` | Source the current file (`:so`) |
|
||||
|
||||
---
|
||||
|
||||
## Visual Mode Keybinds
|
||||
|
||||
| Mode | Key | Action |
|
||||
|------|-----------------|---------------------------------------------------------------------------------------------|
|
||||
| `v` | `J` | Move selected block down |
|
||||
| `v` | `K` | Move selected block up |
|
||||
| `x` | `<leader>p` | Paste without overwriting clipboard |
|
||||
| `v` | `<leader>y` | Yank into system clipboard (even on SSH) |
|
||||
|
||||
---
|
||||
|
||||
## Linting and Formatting
|
||||
|
||||
| Mode | Key | Action |
|
||||
|------|-----------------|---------------------------------------------------------------------------------------------|
|
||||
| `n` | `<leader>cc` | Run `php-cs-fixer` to lint and format PHP files |
|
||||
| `n` | `<F3>` | Format code (`LSP`) |
|
||||
|
||||
---
|
||||
|
||||
## Telescope Keybinds
|
||||
|
||||
| Mode | Key | Action |
|
||||
|------|-----------------|---------------------------------------------------------------------------------------------|
|
||||
| `n` | `<leader>ff` | Find files |
|
||||
| `n` | `<leader>fg` | Find git-tracked files |
|
||||
| `n` | `<leader>fo` | Open recent files |
|
||||
| `n` | `<leader>fq` | Open quickfix list |
|
||||
| `n` | `<leader>fh` | Open help tags |
|
||||
| `n` | `<leader>fb` | Open buffer list |
|
||||
| `n` | `<leader>fs` | Grep current string |
|
||||
| `n` | `<leader>fc` | Grep instances of the current file name without the extension |
|
||||
| `n` | `<leader>fi` | Find files in Neovim configuration directory (`~/.config/nvim/`) |
|
||||
|
||||
---
|
||||
|
||||
## Harpoon Integration
|
||||
|
||||
| Mode | Key | Action |
|
||||
|------|-----------------|---------------------------------------------------------------------------------------------|
|
||||
| `n` | `<leader>a` | Add current file to Harpoon list |
|
||||
| `n` | `<C-e>` | Toggle Harpoon quick menu |
|
||||
| `n` | `<leader>fl` | Open Harpoon window with Telescope |
|
||||
| `n` | `<C-p>` | Go to previous Harpoon mark |
|
||||
| `n` | `<C-n>` | Go to next Harpoon mark |
|
||||
|
||||
---
|
||||
|
||||
## LSP Keybinds
|
||||
|
||||
| Mode | Key | Action |
|
||||
|-----------|------------|---------------------------------------------------------------------------------------------|
|
||||
| `n` | `K` | Show hover information |
|
||||
| `n` | `gd` | Go to definition |
|
||||
| `n` | `gD` | Go to declaration |
|
||||
| `n` | `gi` | Go to implementation |
|
||||
| `n` | `go` | Go to type definition |
|
||||
| `n` | `gr` | Show references |
|
||||
| `n` | `gs` | Show signature help |
|
||||
| `n` | `gl` | Show diagnostics in a floating window |
|
||||
| `n` | `<F2>` | Rename symbol |
|
||||
| `n`, `x` | `<F3>` | Format code asynchronously |
|
||||
| `n` | `<F4>` | Show code actions |
|
||||
|
||||
---
|
||||
|
||||
## Miscellaneous
|
||||
|
||||
| Mode | Key | Action |
|
||||
|------|-----------------|---------------------------------------------------------------------------------------------|
|
||||
| `n` | `<leader>dg` | Run `DogeGenerate` (comment documentation generation) |
|
||||
| `n` | `<leader>s` | Replace all instances of the word under the cursor on the current line |
|
||||
|
||||
---
|
||||
|
||||
# LSP servers:
|
||||
|
||||
I am migrating my lsp config to /lua/plugins/lsp.lua because nvim v0.11 allows a very minimal debloated way to setup language server protocols.
|
||||
|
||||
Below is a running list of what and how to install the lsp's that are going to be configured in this build. I will avoid mason for now because I think its better to have full control over your system, and not outsource it to mason. Just uncommonet `return {` in /plugins/lsp.lua from the original lspconfig if you want to go that route.
|
||||
|
||||
1. { lua-language-server }
|
||||
- refer to distro ( pacman -Ss lua-language-server )
|
||||
2. { css-language-server --studio, html-language-server }
|
||||
- npm install -g vscode-langservers-extracted
|
||||
3. { intelephense }
|
||||
- npm install -g intelephense
|
||||
4. { typescript-language-server }
|
||||
- npm install -g typescript-language-server typescript
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
vim.bo.commentstring = "// %s"
|
||||
vim.bo.comments = "s:/*,m: *,ex:*/,://"
|
||||
@@ -1,12 +0,0 @@
|
||||
local set = vim.opt_local
|
||||
|
||||
vim.bo.commentstring = "// %s"
|
||||
vim.bo.comments = "s:/*,m: *,ex:*/,://"
|
||||
|
||||
set.shiftwidth = 4
|
||||
set.tabstop = 4
|
||||
set.softtabstop = 4
|
||||
set.expandtab = true
|
||||
|
||||
set.number = true
|
||||
set.relativenumber = true
|
||||
@@ -1,9 +0,0 @@
|
||||
local set = vim.opt_local
|
||||
|
||||
set.shiftwidth = 2
|
||||
set.tabstop = 2
|
||||
set.softtabstop = 2
|
||||
set.expandtab = true
|
||||
|
||||
set.number = true
|
||||
set.relativenumber = true
|
||||
@@ -1,8 +0,0 @@
|
||||
local set = vim.opt_local
|
||||
set.number = true
|
||||
set.relativenumber = true
|
||||
set.number = true
|
||||
set.relativenumber = false
|
||||
set.wrap = true
|
||||
set.linebreak = true
|
||||
set.conceallevel = 0
|
||||
@@ -1,8 +0,0 @@
|
||||
local set = vim.opt_local
|
||||
|
||||
set.shiftwidth = 2
|
||||
set.tabstop = 2
|
||||
set.softtabstop = 2
|
||||
set.expandtab = true
|
||||
set.number = true
|
||||
set.relativenumber = true
|
||||
@@ -1,6 +0,0 @@
|
||||
vim.cmd.colorscheme("tokyonight")
|
||||
vim.cmd("hi Directory guibg=NONE")
|
||||
vim.cmd("hi SignColumn guibg=NONE")
|
||||
vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
|
||||
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
|
||||
vim.api.nvim_set_hl(0, "LineNr", { bg = "none" })
|
||||
@@ -1,33 +0,0 @@
|
||||
local cmp = require("cmp")
|
||||
require("cmp_nvim_lsp").setup()
|
||||
cmp.register_source("path", require("cmp_path").new())
|
||||
cmp.register_source("buffer", require("cmp_buffer"))
|
||||
|
||||
cmp.setup({
|
||||
preselect = cmp.PreselectMode.Item,
|
||||
completion = {
|
||||
completeopt = "menu,menuone,noinsert",
|
||||
autocomplete = { cmp.TriggerEvent.TextChanged },
|
||||
},
|
||||
window = { documentation = cmp.config.window.bordered() },
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<CR>"] = cmp.mapping.confirm({ select = false }),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
|
||||
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-u>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then cmp.select_next_item() else fallback() end
|
||||
end, { "i", "s" }),
|
||||
["<S-Tab>"] = cmp.mapping(function()
|
||||
if cmp.visible() then cmp.select_prev_item() end
|
||||
end, { "i", "s" }),
|
||||
}),
|
||||
sources = {
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "path" },
|
||||
{ name = "buffer", keyword_length = 3 },
|
||||
},
|
||||
})
|
||||
@@ -1,21 +0,0 @@
|
||||
local harpoon = require("harpoon")
|
||||
harpoon:setup()
|
||||
|
||||
vim.keymap.set("n", "<leader>a", function() harpoon:list():add() end)
|
||||
vim.keymap.set("n", "<C-e>", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
|
||||
vim.keymap.set("n", "<C-p>", function() harpoon:list():prev() end)
|
||||
vim.keymap.set("n", "<C-n>", function() harpoon:list():next() end)
|
||||
|
||||
vim.keymap.set("n", "<leader>fl", function()
|
||||
local conf = require("telescope.config").values
|
||||
local themes = require("telescope.themes")
|
||||
local file_paths = {}
|
||||
for _, item in ipairs(harpoon:list().items) do
|
||||
table.insert(file_paths, item.value)
|
||||
end
|
||||
require("telescope.pickers").new(themes.get_ivy({ prompt_title = "Working List" }), {
|
||||
finder = require("telescope.finders").new_table({ results = file_paths }),
|
||||
previewer = conf.file_previewer({}),
|
||||
sorter = conf.generic_sorter({}),
|
||||
}):find()
|
||||
end, { desc = "Open harpoon window" })
|
||||
@@ -1,2 +0,0 @@
|
||||
require("lualine").setup({ options = { theme = "tokyonight" } })
|
||||
require("nvim-highlight-colors").setup({})
|
||||
@@ -1,34 +0,0 @@
|
||||
local actions = require("telescope.actions")
|
||||
require("telescope").setup({
|
||||
defaults = {
|
||||
mappings = {
|
||||
i = {
|
||||
["<C-k>"] = actions.move_selection_previous,
|
||||
["<C-j>"] = actions.move_selection_next,
|
||||
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
local builtin = require("telescope.builtin")
|
||||
vim.keymap.set("n", "<leader>ff", builtin.find_files)
|
||||
vim.keymap.set("n", "<leader>fo", builtin.oldfiles)
|
||||
vim.keymap.set("n", "<leader>fq", builtin.quickfix)
|
||||
vim.keymap.set("n", "<leader>fh", builtin.help_tags, { desc = "Telescope help tags" })
|
||||
vim.keymap.set("n", "<leader>fm", function()
|
||||
builtin.man_pages({ sections = { "ALL" } })
|
||||
end, { desc = "Telescope man pages" })
|
||||
vim.keymap.set("n", "<leader>fb", builtin.buffers, { desc = "Telescope buffers" })
|
||||
vim.keymap.set("n", "<leader>fg", function()
|
||||
builtin.grep_string({ search = vim.fn.input("Grep > ") })
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>fc", function()
|
||||
builtin.grep_string({ search = vim.fn.expand("%:t:r") })
|
||||
end, { desc = "Find current file" })
|
||||
vim.keymap.set("n", "<leader>fs", function()
|
||||
builtin.grep_string({})
|
||||
end, { desc = "Find current string" })
|
||||
vim.keymap.set("n", "<leader>fi", function()
|
||||
builtin.find_files({ cwd = "~/.config/nvim/" })
|
||||
end)
|
||||
@@ -1,6 +0,0 @@
|
||||
-- Treesitter config lives in plugin/tonysitter.lua.
|
||||
-- The only thing left here is the goon filetype mapping;
|
||||
-- goon's parser is at ~/.local/share/nvim/site/parser/goon.so
|
||||
-- and queries are at ~/.config/nvim/queries/goon/, both auto-loaded.
|
||||
|
||||
vim.filetype.add({ extension = { goon = "goon" } })
|
||||
+461
-3
@@ -1,3 +1,461 @@
|
||||
require("config.options")
|
||||
require("config.keybinds")
|
||||
require("manage").setup()
|
||||
--
|
||||
-- CONFIGS
|
||||
--
|
||||
vim.opt.termguicolors = true -- enable 24-bit RGB colors in the terminal
|
||||
|
||||
-- Line numbers
|
||||
vim.opt.number = true -- show absolute line number on current line
|
||||
vim.opt.relativenumber = true -- show relative line numbers for all other lines
|
||||
vim.opt.cursorline = true -- highlight the row the cursor is on
|
||||
vim.opt.wrap = false -- do not wrap long lines
|
||||
vim.opt.scrolloff = 10 -- keep at least 10 lines above/below the cursor
|
||||
vim.opt.sidescrolloff = 10 -- keep at least 10 columns left/right of the cursor
|
||||
|
||||
-- Indentation: 2-space soft tabs
|
||||
vim.opt.tabstop = 2 -- a <Tab> counts as 2 columns
|
||||
vim.opt.shiftwidth = 2 -- >> / << shift by 2 columns
|
||||
vim.opt.softtabstop = 2 -- <Tab> in insert mode inserts 2 spaces
|
||||
vim.opt.expandtab = true -- insert spaces instead of tab characters
|
||||
vim.opt.smartindent = true
|
||||
vim.opt.autoindent = true
|
||||
|
||||
-- Search
|
||||
vim.opt.ignorecase = true -- case-insensitive search by default
|
||||
vim.opt.smartcase = true -- switch to case-sensitive when query contains an uppercase letter
|
||||
vim.opt.hlsearch = true -- highlight all matches
|
||||
vim.opt.incsearch = true -- show matches while typing the query
|
||||
|
||||
-- UI
|
||||
vim.opt.showmatch = true -- briefly jump to matching bracket when one is inserted
|
||||
vim.opt.cmdheight = 1 -- always show the command line (1 row)
|
||||
vim.opt.showmode = false -- hide "-- INSERT --" etc.; the statusline shows the mode instead
|
||||
vim.opt.pumheight = 10 -- limit the completion popup to 10 items
|
||||
vim.opt.pumblend = 10 -- make the completion popup slightly transparent
|
||||
vim.opt.winblend = 0 -- floating windows are fully opaque
|
||||
vim.opt.conceallevel = 0 -- never hide markup characters (e.g. Markdown asterisks)
|
||||
vim.opt.concealcursor = "" -- never hide markup on the cursor line either
|
||||
vim.opt.synmaxcol = 300 -- stop syntax highlighting for columns beyond 300 (perf guard)
|
||||
vim.opt.fillchars = { eob = " " } -- replace the "~" placeholder on empty lines with a space
|
||||
|
||||
-- Persistent undo: survive across sessions even after the buffer is closed
|
||||
local undodir = vim.fn.expand("~/.vim/undodir")
|
||||
if
|
||||
vim.fn.isdirectory(undodir) == 0 -- create undodir if nonexistent
|
||||
then
|
||||
vim.fn.mkdir(undodir, "p")
|
||||
end
|
||||
|
||||
vim.opt.backup = false -- do not create a backup file
|
||||
vim.opt.writebackup = false -- do not keep a backup while overwriting a file
|
||||
vim.opt.swapfile = false -- do not create a swapfile
|
||||
vim.opt.undofile = true -- persist undo history to disk
|
||||
vim.opt.undodir = undodir -- where to store undo files
|
||||
vim.opt.updatetime = 300 -- write swap file (and trigger CursorHold) after 300 ms of inactivity
|
||||
vim.opt.timeoutlen = 500 -- wait 500 ms for a mapped key sequence to complete
|
||||
vim.opt.ttimeoutlen = 50 -- wait 50 ms for a terminal key code to complete
|
||||
vim.opt.autoread = true -- reload a file changed outside Neovim without prompting
|
||||
vim.opt.autowrite = false -- do not silently save on :make / buffer switch
|
||||
|
||||
-- Buffer and editing behaviour
|
||||
vim.opt.hidden = true -- allow switching away from an unsaved buffer without closing it
|
||||
vim.opt.errorbells = false -- disable the error bell
|
||||
vim.opt.backspace = "indent,eol,start" -- allow backspace over auto-indent, line breaks, and insert start
|
||||
vim.opt.autochdir = false -- keep the working directory fixed (don't follow the open file)
|
||||
vim.opt.iskeyword:append("-") -- treat "foo-bar" as a single word for motions like w/b
|
||||
vim.opt.path:append("**") -- make :find search recursively into subdirectories
|
||||
vim.opt.selection = "inclusive" -- visual selection includes the character under the cursor
|
||||
vim.opt.mouse = "a" -- enable mouse support in all modes
|
||||
vim.opt.clipboard:append("unnamedplus") -- share the system clipboard (+ register)
|
||||
|
||||
-- Over SSH, wl-clipboard is unavailable; use OSC 52 to write yanks to the local terminal clipboard.
|
||||
if os.getenv("SSH_TTY") then
|
||||
vim.g.clipboard = {
|
||||
name = "OSC 52",
|
||||
copy = {
|
||||
["+"] = require("vim.ui.clipboard.osc52").copy("+"),
|
||||
["*"] = require("vim.ui.clipboard.osc52").copy("*"),
|
||||
},
|
||||
paste = {
|
||||
["+"] = require("vim.ui.clipboard.osc52").paste("+"),
|
||||
["*"] = require("vim.ui.clipboard.osc52").paste("*"),
|
||||
},
|
||||
}
|
||||
end
|
||||
vim.opt.modifiable = true -- allow buffer modifications (safety default)
|
||||
vim.opt.encoding = "utf-8" -- internal character encoding
|
||||
|
||||
-- Folding: driven by Tree-sitter when available; foldlevel = 99 means all folds start open
|
||||
vim.opt.foldmethod = "expr"
|
||||
vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
||||
vim.opt.foldlevel = 99 -- a high value ensures every fold is open on buffer load
|
||||
|
||||
-- Window splits
|
||||
vim.opt.splitbelow = true -- :split opens the new window below
|
||||
vim.opt.splitright = true -- :vsplit opens the new window to the right
|
||||
|
||||
-- Miscellaneous
|
||||
vim.opt.wildmenu = true -- enable enhanced command-line completion
|
||||
vim.opt.wildmode = "longest:full,full" -- first Tab completes the longest common prefix and lists all; subsequent Tabs cycle
|
||||
vim.opt.diffopt:append("linematch:60") -- use the improved diff algorithm for blocks up to 60 lines
|
||||
vim.opt.redrawtime = 10000 -- allow up to 10 s for a full screen redraw (useful for large files)
|
||||
vim.opt.maxmempattern = 20000 -- raise the memory cap for pattern matching (avoids "pattern too complex" errors)
|
||||
|
||||
--
|
||||
-- KEYMAPS
|
||||
--
|
||||
vim.g.mapleader = " " -- <Space> as the leader key
|
||||
vim.g.maplocalleader = " " -- <Space> as the local leader key
|
||||
|
||||
-- j/k navigate display lines when there is no count prefix, so wrapped lines
|
||||
-- feel natural. With a count (e.g. 5j) they use real lines so relative jumps work.
|
||||
vim.keymap.set("n", "j", function()
|
||||
return vim.v.count == 0 and "gj" or "j"
|
||||
end, { expr = true, silent = true, desc = "Down (wrap-aware)" })
|
||||
vim.keymap.set("n", "k", function()
|
||||
return vim.v.count == 0 and "gk" or "k"
|
||||
end, { expr = true, silent = true, desc = "Up (wrap-aware)" })
|
||||
|
||||
-- Keep search results and half-page jumps vertically centred
|
||||
vim.keymap.set("n", "n", "nzzzv", { desc = "Next search result (centered)" })
|
||||
vim.keymap.set("n", "N", "Nzzzv", { desc = "Previous search result (centered)" })
|
||||
vim.keymap.set("n", "<C-d>", "<C-d>zz", { desc = "Half page down (centered)" })
|
||||
vim.keymap.set("n", "<C-u>", "<C-u>zz", { desc = "Half page up (centered)" })
|
||||
|
||||
-- Window navigation without the <C-w> prefix
|
||||
vim.keymap.set("n", "<C-h>", "<C-w>h", { desc = "Move to left window" })
|
||||
vim.keymap.set("n", "<C-j>", "<C-w>j", { desc = "Move to bottom window" })
|
||||
vim.keymap.set("n", "<C-k>", "<C-w>k", { desc = "Move to top window" })
|
||||
vim.keymap.set("n", "<C-l>", "<C-w>l", { desc = "Move to right window" })
|
||||
|
||||
-- Re-select visual block after indent so you can keep indenting with < or >
|
||||
vim.keymap.set("v", "<", "<gv", { desc = "Indent left and reselect" })
|
||||
vim.keymap.set("v", ">", ">gv", { desc = "Indent right and reselect" })
|
||||
|
||||
-- J joins lines but restores the cursor position (mz saves, `z restores)
|
||||
vim.keymap.set("n", "J", "mzJ`z", { desc = "Join lines and keep cursor position" })
|
||||
|
||||
vim.keymap.set("n", "H", "<cmd>bprev<cr>", { desc = "Previous buffer" })
|
||||
vim.keymap.set("n", "L", "<cmd>bnext<cr>", { desc = "Next buffer" })
|
||||
|
||||
-- Toggle LSP diagnostics on/off for the current session
|
||||
vim.keymap.set("n", "<leader>td", function()
|
||||
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
|
||||
end, { desc = "Toggle diagnostics" })
|
||||
|
||||
-- Toggle inline virtual text only (keeps underlines and signs)
|
||||
vim.keymap.set("n", "<leader>tv", function()
|
||||
local current = vim.diagnostic.config().virtual_text
|
||||
vim.diagnostic.config({ virtual_text = not current })
|
||||
end, { desc = "Toggle virtual text" })
|
||||
|
||||
--
|
||||
-- AUTOCOMMANDS
|
||||
--
|
||||
local augroup = vim.api.nvim_create_augroup("UserConfig", { clear = true })
|
||||
|
||||
-- Format on save via the EFM language server.
|
||||
-- Only runs when: the buffer is a real file, it is modifiable, it has a name,
|
||||
-- and efm is attached. This avoids spurious save prompts on scratch buffers.
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
pattern = {
|
||||
"*.cs",
|
||||
"*.lua",
|
||||
"*.py",
|
||||
"*.go",
|
||||
"*.js",
|
||||
"*.jsx",
|
||||
"*.ts",
|
||||
"*.tsx",
|
||||
"*.json",
|
||||
"*.css",
|
||||
"*.scss",
|
||||
"*.html",
|
||||
"*.sh",
|
||||
"*.bash",
|
||||
},
|
||||
callback = function(args)
|
||||
-- avoid formatting non-file buffers (helps prevent weird write prompts)
|
||||
if vim.bo[args.buf].buftype ~= "" then
|
||||
return
|
||||
end
|
||||
if not vim.bo[args.buf].modifiable then
|
||||
return
|
||||
end
|
||||
if vim.api.nvim_buf_get_name(args.buf) == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local has_efm = false
|
||||
for _, c in ipairs(vim.lsp.get_clients({ bufnr = args.buf })) do
|
||||
if c.name == "efm" then
|
||||
has_efm = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not has_efm then
|
||||
return
|
||||
end
|
||||
|
||||
pcall(vim.lsp.buf.format, {
|
||||
bufnr = args.buf,
|
||||
timeout_ms = 2000,
|
||||
filter = function(c)
|
||||
return c.name == "efm"
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
-- Flash the yanked region briefly so it is clear what was copied
|
||||
vim.api.nvim_create_autocmd("TextYankPost", {
|
||||
group = augroup,
|
||||
callback = function()
|
||||
vim.hl.on_yank()
|
||||
end,
|
||||
})
|
||||
|
||||
-- Restore the cursor to where it was when the file was last closed
|
||||
vim.api.nvim_create_autocmd("BufReadPost", {
|
||||
group = augroup,
|
||||
desc = "Restore last cursor position",
|
||||
callback = function()
|
||||
if vim.o.diff then -- except in diff mode
|
||||
return
|
||||
end
|
||||
|
||||
local last_pos = vim.api.nvim_buf_get_mark(0, '"') -- {line, col}
|
||||
local last_line = vim.api.nvim_buf_line_count(0)
|
||||
|
||||
local row = last_pos[1]
|
||||
if row < 1 or row > last_line then
|
||||
return
|
||||
end
|
||||
|
||||
pcall(vim.api.nvim_win_set_cursor, 0, last_pos)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Prose-friendly settings for Markdown, plain text, and commit messages
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = augroup,
|
||||
pattern = { "markdown", "text", "gitcommit" },
|
||||
callback = function()
|
||||
vim.opt_local.wrap = true -- soft-wrap at window edge
|
||||
vim.opt_local.linebreak = true -- break at word boundaries, not mid-word
|
||||
vim.opt_local.spell = true -- enable spell-checking
|
||||
end,
|
||||
})
|
||||
|
||||
--
|
||||
-- PLUGINS
|
||||
--
|
||||
vim.pack.add({
|
||||
"https://github.com/folke/which-key.nvim", -- shows pending keymap hints
|
||||
"https://github.com/folke/tokyonight.nvim", -- colorscheme
|
||||
"https://github.com/nvim-lualine/lualine.nvim", -- statusline
|
||||
"https://www.github.com/lewis6991/gitsigns.nvim", -- git hunk signs in the gutter
|
||||
"https://www.github.com/echasnovski/mini.nvim", -- collection of small plugins
|
||||
"https://www.github.com/ibhagwan/fzf-lua", -- fuzzy finder (files, grep, LSP, …)
|
||||
"https://www.github.com/neovim/nvim-lspconfig", -- provides cmd/root_dir/filetypes for each LSP server
|
||||
"https://github.com/mason-org/mason.nvim", -- LSP / tool installer UI
|
||||
"https://github.com/creativenull/efmls-configs-nvim", -- pre-built efm-langserver tool configs
|
||||
"https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim", -- auto-install Mason tools on startup
|
||||
"https://github.com/folke/flash.nvim", -- enhanced f/t/s jumps with labels
|
||||
"https://github.com/L3MON4D3/LuaSnip", -- snippet engine (used by blink.cmp)
|
||||
{
|
||||
src = "https://github.com/saghen/blink.cmp", -- completion engine
|
||||
version = vim.version.range("1.*"), -- pin to any 1.x release
|
||||
},
|
||||
{
|
||||
src = "https://github.com/nvim-treesitter/nvim-treesitter",
|
||||
branch = "main",
|
||||
build = ":TSUpdate", -- keep parser binaries up to date after install/update
|
||||
},
|
||||
"https://github.com/nvim-treesitter/nvim-treesitter-textobjects",
|
||||
"https://github.com/HakonHarnes/img-clip.nvim", -- paste images from clipboard (no Python required)
|
||||
})
|
||||
|
||||
--
|
||||
-- PLUGIN CONFIGS
|
||||
--
|
||||
require("lualine").setup()
|
||||
|
||||
vim.cmd.colorscheme("tokyonight")
|
||||
|
||||
-- which-key: shows a popup of available keymaps after a delay.
|
||||
-- Groups give the prefixes human-readable titles in the popup.
|
||||
require("which-key").setup({})
|
||||
require("which-key").add({
|
||||
{ "<leader>f", group = "Find" }, -- fzf-lua pickers (files, grep, LSP symbols, …)
|
||||
{ "<leader>g", group = "Go to" }, -- LSP navigation (definition, split, …)
|
||||
{ "<leader>c", group = "Code" }, -- code actions
|
||||
{ "<leader>r", group = "Refactor" }, -- rename, extract, …
|
||||
{ "<leader>t", group = "Toggle" }, -- toggle settings (diagnostics, …)
|
||||
{ "<leader>o", group = "Organize" }, -- organize imports, sort, …
|
||||
{ "<leader>d", group = "Diagnostics" }, -- diagnostic float / list
|
||||
{ "<leader>n", group = "Next" }, -- jump to next item
|
||||
{ "<leader>p", group = "Prev" }, -- jump to previous item
|
||||
{ "]m", hidden = true },
|
||||
{ "[m", hidden = true },
|
||||
{ "]M", hidden = true },
|
||||
{ "[M", hidden = true },
|
||||
})
|
||||
|
||||
-- Tree-sitter: start the parser for a filetype only when its grammar is
|
||||
-- already installed. Missing grammars are installed asynchronously on first
|
||||
-- launch so the editor never blocks at startup.
|
||||
local setup_treesitter = function()
|
||||
local treesitter = require("nvim-treesitter")
|
||||
treesitter.setup({})
|
||||
local ensure_installed = {
|
||||
"vim",
|
||||
"vimdoc",
|
||||
"go",
|
||||
"html",
|
||||
"css",
|
||||
"javascript",
|
||||
"json",
|
||||
"lua",
|
||||
"markdown",
|
||||
"python",
|
||||
"typescript",
|
||||
"bash",
|
||||
"c_sharp",
|
||||
}
|
||||
|
||||
local config = require("nvim-treesitter.config")
|
||||
|
||||
-- Only install parsers that are not already present
|
||||
local already_installed = config.get_installed()
|
||||
local parsers_to_install = {}
|
||||
|
||||
for _, parser in ipairs(ensure_installed) do
|
||||
if not vim.tbl_contains(already_installed, parser) then
|
||||
table.insert(parsers_to_install, parser)
|
||||
end
|
||||
end
|
||||
|
||||
if #parsers_to_install > 0 then
|
||||
treesitter.install(parsers_to_install)
|
||||
end
|
||||
|
||||
-- Start the Tree-sitter parser whenever a supported filetype is opened.
|
||||
-- Using an autocmd instead of the built-in auto_install avoids the
|
||||
-- blocking install prompt on first open.
|
||||
local group = vim.api.nvim_create_augroup("TreeSitterConfig", { clear = true })
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = group,
|
||||
callback = function(args)
|
||||
if vim.list_contains(treesitter.get_installed(), vim.treesitter.language.get_lang(args.match)) then
|
||||
vim.treesitter.start(args.buf)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
setup_treesitter()
|
||||
|
||||
require("nvim-treesitter-textobjects").setup({ move = { set_jumps = true } })
|
||||
|
||||
local move = require("nvim-treesitter-textobjects.move")
|
||||
vim.keymap.set({ "n", "x", "o" }, "]f", function()
|
||||
move.goto_next_start("@function.outer", "textobjects")
|
||||
end, { desc = "Next function" })
|
||||
vim.keymap.set({ "n", "x", "o" }, "[f", function()
|
||||
move.goto_previous_start("@function.outer", "textobjects")
|
||||
end, { desc = "Prev function" })
|
||||
vim.keymap.set({ "n", "x", "o" }, "]c", function()
|
||||
move.goto_next_start("@class.outer", "textobjects")
|
||||
end, { desc = "Next class" })
|
||||
vim.keymap.set({ "n", "x", "o" }, "[c", function()
|
||||
move.goto_previous_start("@class.outer", "textobjects")
|
||||
end, { desc = "Prev class" })
|
||||
|
||||
-- fzf-lua: fuzzy finder keymaps
|
||||
require("fzf-lua").setup({
|
||||
files = {
|
||||
actions = {
|
||||
["ctrl-h"] = { require("fzf-lua").actions.toggle_hidden },
|
||||
},
|
||||
},
|
||||
})
|
||||
vim.keymap.set("n", "<leader><leader>", function()
|
||||
require("fzf-lua").files()
|
||||
end, { desc = "Find files" })
|
||||
vim.keymap.set("n", "<leader>fg", function()
|
||||
require("fzf-lua").live_grep()
|
||||
end, { desc = "FZF Live Grep" })
|
||||
vim.keymap.set("n", "<leader>fb", function()
|
||||
require("fzf-lua").buffers()
|
||||
end, { desc = "FZF Buffers" })
|
||||
vim.keymap.set("n", "<leader>fh", function()
|
||||
require("fzf-lua").help_tags()
|
||||
end, { desc = "FZF Help Tags" })
|
||||
vim.keymap.set("n", "<leader>fx", function()
|
||||
require("fzf-lua").diagnostics_document()
|
||||
end, { desc = "FZF Diagnostics Document" })
|
||||
vim.keymap.set("n", "<leader>fX", function()
|
||||
require("fzf-lua").diagnostics_workspace()
|
||||
end, { desc = "FZF Diagnostics Workspace" })
|
||||
|
||||
-- mini.nvim: a suite of small, focused plugins. Each module is opted in explicitly.
|
||||
require("mini.ai").setup({}) -- extended text objects (e.g. cia = inside any argument)
|
||||
require("mini.comment").setup({}) -- gcc / gc<motion> to toggle comments
|
||||
require("mini.move").setup({}) -- move lines/selections with Option+hjkl (macOS Option = Alt)
|
||||
require("mini.surround").setup({}) -- sa/sd/sr to add/delete/replace surrounding chars
|
||||
require("mini.cursorword").setup({}) -- highlight all occurrences of the word under the cursor
|
||||
require("mini.indentscope").setup({}) -- animated indent-scope indicator line
|
||||
require("mini.pairs").setup({}) -- auto-close brackets, quotes, etc.
|
||||
require("mini.trailspace").setup({}) -- highlight and trim trailing whitespace
|
||||
require("mini.notify").setup({}) -- non-blocking notification popups
|
||||
require("mini.icons").setup({}) -- icon provider (replaces nvim-web-devicons calls)
|
||||
|
||||
-- flash.nvim: label-based jumps for f/t and anywhere on screen
|
||||
require("flash").setup({})
|
||||
vim.keymap.set({ "n", "x", "o" }, "s", function()
|
||||
require("flash").jump()
|
||||
end, { desc = "Flash jump" })
|
||||
vim.keymap.set({ "n", "x", "o" }, "S", function()
|
||||
require("flash").treesitter()
|
||||
end, { desc = "Flash treesitter" })
|
||||
vim.keymap.set("o", "r", function()
|
||||
require("flash").remote()
|
||||
end, { desc = "Flash remote" })
|
||||
vim.keymap.set({ "o", "x" }, "R", function()
|
||||
require("flash").treesitter_search()
|
||||
end, { desc = "Flash treesitter search" })
|
||||
|
||||
-- img-clip: paste images from clipboard into markdown files (no Python required)
|
||||
require("img-clip").setup({
|
||||
default = {
|
||||
use_absolute_path = false,
|
||||
relative_to_current_file = true,
|
||||
file_name = function()
|
||||
return os.date("%Y-%m-%d_%H-%M-%S")
|
||||
end,
|
||||
},
|
||||
filetypes = {
|
||||
markdown = { template = "" },
|
||||
},
|
||||
})
|
||||
vim.keymap.set({ "n", "x" }, "<leader>pi", "<cmd>PasteImage<CR>", { desc = "Paste image" })
|
||||
|
||||
-- gitsigns: decorates the sign column with added/changed/removed hunk markers
|
||||
require("gitsigns").setup({
|
||||
signs = {
|
||||
add = { text = "\u{2590}" }, -- ▏
|
||||
change = { text = "\u{2590}" }, -- ▐
|
||||
delete = { text = "\u{2590}" }, -- ◦
|
||||
topdelete = { text = "\u{25e6}" }, -- ◦
|
||||
changedelete = { text = "\u{25cf}" }, -- ●
|
||||
untracked = { text = "\u{25cb}" }, -- ○
|
||||
},
|
||||
signcolumn = true,
|
||||
current_line_blame = false, -- set to true to show inline git blame on the cursor line
|
||||
})
|
||||
|
||||
--
|
||||
-- LSP - Too anoying to have in this file
|
||||
--
|
||||
require("lsp-nix")
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
-- KEYBINDS
|
||||
vim.g.mapleader = " "
|
||||
vim.keymap.set("n", "<leader>cd", vim.cmd.Ex)
|
||||
|
||||
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv") -- Alt Up/Down in vscode
|
||||
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
|
||||
|
||||
vim.keymap.set("n", "J", "mzJ`z") -- Remap joining lines
|
||||
vim.keymap.set("n", "<C-d>", "<C-d>zz") -- Keep cursor in place while moving up/down page
|
||||
vim.keymap.set("n", "<C-u>", "<C-u>zz")
|
||||
vim.keymap.set("n", "n", "nzzzv") -- center screen when looping search results
|
||||
vim.keymap.set("n", "N", "Nzzzv")
|
||||
|
||||
-- paste and don't replace clipboard over deleted text
|
||||
vim.keymap.set("x", "<leader>p", [["_dP]])
|
||||
vim.keymap.set({ "n", "v" }, "<leader>d", [["_d]])
|
||||
|
||||
|
||||
-- sometimes in insert mode, control-c doesn't exactly work like escape
|
||||
vim.keymap.set("i", "<C-c>", "<Esc>")
|
||||
|
||||
-- add binds for Control J/K to scroll thru quickfix list
|
||||
vim.keymap.set("n", "<C-j>", "<cmd>cnext<CR>zz")
|
||||
vim.keymap.set("n", "<C-k>", "<cmd>cprev<CR>zz")
|
||||
|
||||
-- What the heck is Ex mode?
|
||||
vim.keymap.set("n", "Q", "<nop>")
|
||||
|
||||
vim.keymap.set("n", "<leader>k", "<cmd>lnext<CR>zz")
|
||||
vim.keymap.set("n", "<leader>j", "<cmd>lprev<CR>zz")
|
||||
|
||||
|
||||
-- lint / format php files for LC
|
||||
vim.keymap.set("n", "<leader>cc", "<cmd>!php-cs-fixer fix % --using-cache=no<cr>")
|
||||
|
||||
-- Replace all instances of whatever is under cursor (on line)
|
||||
vim.keymap.set("n", "<leader>s", [[:s/\<<C-r><C-w>\>//gI<Left><Left><Left>]])
|
||||
|
||||
-- make file executable
|
||||
vim.keymap.set("n", "<leader>x", "<cmd>!chmod +x %<CR>", { silent = true })
|
||||
|
||||
-- yank into clipboard even if on ssh
|
||||
vim.keymap.set('n', '<leader>y', '<Plug>OSCYankOperator')
|
||||
vim.keymap.set('v', '<leader>y', '<Plug>OSCYankVisual')
|
||||
|
||||
-- reload without exiting vim
|
||||
vim.keymap.set("n", "<leader>rl", "<cmd>source ~/.config/nvim/init.lua<cr>")
|
||||
|
||||
vim.keymap.set("n", "<leader>u", vim.cmd.UndotreeToggle)
|
||||
|
||||
-- Quickfix list stuff
|
||||
vim.keymap.set("n", "<leader>cl", ":cclose<CR>", { silent = true })
|
||||
vim.keymap.set("n", "<leader>co", ":copen<CR>", { silent = true })
|
||||
vim.keymap.set("n", "<leader>cn", ":cnext<CR>zz")
|
||||
vim.keymap.set("n", "<leader>cp", ":cprev<CR>zz")
|
||||
vim.keymap.set("n", "<leader>li", ":checkhealth vim.lsp<CR>", { desc = "LSP Info" })
|
||||
|
||||
-- run make in current working directory
|
||||
vim.keymap.set("n", "<leader>mm", "<cmd>make<CR>")
|
||||
|
||||
-- source file
|
||||
vim.keymap.set("n", "<leader><leader>", function()
|
||||
vim.cmd("so")
|
||||
end)
|
||||
@@ -1,55 +0,0 @@
|
||||
-- OPTIONS
|
||||
local set = vim.opt
|
||||
|
||||
--line nums
|
||||
set.relativenumber = true
|
||||
set.number = true
|
||||
|
||||
-- indentation and tabs
|
||||
set.tabstop = 4
|
||||
set.shiftwidth = 4
|
||||
set.autoindent = true
|
||||
set.expandtab = true
|
||||
|
||||
-- search settings
|
||||
set.ignorecase = true
|
||||
set.smartcase = true
|
||||
|
||||
-- appearance
|
||||
set.termguicolors = true
|
||||
set.background = "dark"
|
||||
set.signcolumn = "yes"
|
||||
|
||||
-- cursor line
|
||||
set.cursorline = true
|
||||
|
||||
-- 80th column
|
||||
set.colorcolumn = "80"
|
||||
|
||||
-- clipboard
|
||||
set.clipboard:append("unnamedplus")
|
||||
|
||||
-- backspace
|
||||
set.backspace = "indent,eol,start"
|
||||
|
||||
-- split windows
|
||||
set.splitbelow = true
|
||||
set.splitright = true
|
||||
|
||||
-- dw/diw/ciw works on full-word
|
||||
set.iskeyword:append("-")
|
||||
|
||||
-- keep cursor at least 8 rows from top/bot
|
||||
set.scrolloff = 8
|
||||
|
||||
-- undo dir settings
|
||||
set.swapfile = false
|
||||
set.backup = false
|
||||
set.undodir = os.getenv("HOME") .. "/.vim/undodir"
|
||||
set.undofile = true
|
||||
|
||||
-- incremental search
|
||||
set.incsearch = true
|
||||
|
||||
-- faster cursor hold
|
||||
set.updatetime = 50
|
||||
@@ -0,0 +1,211 @@
|
||||
local augroup = vim.api.nvim_create_augroup("UserConfig", { clear = false })
|
||||
|
||||
-- Diagnostic icons shown in the sign column and virtual text
|
||||
local diagnostic_signs = {
|
||||
Error = " ",
|
||||
Warn = " ",
|
||||
Hint = "",
|
||||
Info = "",
|
||||
}
|
||||
|
||||
-- Global diagnostic display options
|
||||
vim.diagnostic.config({
|
||||
virtual_text = { prefix = "●", spacing = 4 }, -- inline diagnostic text to the right
|
||||
signs = {
|
||||
text = {
|
||||
[vim.diagnostic.severity.ERROR] = diagnostic_signs.Error,
|
||||
[vim.diagnostic.severity.WARN] = diagnostic_signs.Warn,
|
||||
[vim.diagnostic.severity.INFO] = diagnostic_signs.Info,
|
||||
[vim.diagnostic.severity.HINT] = diagnostic_signs.Hint,
|
||||
},
|
||||
},
|
||||
underline = true,
|
||||
update_in_insert = false, -- do not update diagnostics while typing (reduces noise)
|
||||
severity_sort = true, -- show errors before warnings in lists
|
||||
float = {
|
||||
border = "rounded",
|
||||
source = "always", -- always show which LSP server produced the diagnostic
|
||||
header = "",
|
||||
prefix = "",
|
||||
focusable = false,
|
||||
style = "minimal",
|
||||
},
|
||||
})
|
||||
|
||||
-- Patch vim.lsp.util.open_floating_preview so every LSP floating window
|
||||
-- (hover, signature help, etc.) gets a rounded border without having to
|
||||
-- configure it per-server.
|
||||
do
|
||||
local orig = vim.lsp.util.open_floating_preview
|
||||
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
|
||||
opts = opts or {}
|
||||
opts.border = opts.border or "rounded"
|
||||
return orig(contents, syntax, opts, ...)
|
||||
end
|
||||
end
|
||||
|
||||
-- lsp_on_attach is called whenever an LSP server attaches to a buffer.
|
||||
-- It sets up buffer-local keymaps that are only active when an LSP is present.
|
||||
local function lsp_on_attach(ev)
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
|
||||
local bufnr = ev.buf
|
||||
local function map(key, fn, desc)
|
||||
vim.keymap.set("n", key, fn, { noremap = true, silent = true, buffer = bufnr, desc = desc })
|
||||
end
|
||||
|
||||
-- Navigation
|
||||
map("<leader>gd", vim.lsp.buf.definition, "Go to definition")
|
||||
map("<leader>gS", function() vim.cmd("vsplit") vim.lsp.buf.definition() end, "Go to definition (vsplit)")
|
||||
|
||||
-- Code actions and refactoring
|
||||
map("<leader>ca", vim.lsp.buf.code_action, "Code action")
|
||||
map("<leader>rn", vim.lsp.buf.rename, "Rename symbol")
|
||||
|
||||
-- Diagnostics
|
||||
map("<leader>D", function() vim.diagnostic.open_float({ scope = "line" }) end, "Line diagnostics")
|
||||
map("<leader>d", function() vim.diagnostic.open_float({ scope = "cursor" }) end, "Cursor diagnostic")
|
||||
map("<leader>nd", function() vim.diagnostic.jump({ count = 1 }) end, "Next diagnostic")
|
||||
map("<leader>pd", function() vim.diagnostic.jump({ count = -1 }) end, "Prev diagnostic")
|
||||
|
||||
-- Hover documentation
|
||||
map("K", vim.lsp.buf.hover, "Hover docs")
|
||||
|
||||
-- fzf-lua LSP pickers
|
||||
map("<leader>fd", function() require("fzf-lua").lsp_definitions({ jump_to_single_result = true }) end, "Definitions")
|
||||
map("<leader>fr", function() require("fzf-lua").lsp_references() end, "References")
|
||||
map("<leader>ft", function() require("fzf-lua").lsp_typedefs() end, "Type definitions")
|
||||
map("<leader>fs", function() require("fzf-lua").lsp_document_symbols() end, "Document symbols")
|
||||
map("<leader>fw", function() require("fzf-lua").lsp_workspace_symbols() end, "Workspace symbols")
|
||||
map("<leader>fi", function() require("fzf-lua").lsp_implementations() end, "Implementations")
|
||||
|
||||
-- Organise imports then format (only registered when the server supports codeAction)
|
||||
if client:supports_method("textDocument/codeAction", bufnr) then
|
||||
map("<leader>oi", function()
|
||||
vim.lsp.buf.code_action({
|
||||
context = { only = { "source.organizeImports" }, diagnostics = {} },
|
||||
apply = true,
|
||||
bufnr = bufnr,
|
||||
})
|
||||
-- Small delay lets the import action settle before formatting
|
||||
vim.defer_fn(function()
|
||||
vim.lsp.buf.format({ bufnr = bufnr })
|
||||
end, 50)
|
||||
end, "Organize imports")
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", { group = augroup, callback = lsp_on_attach })
|
||||
|
||||
-- Global diagnostic keymaps (available without an LSP attached)
|
||||
vim.keymap.set("n", "<leader>q", function() vim.diagnostic.setloclist({ open = true }) end, { desc = "Open diagnostic list" })
|
||||
|
||||
-- blink.cmp: completion engine wired to LuaSnip for snippet expansion
|
||||
require("blink.cmp").setup({
|
||||
enabled = function()
|
||||
return not vim.tbl_contains({ "markdown", "text" }, vim.bo.filetype)
|
||||
end,
|
||||
keymap = {
|
||||
preset = "none", -- start from a blank slate; all bindings are explicit
|
||||
["<C-Space>"] = { "show", "hide" }, -- toggle the completion menu
|
||||
["<CR>"] = { "accept", "fallback" }, -- confirm selection
|
||||
["<C-j>"] = { "select_next", "fallback" },
|
||||
["<C-k>"] = { "select_prev", "fallback" },
|
||||
["<Tab>"] = { "snippet_forward", "fallback" }, -- jump to next snippet placeholder
|
||||
["<S-Tab>"] = { "snippet_backward", "fallback" }, -- jump to previous placeholder
|
||||
},
|
||||
appearance = { nerd_font_variant = "mono" },
|
||||
completion = { menu = { auto_show = true } }, -- show the menu automatically (no manual trigger needed)
|
||||
sources = { default = { "lsp", "path", "buffer", "snippets" } },
|
||||
snippets = {
|
||||
-- Delegate snippet expansion to LuaSnip
|
||||
expand = function(snippet)
|
||||
require("luasnip").lsp_expand(snippet)
|
||||
end,
|
||||
},
|
||||
fuzzy = {
|
||||
implementation = "prefer_rust", -- use the faster Rust fuzzy-matching backend when available
|
||||
prebuilt_binaries = { download = true }, -- automatically download the pre-built binary
|
||||
},
|
||||
})
|
||||
|
||||
-- Inject blink.cmp capabilities into every LSP server so they can offer
|
||||
-- completions that respect snippet and LSP-specific completion item fields
|
||||
vim.lsp.config["*"] = {
|
||||
capabilities = require("blink.cmp").get_lsp_capabilities(),
|
||||
}
|
||||
|
||||
-- Server configurations
|
||||
vim.lsp.config("lua_ls", {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = { globals = { "vim" } }, -- teach lua_ls that `vim` is a known global
|
||||
telemetry = { enable = false },
|
||||
},
|
||||
},
|
||||
})
|
||||
vim.lsp.config("pyright", {}) -- Python type checker and language server
|
||||
vim.lsp.config("bashls", {}) -- Bash language server
|
||||
vim.lsp.config("vtsls", {}) -- TypeScript / JavaScript language server (VS Code's TS server)
|
||||
vim.lsp.config("gopls", {}) -- Go language server
|
||||
vim.lsp.config("omnisharp", {}) -- C# language server
|
||||
|
||||
-- EFM (efm-langserver): a generic LSP adapter that runs command-line linters
|
||||
-- and formatters and exposes them as LSP capabilities.
|
||||
do
|
||||
local luacheck = require("efmls-configs.linters.luacheck")
|
||||
local stylua = require("efmls-configs.formatters.stylua")
|
||||
local flake8 = require("efmls-configs.linters.flake8")
|
||||
local black = require("efmls-configs.formatters.black")
|
||||
local prettier_d = require("efmls-configs.formatters.prettier_d")
|
||||
local eslint_d = require("efmls-configs.linters.eslint_d")
|
||||
local fixjson = require("efmls-configs.formatters.fixjson")
|
||||
local shellcheck = require("efmls-configs.linters.shellcheck")
|
||||
local shfmt = require("efmls-configs.formatters.shfmt")
|
||||
local go_revive = require("efmls-configs.linters.go_revive")
|
||||
local gofumpt = require("efmls-configs.formatters.gofumpt")
|
||||
local csharpier = { formatCommand = "dotnet csharpier --write-stdout", formatStdin = true }
|
||||
|
||||
vim.lsp.config("efm", {
|
||||
filetypes = {
|
||||
"cs", "css", "go", "html",
|
||||
"javascript", "javascriptreact",
|
||||
"json", "jsonc",
|
||||
"lua", "markdown", "python", "sh",
|
||||
"typescript", "typescriptreact",
|
||||
},
|
||||
init_options = { documentFormatting = true },
|
||||
settings = {
|
||||
languages = {
|
||||
cs = { csharpier },
|
||||
go = { gofumpt, go_revive },
|
||||
css = { prettier_d },
|
||||
html = { prettier_d },
|
||||
javascript = { eslint_d, prettier_d },
|
||||
javascriptreact = { eslint_d, prettier_d },
|
||||
json = { eslint_d, fixjson },
|
||||
jsonc = { eslint_d, fixjson },
|
||||
lua = { luacheck, stylua },
|
||||
markdown = { prettier_d },
|
||||
python = { flake8, black },
|
||||
sh = { shellcheck, shfmt },
|
||||
typescript = { eslint_d, prettier_d },
|
||||
typescriptreact = { eslint_d, prettier_d },
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
-- Start all configured LSP servers
|
||||
vim.lsp.enable({
|
||||
"lua_ls",
|
||||
"pyright",
|
||||
"bashls",
|
||||
"vtsls",
|
||||
"gopls",
|
||||
"omnisharp",
|
||||
"efm",
|
||||
})
|
||||
@@ -0,0 +1,242 @@
|
||||
-- mason: GUI for installing LSP servers, DAPs, linters and formatters
|
||||
require("mason").setup({})
|
||||
|
||||
-- mason-tool-installer: automatically install all required tools on startup
|
||||
require("mason-tool-installer").setup({
|
||||
ensure_installed = {
|
||||
-- LSP servers
|
||||
"lua-language-server",
|
||||
"pyright",
|
||||
"bash-language-server",
|
||||
"vtsls",
|
||||
"gopls",
|
||||
"omnisharp",
|
||||
"efm",
|
||||
-- Formatters
|
||||
"stylua",
|
||||
"black",
|
||||
"prettierd",
|
||||
"shfmt",
|
||||
"gofumpt",
|
||||
"fixjson",
|
||||
-- Linters
|
||||
"flake8",
|
||||
"eslint_d",
|
||||
"shellcheck",
|
||||
"revive",
|
||||
},
|
||||
auto_update = false,
|
||||
run_on_start = true,
|
||||
})
|
||||
|
||||
local augroup = vim.api.nvim_create_augroup("UserConfig", { clear = false })
|
||||
|
||||
-- Diagnostic icons shown in the sign column and virtual text
|
||||
local diagnostic_signs = {
|
||||
Error = " ",
|
||||
Warn = " ",
|
||||
Hint = "",
|
||||
Info = "",
|
||||
}
|
||||
|
||||
-- Global diagnostic display options
|
||||
vim.diagnostic.config({
|
||||
virtual_text = { prefix = "●", spacing = 4 }, -- inline diagnostic text to the right
|
||||
signs = {
|
||||
text = {
|
||||
[vim.diagnostic.severity.ERROR] = diagnostic_signs.Error,
|
||||
[vim.diagnostic.severity.WARN] = diagnostic_signs.Warn,
|
||||
[vim.diagnostic.severity.INFO] = diagnostic_signs.Info,
|
||||
[vim.diagnostic.severity.HINT] = diagnostic_signs.Hint,
|
||||
},
|
||||
},
|
||||
underline = true,
|
||||
update_in_insert = false, -- do not update diagnostics while typing (reduces noise)
|
||||
severity_sort = true, -- show errors before warnings in lists
|
||||
float = {
|
||||
border = "rounded",
|
||||
source = "always", -- always show which LSP server produced the diagnostic
|
||||
header = "",
|
||||
prefix = "",
|
||||
focusable = false,
|
||||
style = "minimal",
|
||||
},
|
||||
})
|
||||
|
||||
-- Patch vim.lsp.util.open_floating_preview so every LSP floating window
|
||||
-- (hover, signature help, etc.) gets a rounded border without having to
|
||||
-- configure it per-server.
|
||||
do
|
||||
local orig = vim.lsp.util.open_floating_preview
|
||||
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
|
||||
opts = opts or {}
|
||||
opts.border = opts.border or "rounded"
|
||||
return orig(contents, syntax, opts, ...)
|
||||
end
|
||||
end
|
||||
|
||||
-- lsp_on_attach is called whenever an LSP server attaches to a buffer.
|
||||
-- It sets up buffer-local keymaps that are only active when an LSP is present.
|
||||
local function lsp_on_attach(ev)
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
|
||||
local bufnr = ev.buf
|
||||
local function map(key, fn, desc)
|
||||
vim.keymap.set("n", key, fn, { noremap = true, silent = true, buffer = bufnr, desc = desc })
|
||||
end
|
||||
|
||||
-- Navigation
|
||||
map("<leader>gd", vim.lsp.buf.definition, "Go to definition")
|
||||
map("<leader>gS", function() vim.cmd("vsplit") vim.lsp.buf.definition() end, "Go to definition (vsplit)")
|
||||
|
||||
-- Code actions and refactoring
|
||||
map("<leader>ca", vim.lsp.buf.code_action, "Code action")
|
||||
map("<leader>rn", vim.lsp.buf.rename, "Rename symbol")
|
||||
|
||||
-- Diagnostics
|
||||
map("<leader>D", function() vim.diagnostic.open_float({ scope = "line" }) end, "Line diagnostics")
|
||||
map("<leader>d", function() vim.diagnostic.open_float({ scope = "cursor" }) end, "Cursor diagnostic")
|
||||
map("<leader>nd", function() vim.diagnostic.jump({ count = 1 }) end, "Next diagnostic")
|
||||
map("<leader>pd", function() vim.diagnostic.jump({ count = -1 }) end, "Prev diagnostic")
|
||||
|
||||
-- Hover documentation
|
||||
map("K", vim.lsp.buf.hover, "Hover docs")
|
||||
|
||||
-- fzf-lua LSP pickers
|
||||
map("<leader>fd", function() require("fzf-lua").lsp_definitions({ jump_to_single_result = true }) end, "Definitions")
|
||||
map("<leader>fr", function() require("fzf-lua").lsp_references() end, "References")
|
||||
map("<leader>ft", function() require("fzf-lua").lsp_typedefs() end, "Type definitions")
|
||||
map("<leader>fs", function() require("fzf-lua").lsp_document_symbols() end, "Document symbols")
|
||||
map("<leader>fw", function() require("fzf-lua").lsp_workspace_symbols() end, "Workspace symbols")
|
||||
map("<leader>fi", function() require("fzf-lua").lsp_implementations() end, "Implementations")
|
||||
|
||||
-- Organise imports then format (only registered when the server supports codeAction)
|
||||
if client:supports_method("textDocument/codeAction", bufnr) then
|
||||
map("<leader>oi", function()
|
||||
vim.lsp.buf.code_action({
|
||||
context = { only = { "source.organizeImports" }, diagnostics = {} },
|
||||
apply = true,
|
||||
bufnr = bufnr,
|
||||
})
|
||||
-- Small delay lets the import action settle before formatting
|
||||
vim.defer_fn(function()
|
||||
vim.lsp.buf.format({ bufnr = bufnr })
|
||||
end, 50)
|
||||
end, "Organize imports")
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", { group = augroup, callback = lsp_on_attach })
|
||||
|
||||
-- Global diagnostic keymaps (available without an LSP attached)
|
||||
vim.keymap.set("n", "<leader>q", function() vim.diagnostic.setloclist({ open = true }) end, { desc = "Open diagnostic list" })
|
||||
|
||||
-- blink.cmp: completion engine wired to LuaSnip for snippet expansion
|
||||
require("blink.cmp").setup({
|
||||
enabled = function()
|
||||
return not vim.tbl_contains({ "markdown", "text" }, vim.bo.filetype)
|
||||
end,
|
||||
keymap = {
|
||||
preset = "none", -- start from a blank slate; all bindings are explicit
|
||||
["<C-Space>"] = { "show", "hide" }, -- toggle the completion menu
|
||||
["<CR>"] = { "accept", "fallback" }, -- confirm selection
|
||||
["<C-j>"] = { "select_next", "fallback" },
|
||||
["<C-k>"] = { "select_prev", "fallback" },
|
||||
["<Tab>"] = { "snippet_forward", "fallback" }, -- jump to next snippet placeholder
|
||||
["<S-Tab>"] = { "snippet_backward", "fallback" }, -- jump to previous placeholder
|
||||
},
|
||||
appearance = { nerd_font_variant = "mono" },
|
||||
completion = { menu = { auto_show = true } }, -- show the menu automatically (no manual trigger needed)
|
||||
sources = { default = { "lsp", "path", "buffer", "snippets" } },
|
||||
snippets = {
|
||||
-- Delegate snippet expansion to LuaSnip
|
||||
expand = function(snippet)
|
||||
require("luasnip").lsp_expand(snippet)
|
||||
end,
|
||||
},
|
||||
fuzzy = {
|
||||
implementation = "prefer_rust", -- use the faster Rust fuzzy-matching backend when available
|
||||
prebuilt_binaries = { download = true }, -- automatically download the pre-built binary
|
||||
},
|
||||
})
|
||||
|
||||
-- Inject blink.cmp capabilities into every LSP server so they can offer
|
||||
-- completions that respect snippet and LSP-specific completion item fields
|
||||
vim.lsp.config["*"] = {
|
||||
capabilities = require("blink.cmp").get_lsp_capabilities(),
|
||||
}
|
||||
|
||||
-- Server configurations
|
||||
vim.lsp.config("lua_ls", {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = { globals = { "vim" } }, -- teach lua_ls that `vim` is a known global
|
||||
telemetry = { enable = false },
|
||||
},
|
||||
},
|
||||
})
|
||||
vim.lsp.config("pyright", {}) -- Python type checker and language server
|
||||
vim.lsp.config("bashls", {}) -- Bash language server
|
||||
vim.lsp.config("vtsls", {}) -- TypeScript / JavaScript language server (VS Code's TS server)
|
||||
vim.lsp.config("gopls", {}) -- Go language server
|
||||
vim.lsp.config("omnisharp", {}) -- C# language server
|
||||
|
||||
-- EFM (efm-langserver): a generic LSP adapter that runs command-line linters
|
||||
-- and formatters and exposes them as LSP capabilities.
|
||||
do
|
||||
local luacheck = require("efmls-configs.linters.luacheck")
|
||||
local stylua = require("efmls-configs.formatters.stylua")
|
||||
local flake8 = require("efmls-configs.linters.flake8")
|
||||
local black = require("efmls-configs.formatters.black")
|
||||
local prettier_d = require("efmls-configs.formatters.prettier_d")
|
||||
local eslint_d = require("efmls-configs.linters.eslint_d")
|
||||
local fixjson = require("efmls-configs.formatters.fixjson")
|
||||
local shellcheck = require("efmls-configs.linters.shellcheck")
|
||||
local shfmt = require("efmls-configs.formatters.shfmt")
|
||||
local go_revive = require("efmls-configs.linters.go_revive")
|
||||
local gofumpt = require("efmls-configs.formatters.gofumpt")
|
||||
local csharpier = { formatCommand = "dotnet csharpier --write-stdout", formatStdin = true }
|
||||
|
||||
vim.lsp.config("efm", {
|
||||
filetypes = {
|
||||
"cs", "css", "go", "html",
|
||||
"javascript", "javascriptreact",
|
||||
"json", "jsonc",
|
||||
"lua", "markdown", "python", "sh",
|
||||
"typescript", "typescriptreact",
|
||||
},
|
||||
init_options = { documentFormatting = true },
|
||||
settings = {
|
||||
languages = {
|
||||
cs = { csharpier },
|
||||
go = { gofumpt, go_revive },
|
||||
css = { prettier_d },
|
||||
html = { prettier_d },
|
||||
javascript = { eslint_d, prettier_d },
|
||||
javascriptreact = { eslint_d, prettier_d },
|
||||
json = { eslint_d, fixjson },
|
||||
jsonc = { eslint_d, fixjson },
|
||||
lua = { luacheck, stylua },
|
||||
markdown = { prettier_d },
|
||||
python = { flake8, black },
|
||||
sh = { shellcheck, shfmt },
|
||||
typescript = { eslint_d, prettier_d },
|
||||
typescriptreact = { eslint_d, prettier_d },
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
-- Start all configured LSP servers
|
||||
vim.lsp.enable({
|
||||
"lua_ls",
|
||||
"pyright",
|
||||
"bashls",
|
||||
"vtsls",
|
||||
"gopls",
|
||||
"omnisharp",
|
||||
"efm",
|
||||
})
|
||||
@@ -1,36 +0,0 @@
|
||||
local M = {}
|
||||
local plug_dir = vim.fn.stdpath("data") .. "/plugins"
|
||||
|
||||
local function ensure(spec)
|
||||
local repo = type(spec) == "string" and spec or spec[1]
|
||||
local name = repo:match(".+/(.+)$")
|
||||
local path = plug_dir .. "/" .. name
|
||||
|
||||
if not vim.uv.fs_stat(path) then
|
||||
vim.fn.mkdir(plug_dir, "p")
|
||||
local cmd = { "git", "clone", "--depth=1" }
|
||||
if spec.branch then
|
||||
table.insert(cmd, "-b")
|
||||
table.insert(cmd, spec.branch)
|
||||
end
|
||||
table.insert(cmd, "https://github.com/" .. repo)
|
||||
table.insert(cmd, path)
|
||||
print("Installing " .. name .. "...")
|
||||
vim.fn.system(cmd)
|
||||
end
|
||||
|
||||
vim.opt.rtp:prepend(path)
|
||||
vim.opt.rtp:append(path .. "/after")
|
||||
local lua_path = path .. "/lua"
|
||||
if vim.uv.fs_stat(lua_path) then
|
||||
package.path = package.path .. ";" .. lua_path .. "/?.lua;" .. lua_path .. "/?/init.lua"
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
for _, spec in ipairs(require("plugin-list")) do
|
||||
ensure(spec)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,17 +0,0 @@
|
||||
return {
|
||||
"nvim-lua/plenary.nvim",
|
||||
"nvim-tree/nvim-web-devicons",
|
||||
"hrsh7th/nvim-cmp",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-path",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"nvim-telescope/telescope.nvim",
|
||||
{ "ThePrimeagen/harpoon", branch = "harpoon2" },
|
||||
"folke/tokyonight.nvim",
|
||||
"nvim-lualine/lualine.nvim",
|
||||
"brenoprata10/nvim-highlight-colors",
|
||||
"tpope/vim-fugitive",
|
||||
"mbbill/undotree",
|
||||
"ojroques/vim-oscyank",
|
||||
"captbaritone/better-indent-support-for-php-with-html",
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"plugins": {
|
||||
"LuaSnip": {
|
||||
"rev": "a62e1083a3cfe8b6b206e7d3d33a51091df25357",
|
||||
"src": "https://github.com/L3MON4D3/LuaSnip"
|
||||
},
|
||||
"blink.cmp": {
|
||||
"rev": "78336bc89ee5365633bcf754d93df01678b5c08f",
|
||||
"src": "https://github.com/saghen/blink.cmp",
|
||||
"version": "1.0.0 - 2.0.0"
|
||||
},
|
||||
"efmls-configs-nvim": {
|
||||
"rev": "5dc52088c231f2721f545570fcb541b04802ce6b",
|
||||
"src": "https://github.com/creativenull/efmls-configs-nvim"
|
||||
},
|
||||
"flash.nvim": {
|
||||
"rev": "fcea7ff883235d9024dc41e638f164a450c14ca2",
|
||||
"src": "https://github.com/folke/flash.nvim"
|
||||
},
|
||||
"fzf-lua": {
|
||||
"rev": "657c1bbb7357c61e26a20d868b53a460b05c18c0",
|
||||
"src": "https://www.github.com/ibhagwan/fzf-lua"
|
||||
},
|
||||
"gitsigns.nvim": {
|
||||
"rev": "8d82c240f190fc33723d48c308ccc1ed8baad69d",
|
||||
"src": "https://www.github.com/lewis6991/gitsigns.nvim"
|
||||
},
|
||||
"img-clip.nvim": {
|
||||
"rev": "b6ddfb97b5600d99afe3452d707444afda658aca",
|
||||
"src": "https://github.com/HakonHarnes/img-clip.nvim"
|
||||
},
|
||||
"lualine.nvim": {
|
||||
"rev": "a905eeebc4e63fdc48b5135d3bf8aea5618fb21c",
|
||||
"src": "https://github.com/nvim-lualine/lualine.nvim"
|
||||
},
|
||||
"mason-tool-installer.nvim": {
|
||||
"rev": "443f1ef8b5e6bf47045cb2217b6f748a223cf7dc",
|
||||
"src": "https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim"
|
||||
},
|
||||
"mason.nvim": {
|
||||
"rev": "b03fb0f20bc1d43daf558cda981a2be22e73ac42",
|
||||
"src": "https://github.com/mason-org/mason.nvim"
|
||||
},
|
||||
"mini.nvim": {
|
||||
"rev": "4182d64727fb4876407af65c181b85428a4a70d1",
|
||||
"src": "https://www.github.com/echasnovski/mini.nvim"
|
||||
},
|
||||
"nvim-lspconfig": {
|
||||
"rev": "cb5bc0b2b35a6d513e3298d285db81453e791f4f",
|
||||
"src": "https://www.github.com/neovim/nvim-lspconfig"
|
||||
},
|
||||
"nvim-treesitter": {
|
||||
"rev": "4916d6592ede8c07973490d9322f187e07dfefac",
|
||||
"src": "https://github.com/nvim-treesitter/nvim-treesitter"
|
||||
},
|
||||
"nvim-treesitter-textobjects": {
|
||||
"rev": "851e865342e5a4cb1ae23d31caf6e991e1c99f1e",
|
||||
"src": "https://github.com/nvim-treesitter/nvim-treesitter-textobjects"
|
||||
},
|
||||
"tokyonight.nvim": {
|
||||
"rev": "cdc07ac78467a233fd62c493de29a17e0cf2b2b6",
|
||||
"src": "https://github.com/folke/tokyonight.nvim"
|
||||
},
|
||||
"which-key.nvim": {
|
||||
"rev": "3aab2147e74890957785941f0c1ad87d0a44c15a",
|
||||
"src": "https://github.com/folke/which-key.nvim"
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,224 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
-- C/kernel-doc style: /** ... @param: ... Return: ... */
|
||||
local function generate_c_doc(bufnr, row, line)
|
||||
-- strip static/inline/extern prefixes
|
||||
local stripped = line:gsub("^%s*static%s+", ""):gsub("^%s*inline%s+", ""):gsub("^%s*extern%s+", "")
|
||||
|
||||
-- match: type *func_name(params) or type* func_name(params)
|
||||
local ret, name, params = stripped:match("^%s*([%w_]+%s*%**)%s*([%w_]+)%s*%((.*)%)%s*{?%s*$")
|
||||
if not name then
|
||||
return nil, "No C function signature found on current line"
|
||||
end
|
||||
|
||||
local doc = { "/**", " * " .. name .. "() - " }
|
||||
|
||||
-- parse parameters
|
||||
if params and params:match("%S") and not params:match("^%s*void%s*$") then
|
||||
for param in params:gmatch("([^,]+)") do
|
||||
local pname = param:match("([%w_]+)%s*$")
|
||||
or param:match("%*%s*([%w_]+)")
|
||||
or param:match("([%w_]+)%s*%[")
|
||||
if pname then
|
||||
table.insert(doc, " * @" .. pname .. ": ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(doc, " *")
|
||||
|
||||
-- add Return: if not void
|
||||
ret = ret and ret:gsub("%s+", " "):gsub("^%s*", ""):gsub("%s*$", "") or ""
|
||||
if ret ~= "void" and ret ~= "" then
|
||||
table.insert(doc, " * Return: ")
|
||||
end
|
||||
|
||||
table.insert(doc, " */")
|
||||
return doc, nil
|
||||
end
|
||||
|
||||
-- Go style: // FunctionName does something.
|
||||
local function generate_go_doc(bufnr, row, line)
|
||||
-- match: func (receiver) name(params) return or func name(params) return
|
||||
local name, params, ret
|
||||
|
||||
-- method with receiver: func (r *Receiver) Name(params) return
|
||||
name, params, ret = line:match("^%s*func%s+%([^)]+%)%s+([%w_]+)%s*%((.-)%)%s*(.-)%s*{?%s*$")
|
||||
|
||||
-- regular function: func Name(params) return
|
||||
if not name then
|
||||
name, params, ret = line:match("^%s*func%s+([%w_]+)%s*%((.-)%)%s*(.-)%s*{?%s*$")
|
||||
end
|
||||
|
||||
if not name then
|
||||
return nil, "No Go function signature found on current line"
|
||||
end
|
||||
|
||||
local doc = { "// " .. name .. " " }
|
||||
|
||||
-- add parameter hints if present
|
||||
if params and params:match("%S") then
|
||||
local param_names = {}
|
||||
for param in params:gmatch("([^,]+)") do
|
||||
-- Go params: name type or name, name2 type
|
||||
local pname = param:match("^%s*([%w_]+)")
|
||||
if pname then
|
||||
table.insert(param_names, pname)
|
||||
end
|
||||
end
|
||||
if #param_names > 0 then
|
||||
table.insert(doc, "//")
|
||||
table.insert(doc, "// Parameters:")
|
||||
for _, pname in ipairs(param_names) do
|
||||
table.insert(doc, "// - " .. pname .. ": ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- add return hint if present
|
||||
ret = ret and ret:gsub("^%s*", ""):gsub("%s*$", "") or ""
|
||||
if ret ~= "" and ret ~= "error" then
|
||||
table.insert(doc, "//")
|
||||
table.insert(doc, "// Returns: ")
|
||||
end
|
||||
|
||||
return doc, nil
|
||||
end
|
||||
|
||||
-- Rust style: /// Description
|
||||
local function generate_rust_doc(bufnr, row, line)
|
||||
-- match: fn name(params) -> return or pub fn name...
|
||||
local name, params, ret = line:match("^%s*pub%s+fn%s+([%w_]+)%s*%((.-)%)%s*%->%s*(.-)%s*{?%s*$")
|
||||
if not name then
|
||||
name, params, ret = line:match("^%s*fn%s+([%w_]+)%s*%((.-)%)%s*%->%s*(.-)%s*{?%s*$")
|
||||
end
|
||||
if not name then
|
||||
name, params = line:match("^%s*pub%s+fn%s+([%w_]+)%s*%((.-)%)%s*{?%s*$")
|
||||
end
|
||||
if not name then
|
||||
name, params = line:match("^%s*fn%s+([%w_]+)%s*%((.-)%)%s*{?%s*$")
|
||||
end
|
||||
|
||||
if not name then
|
||||
return nil, "No Rust function signature found on current line"
|
||||
end
|
||||
|
||||
local doc = { "/// " }
|
||||
|
||||
-- add parameter hints if present
|
||||
if params and params:match("%S") then
|
||||
local param_names = {}
|
||||
for param in params:gmatch("([^,]+)") do
|
||||
local pname = param:match("^%s*([%w_]+)%s*:")
|
||||
if pname and pname ~= "self" and pname ~= "&self" and pname ~= "&mut" then
|
||||
table.insert(param_names, pname)
|
||||
end
|
||||
end
|
||||
if #param_names > 0 then
|
||||
table.insert(doc, "///")
|
||||
table.insert(doc, "/// # Arguments")
|
||||
table.insert(doc, "///")
|
||||
for _, pname in ipairs(param_names) do
|
||||
table.insert(doc, "/// * `" .. pname .. "` - ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- add return hint if present
|
||||
ret = ret and ret:gsub("^%s*", ""):gsub("%s*$", "") or ""
|
||||
if ret ~= "" then
|
||||
table.insert(doc, "///")
|
||||
table.insert(doc, "/// # Returns")
|
||||
table.insert(doc, "///")
|
||||
table.insert(doc, "/// ")
|
||||
end
|
||||
|
||||
return doc, nil
|
||||
end
|
||||
|
||||
-- Python style: """docstring"""
|
||||
local function generate_python_doc(bufnr, row, line)
|
||||
local name, params = line:match("^%s*def%s+([%w_]+)%s*%((.-)%)%s*:?%s*$")
|
||||
if not name then
|
||||
name, params = line:match("^%s*async%s+def%s+([%w_]+)%s*%((.-)%)%s*:?%s*$")
|
||||
end
|
||||
|
||||
if not name then
|
||||
return nil, "No Python function signature found on current line"
|
||||
end
|
||||
|
||||
local indent = line:match("^(%s*)") or ""
|
||||
local doc = { indent .. ' """' }
|
||||
|
||||
-- parse parameters
|
||||
if params and params:match("%S") then
|
||||
local param_names = {}
|
||||
for param in params:gmatch("([^,]+)") do
|
||||
local pname = param:match("^%s*([%w_]+)")
|
||||
if pname and pname ~= "self" and pname ~= "cls" then
|
||||
table.insert(param_names, pname)
|
||||
end
|
||||
end
|
||||
if #param_names > 0 then
|
||||
table.insert(doc, indent .. "")
|
||||
table.insert(doc, indent .. " Args:")
|
||||
for _, pname in ipairs(param_names) do
|
||||
table.insert(doc, indent .. " " .. pname .. ": ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(doc, indent .. "")
|
||||
table.insert(doc, indent .. " Returns:")
|
||||
table.insert(doc, indent .. " ")
|
||||
table.insert(doc, indent .. ' """')
|
||||
|
||||
return doc, nil
|
||||
end
|
||||
|
||||
-- filetype to generator mapping
|
||||
local generators = {
|
||||
c = generate_c_doc,
|
||||
cpp = generate_c_doc,
|
||||
h = generate_c_doc,
|
||||
go = generate_go_doc,
|
||||
rust = generate_rust_doc,
|
||||
python = generate_python_doc,
|
||||
}
|
||||
|
||||
function M.generate_doc()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||
local line = vim.api.nvim_buf_get_lines(bufnr, row - 1, row, false)[1]
|
||||
local ft = vim.bo[bufnr].filetype
|
||||
|
||||
local generator = generators[ft]
|
||||
if not generator then
|
||||
vim.notify("No doc generator for filetype: " .. ft, vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local doc, err = generator(bufnr, row, line)
|
||||
if err then
|
||||
vim.notify(err, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_set_lines(bufnr, row - 1, row - 1, false, doc)
|
||||
|
||||
-- position cursor at first empty description spot
|
||||
local cursor_row = row
|
||||
local cursor_col = #doc[1]
|
||||
for i, docline in ipairs(doc) do
|
||||
if docline:match("%s$") or docline:match(":%s*$") or docline:match("%-%s*$") then
|
||||
cursor_row = row + i - 1
|
||||
cursor_col = #docline
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { cursor_row, cursor_col })
|
||||
vim.cmd("startinsert!")
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<leader>dg", M.generate_doc)
|
||||
@@ -1,55 +0,0 @@
|
||||
-- Remap leaving 'terminal mode' to double tap esc
|
||||
vim.keymap.set("t", "<esc><esc>", "<c-\\><c-n>")
|
||||
|
||||
local state = {
|
||||
floating = {
|
||||
buf = -1,
|
||||
win = -1,
|
||||
}
|
||||
}
|
||||
|
||||
local function open_floating_terminal(opts)
|
||||
opts = opts or {}
|
||||
local width = opts.width or math.floor(vim.o.columns * 0.8)
|
||||
local height = opts.height or math.floor(vim.o.lines * 0.8)
|
||||
|
||||
local row = math.floor((vim.o.lines - height) / 2)
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
|
||||
local buf = nil
|
||||
if vim.api.nvim_buf_is_valid(opts.buf) then
|
||||
buf = opts.buf
|
||||
else
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
end
|
||||
if not buf then
|
||||
error("Failed to create buffer")
|
||||
end
|
||||
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = 'editor',
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = 'minimal',
|
||||
border = 'rounded',
|
||||
})
|
||||
|
||||
return { buf = buf, win = win }
|
||||
end
|
||||
|
||||
local toggle_terminal = function()
|
||||
if not vim.api.nvim_win_is_valid(state.floating.win) then
|
||||
state.floating = open_floating_terminal({ buf = state.floating.buf });
|
||||
if vim.bo[state.floating.buf].buftype ~= "terminal" then
|
||||
vim.cmd.terminal()
|
||||
vim.cmd("startinsert!")
|
||||
end
|
||||
else
|
||||
vim.api.nvim_win_hide(state.floating.win)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("Flterm", toggle_terminal, {})
|
||||
vim.api.nvim_set_keymap('n', '<leader>ft', [[:Flterm<CR>]], { noremap = true, silent = true })
|
||||
@@ -1,283 +0,0 @@
|
||||
vim.lsp.config('*', {
|
||||
root_markers = { '.git' },
|
||||
})
|
||||
|
||||
vim.diagnostic.config({
|
||||
virtual_text = true,
|
||||
severity_sort = true,
|
||||
float = {
|
||||
style = 'minimal',
|
||||
border = 'rounded',
|
||||
source = 'if_many',
|
||||
header = '',
|
||||
prefix = '',
|
||||
},
|
||||
signs = {
|
||||
text = {
|
||||
[vim.diagnostic.severity.ERROR] = '✘',
|
||||
[vim.diagnostic.severity.WARN] = '▲',
|
||||
[vim.diagnostic.severity.HINT] = '⚑',
|
||||
[vim.diagnostic.severity.INFO] = '»',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
local orig = vim.lsp.util.open_floating_preview
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
|
||||
opts = opts or {}
|
||||
opts.border = opts.border or 'rounded'
|
||||
opts.max_width = opts.max_width or 80
|
||||
opts.max_height = opts.max_height or 24
|
||||
opts.wrap = opts.wrap ~= false
|
||||
return orig(contents, syntax, opts, ...)
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = vim.api.nvim_create_augroup('my.lsp', {}),
|
||||
callback = function(args)
|
||||
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
|
||||
local buf = args.buf
|
||||
local map = function(mode, lhs, rhs) vim.keymap.set(mode, lhs, rhs, { buffer = buf }) end
|
||||
|
||||
map('n', 'K', vim.lsp.buf.hover)
|
||||
map('n', 'gd', vim.lsp.buf.definition)
|
||||
map('n', 'gD', vim.lsp.buf.declaration)
|
||||
map('n', 'gi', vim.lsp.buf.implementation)
|
||||
map('n', 'go', vim.lsp.buf.type_definition)
|
||||
map('n', 'gr', vim.lsp.buf.references)
|
||||
map('n', 'gs', vim.lsp.buf.signature_help)
|
||||
map('n', 'gl', vim.diagnostic.open_float)
|
||||
map('n', '<F2>', vim.lsp.buf.rename)
|
||||
map({ 'n', 'x' }, '<F3>', function() vim.lsp.buf.format({ async = true }) end)
|
||||
map('n', '<F4>', vim.lsp.buf.code_action)
|
||||
|
||||
if client:supports_method('textDocument/documentHighlight') then
|
||||
local highlight_augroup = vim.api.nvim_create_augroup('my.lsp.highlight', { clear = false })
|
||||
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
|
||||
buffer = buf,
|
||||
group = highlight_augroup,
|
||||
callback = vim.lsp.buf.document_highlight,
|
||||
})
|
||||
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
|
||||
buffer = buf,
|
||||
group = highlight_augroup,
|
||||
callback = vim.lsp.buf.clear_references,
|
||||
})
|
||||
end
|
||||
|
||||
local excluded_filetypes = { php = true, c = true, cpp = true }
|
||||
if not client:supports_method('textDocument/willSaveWaitUntil')
|
||||
and client:supports_method('textDocument/formatting')
|
||||
and not excluded_filetypes[vim.bo[buf].filetype]
|
||||
then
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
group = vim.api.nvim_create_augroup('my.lsp.format', { clear = false }),
|
||||
buffer = buf,
|
||||
callback = function()
|
||||
vim.lsp.buf.format({ bufnr = buf, id = client.id, timeout_ms = 1000 })
|
||||
end,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
local caps = require("cmp_nvim_lsp").default_capabilities()
|
||||
vim.lsp.config['luals'] = {
|
||||
cmd = { 'lua-language-server' },
|
||||
filetypes = { 'lua' },
|
||||
root_markers = { { '.luarc.json', '.luarc.jsonc' }, '.git' },
|
||||
capabilities = caps,
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = { version = 'LuaJIT' },
|
||||
diagnostics = { globals = { 'vim' } },
|
||||
workspace = {
|
||||
checkThirdParty = false,
|
||||
library = vim.list_extend(
|
||||
vim.api.nvim_get_runtime_file('', true),
|
||||
{ '/home/tony/repos/oxwm/templates' }
|
||||
),
|
||||
},
|
||||
telemetry = { enable = false },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
vim.lsp.config['cssls'] = {
|
||||
cmd = { 'vscode-css-language-server', '--stdio' },
|
||||
filetypes = { 'css', 'scss', 'less' },
|
||||
root_markers = { 'package.json', '.git' },
|
||||
capabilities = caps,
|
||||
settings = {
|
||||
css = { validate = true },
|
||||
scss = { validate = true },
|
||||
less = { validate = true },
|
||||
},
|
||||
}
|
||||
|
||||
vim.lsp.config['phpls'] = {
|
||||
cmd = { 'intelephense', '--stdio' },
|
||||
filetypes = { 'php' },
|
||||
root_markers = { 'composer.json', '.git' },
|
||||
capabilities = caps,
|
||||
settings = {
|
||||
intelephense = {
|
||||
files = {
|
||||
maxSize = 5000000, -- default 5MB
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
vim.lsp.config['ts_ls'] = {
|
||||
cmd = { 'typescript-language-server', '--stdio' },
|
||||
filetypes = {
|
||||
'javascript', 'javascriptreact', 'javascript.jsx',
|
||||
'typescript', 'typescriptreact', 'typescript.tsx',
|
||||
},
|
||||
root_markers = { 'package.json', 'tsconfig.json', 'jsconfig.json', '.git' },
|
||||
capabilities = caps,
|
||||
settings = {
|
||||
completions = {
|
||||
completeFunctionCalls = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
vim.lsp.config['zls'] = {
|
||||
cmd = { 'zls' },
|
||||
filetypes = { 'zig', 'zir' },
|
||||
root_markers = { 'zls.json', 'build.zig', '.git' },
|
||||
capabilities = caps,
|
||||
settings = {
|
||||
zls = {
|
||||
enable_build_on_save = true,
|
||||
build_on_save_step = "install",
|
||||
warn_style = false,
|
||||
enable_snippets = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vim.lsp.config['nil_ls'] = {
|
||||
cmd = { 'nil' },
|
||||
filetypes = { 'nix' },
|
||||
root_markers = { 'flake.nix', 'default.nix', '.git' },
|
||||
capabilities = caps,
|
||||
settings = {
|
||||
['nil'] = {
|
||||
formatting = {
|
||||
command = { "alejandra" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vim.lsp.config['rust_analyzer'] = {
|
||||
cmd = { 'rust-analyzer' },
|
||||
filetypes = { 'rust' },
|
||||
root_markers = { 'Cargo.toml', 'rust-project.json', '.git' },
|
||||
capabilities = caps,
|
||||
settings = {
|
||||
['rust-analyzer'] = {
|
||||
cargo = { allFeatures = true },
|
||||
formatting = {
|
||||
command = { "rustfmt" }
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- C / C++ via clangd
|
||||
vim.lsp.config['clangd'] = {
|
||||
cmd = {
|
||||
'clangd',
|
||||
-- '--background-index',
|
||||
-- '--clang-tidy',
|
||||
-- '--header-insertion=never',
|
||||
-- '--completion-style=detailed',
|
||||
-- '--query-driver=/nix/store/*-gcc-*/bin/gcc*,/nix/store/*-clang-*/bin/clang*,/run/current-system/sw/bin/cc*',
|
||||
},
|
||||
filetypes = { 'c', 'cpp', 'objc', 'objcpp' },
|
||||
root_markers = { 'compile_commands.json', '.clangd', 'configure.ac', 'Makefile', '.git' },
|
||||
capabilities = caps,
|
||||
-- init_options = {
|
||||
-- fallbackFlags = { '-std=c23' }, -- Default to C23
|
||||
-- },
|
||||
}
|
||||
|
||||
vim.lsp.config['c3lsp'] = {
|
||||
cmd = { 'c3-lsp' },
|
||||
filetypes = { 'c3' },
|
||||
root_markers = { 'project.json', '.git' },
|
||||
capabilities = caps,
|
||||
}
|
||||
|
||||
vim.lsp.config['serve_d'] = {
|
||||
cmd = { 'serve-d' },
|
||||
filetypes = { 'd' },
|
||||
root_markers = { 'dub.sdl', 'dub.json', '.git' },
|
||||
capabilities = caps,
|
||||
}
|
||||
|
||||
vim.lsp.config['jsonls'] = {
|
||||
cmd = { 'vscode-json-languageserver', '--stdio' },
|
||||
filetypes = { 'json', 'jsonc' },
|
||||
root_markers = { 'package.json', '.git', 'config.jsonc' },
|
||||
capabilities = caps,
|
||||
}
|
||||
|
||||
vim.lsp.config['hls'] = {
|
||||
cmd = { 'haskell-language-server-wrapper', '--lsp' },
|
||||
filetypes = { 'haskell', 'lhaskell' },
|
||||
root_markers = { 'stack.yaml', 'cabal.project', 'package.yaml', '*.cabal', 'hie.yaml', '.git' },
|
||||
capabilities = caps,
|
||||
settings = {
|
||||
haskell = {
|
||||
formattingProvider = 'fourmolu',
|
||||
plugin = {
|
||||
semanticTokens = { globalOn = false }
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
vim.lsp.config['gopls'] = {
|
||||
cmd = { 'gopls' },
|
||||
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
|
||||
root_markers = { 'go.mod', 'go.work', '.git' },
|
||||
capabilities = caps,
|
||||
settings = {
|
||||
gopls = {
|
||||
analyses = {
|
||||
unusedparams = false,
|
||||
ST1003 = false,
|
||||
ST1000 = false,
|
||||
},
|
||||
staticcheck = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
vim.lsp.config['templ'] = {
|
||||
cmd = { 'templ', 'lsp' },
|
||||
filetypes = { 'templ' },
|
||||
root_markers = { 'go.mod', '.git' },
|
||||
capabilities = caps,
|
||||
}
|
||||
|
||||
vim.filetype.add({
|
||||
extension = {
|
||||
h = 'c',
|
||||
c3 = 'c3',
|
||||
d = 'd',
|
||||
templ = 'templ',
|
||||
},
|
||||
})
|
||||
|
||||
---@diagnostic disable-next-line: invisible
|
||||
for name, _ in pairs(vim.lsp.config._configs) do
|
||||
if name ~= '*' then
|
||||
vim.lsp.enable(name)
|
||||
end
|
||||
end
|
||||
@@ -1,40 +0,0 @@
|
||||
local function reformat_parenthesized_content()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||
local line = vim.api.nvim_buf_get_lines(bufnr, row - 1, row, false)[1]
|
||||
|
||||
local inside = line:match("%((.-)%)")
|
||||
if not inside then
|
||||
vim.notify(
|
||||
"No content found inside parentheses",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
local prefix = line:match("^(.-)%(") or ""
|
||||
local suffix = line:match("%)(.*)$") or ""
|
||||
|
||||
local parts = vim.split(inside, ",%s*")
|
||||
if #parts == 0 then
|
||||
vim.notify("No comma-separated content found", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
local new_lines = {}
|
||||
table.insert(new_lines, prefix .. "(")
|
||||
for i, part in ipairs(parts) do
|
||||
if i < #parts then
|
||||
table.insert(new_lines, " " .. part .. ",")
|
||||
else
|
||||
table.insert(new_lines, " " .. part)
|
||||
end
|
||||
end
|
||||
table.insert(new_lines, " )" .. suffix)
|
||||
|
||||
vim.api.nvim_buf_set_lines(bufnr, row - 1, row, false, new_lines)
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<leader>qq", function()
|
||||
reformat_parenthesized_content()
|
||||
end)
|
||||
@@ -1,110 +0,0 @@
|
||||
-- Minimal sticky context header. Replaces nvim-treesitter-context.
|
||||
-- Shows the first line of the enclosing function/class pinned to the
|
||||
-- top of the window when that line has scrolled offscreen above.
|
||||
--
|
||||
-- One level of context only (innermost enclosing). Extend CONTEXT_TYPES
|
||||
-- to support more languages or richer node kinds.
|
||||
--
|
||||
-- Toggle:
|
||||
-- <leader>th hide
|
||||
-- <leader>tu unhide
|
||||
|
||||
local M = { enabled = true }
|
||||
local ctx_buf, ctx_win
|
||||
|
||||
local CONTEXT_TYPES = {
|
||||
-- C / PHP
|
||||
function_definition = true,
|
||||
method_declaration = true,
|
||||
class_declaration = true,
|
||||
-- Lua
|
||||
function_declaration = true,
|
||||
-- Rust
|
||||
function_item = true,
|
||||
impl_item = true,
|
||||
trait_item = true,
|
||||
-- Go (function_declaration shared)
|
||||
-- JS
|
||||
method_definition = true,
|
||||
arrow_function = true,
|
||||
-- Zig
|
||||
fn_proto = true,
|
||||
-- Nix
|
||||
function_expression = true,
|
||||
}
|
||||
|
||||
local function close_ctx()
|
||||
if ctx_win and vim.api.nvim_win_is_valid(ctx_win) then
|
||||
vim.api.nvim_win_close(ctx_win, true)
|
||||
end
|
||||
ctx_win = nil
|
||||
end
|
||||
|
||||
local function update_ctx()
|
||||
if not M.enabled then close_ctx() return end
|
||||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local node = vim.treesitter.get_node()
|
||||
if not node then close_ctx() return end
|
||||
|
||||
while node and not CONTEXT_TYPES[node:type()] do
|
||||
node = node:parent()
|
||||
end
|
||||
if not node then close_ctx() return end
|
||||
|
||||
local sr = node:start()
|
||||
local top_visible = vim.fn.line("w0") - 1
|
||||
if sr >= top_visible then close_ctx() return end
|
||||
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, sr, sr + 1, false)
|
||||
if #lines == 0 then close_ctx() return end
|
||||
|
||||
if not ctx_buf or not vim.api.nvim_buf_is_valid(ctx_buf) then
|
||||
ctx_buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.bo[ctx_buf].buftype = "nofile"
|
||||
end
|
||||
vim.api.nvim_buf_set_lines(ctx_buf, 0, -1, false, lines)
|
||||
vim.bo[ctx_buf].filetype = vim.bo[bufnr].filetype
|
||||
|
||||
local config = {
|
||||
relative = "win",
|
||||
win = vim.api.nvim_get_current_win(),
|
||||
row = 0,
|
||||
col = 0,
|
||||
width = vim.api.nvim_win_get_width(0),
|
||||
height = 1,
|
||||
focusable = false,
|
||||
style = "minimal",
|
||||
zindex = 20,
|
||||
}
|
||||
if ctx_win and vim.api.nvim_win_is_valid(ctx_win) then
|
||||
vim.api.nvim_win_set_config(ctx_win, config)
|
||||
else
|
||||
ctx_win = vim.api.nvim_open_win(ctx_buf, false, config)
|
||||
vim.wo[ctx_win].winhighlight = "Normal:TonyContext,NormalFloat:TonyContext"
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_set_hl(0, "TonyContext", { link = "NormalFloat", default = true })
|
||||
|
||||
local group = vim.api.nvim_create_augroup("TonyContext", { clear = true })
|
||||
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI", "WinScrolled", "BufEnter" }, {
|
||||
group = group,
|
||||
callback = update_ctx,
|
||||
})
|
||||
vim.api.nvim_create_autocmd({ "BufLeave", "WinLeave" }, {
|
||||
group = group,
|
||||
callback = close_ctx,
|
||||
})
|
||||
|
||||
vim.keymap.set("n", "<leader>th", function()
|
||||
M.enabled = false
|
||||
close_ctx()
|
||||
end, { desc = "Hide context header" })
|
||||
|
||||
vim.keymap.set("n", "<leader>tu", function()
|
||||
M.enabled = true
|
||||
update_ctx()
|
||||
end, { desc = "Unhide context header" })
|
||||
|
||||
return M
|
||||
@@ -1,85 +0,0 @@
|
||||
-- Local treesitter setup. Replaces nvim-treesitter + nvim-treesitter-textobjects.
|
||||
-- Parsers: ~/.config/nvim/parser/<lang>.so
|
||||
-- Queries: ~/.config/nvim/queries/<lang>/
|
||||
|
||||
-- Start treesitter highlighting on FileType when a parser is available.
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
callback = function(args)
|
||||
pcall(vim.treesitter.start, args.buf)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Function text objects: af / if
|
||||
-- Walks the textobjects query for the buffer's language and selects the
|
||||
-- smallest @function.outer / @function.inner range containing the cursor.
|
||||
local function select_function(capture)
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local ok, parser = pcall(vim.treesitter.get_parser, bufnr)
|
||||
if not ok or not parser then return end
|
||||
|
||||
local lang = parser:lang()
|
||||
local query = vim.treesitter.query.get(lang, "textobjects")
|
||||
if not query then return end
|
||||
|
||||
local tree = parser:parse()[1]
|
||||
if not tree then return end
|
||||
local root = tree:root()
|
||||
|
||||
local cur = vim.api.nvim_win_get_cursor(0)
|
||||
local crow, ccol = cur[1] - 1, cur[2]
|
||||
|
||||
-- A single textobject (e.g. @function.inner) is often split across
|
||||
-- multiple captures within the same match (e.g. one per statement in
|
||||
-- the body). Use iter_matches and union the ranges of all captures
|
||||
-- with our target name within each match.
|
||||
local best, best_size
|
||||
for _, match in query:iter_matches(root, bufnr, 0, -1, { all = true }) do
|
||||
local min_sr, min_sc, max_er, max_ec
|
||||
for id, nodes in pairs(match) do
|
||||
if query.captures[id] == capture then
|
||||
if type(nodes) ~= "table" then nodes = { nodes } end
|
||||
for _, node in ipairs(nodes) do
|
||||
local sr, sc, er, ec = node:range()
|
||||
if not min_sr or sr < min_sr or (sr == min_sr and sc < min_sc) then
|
||||
min_sr, min_sc = sr, sc
|
||||
end
|
||||
if not max_er or er > max_er or (er == max_er and ec > max_ec) then
|
||||
max_er, max_ec = er, ec
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if min_sr then
|
||||
local contains = (min_sr < crow or (min_sr == crow and min_sc <= ccol))
|
||||
and (max_er > crow or (max_er == crow and max_ec >= ccol))
|
||||
if contains then
|
||||
local size = (max_er - min_sr) * 1e6 + (max_ec - min_sc)
|
||||
if not best_size or size < best_size then
|
||||
best_size = size
|
||||
best = { min_sr, min_sc, max_er, max_ec }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not best then return end
|
||||
local sr, sc, er, ec = best[1], best[2], best[3], best[4]
|
||||
|
||||
-- If we were invoked from visual mode (`vif`, `vaf`, etc.), exit it
|
||||
-- first — otherwise `normal! v` below would toggle visual off instead
|
||||
-- of re-entering it, and we'd end up only moving the cursor.
|
||||
local mode = vim.fn.mode()
|
||||
if mode == "v" or mode == "V" or mode == "\22" then
|
||||
vim.api.nvim_feedkeys(
|
||||
vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "nx", false)
|
||||
end
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { sr + 1, sc })
|
||||
vim.cmd("normal! v")
|
||||
vim.api.nvim_win_set_cursor(0, { er + 1, math.max(0, ec - 1) })
|
||||
end
|
||||
|
||||
vim.keymap.set({ "x", "o" }, "af", function() select_function("function.outer") end,
|
||||
{ desc = "around function" })
|
||||
vim.keymap.set({ "x", "o" }, "if", function() select_function("function.inner") end,
|
||||
{ desc = "inside function" })
|
||||
@@ -1,23 +0,0 @@
|
||||
[
|
||||
(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)
|
||||
@@ -1,341 +0,0 @@
|
||||
; 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 template_method 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
|
||||
@@ -1,128 +0,0 @@
|
||||
((preproc_arg) @injection.content
|
||||
(#set! injection.language "c"))
|
||||
|
||||
((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 "/[*\/][!*\/]<?[^a-zA-Z]")
|
||||
(#set! injection.language "doxygen"))
|
||||
|
||||
((call_expression
|
||||
function: (identifier) @_function
|
||||
arguments: (argument_list
|
||||
.
|
||||
[
|
||||
(string_literal
|
||||
(string_content) @injection.content)
|
||||
(concatenated_string
|
||||
(string_literal
|
||||
(string_content) @injection.content))
|
||||
]))
|
||||
; format-ignore
|
||||
(#any-of? @_function
|
||||
"printf" "printf_s"
|
||||
"vprintf" "vprintf_s"
|
||||
"scanf" "scanf_s"
|
||||
"vscanf" "vscanf_s"
|
||||
"wprintf" "wprintf_s"
|
||||
"vwprintf" "vwprintf_s"
|
||||
"wscanf" "wscanf_s"
|
||||
"vwscanf" "vwscanf_s"
|
||||
"cscanf" "_cscanf"
|
||||
"printw"
|
||||
"scanw")
|
||||
(#set! injection.language "printf"))
|
||||
|
||||
((call_expression
|
||||
function: (identifier) @_function
|
||||
arguments: (argument_list
|
||||
(_)
|
||||
.
|
||||
[
|
||||
(string_literal
|
||||
(string_content) @injection.content)
|
||||
(concatenated_string
|
||||
(string_literal
|
||||
(string_content) @injection.content))
|
||||
]))
|
||||
; format-ignore
|
||||
(#any-of? @_function
|
||||
"fprintf" "fprintf_s"
|
||||
"sprintf"
|
||||
"dprintf"
|
||||
"fscanf" "fscanf_s"
|
||||
"sscanf" "sscanf_s"
|
||||
"vsscanf" "vsscanf_s"
|
||||
"vfprintf" "vfprintf_s"
|
||||
"vsprintf"
|
||||
"vdprintf"
|
||||
"fwprintf" "fwprintf_s"
|
||||
"vfwprintf" "vfwprintf_s"
|
||||
"fwscanf" "fwscanf_s"
|
||||
"swscanf" "swscanf_s"
|
||||
"vswscanf" "vswscanf_s"
|
||||
"vfscanf" "vfscanf_s"
|
||||
"vfwscanf" "vfwscanf_s"
|
||||
"wprintw"
|
||||
"vw_printw" "vwprintw"
|
||||
"wscanw"
|
||||
"vw_scanw" "vwscanw")
|
||||
(#set! injection.language "printf"))
|
||||
|
||||
((call_expression
|
||||
function: (identifier) @_function
|
||||
arguments: (argument_list
|
||||
(_)
|
||||
.
|
||||
(_)
|
||||
.
|
||||
[
|
||||
(string_literal
|
||||
(string_content) @injection.content)
|
||||
(concatenated_string
|
||||
(string_literal
|
||||
(string_content) @injection.content))
|
||||
]))
|
||||
; format-ignore
|
||||
(#any-of? @_function
|
||||
"sprintf_s"
|
||||
"snprintf" "snprintf_s"
|
||||
"vsprintf_s"
|
||||
"vsnprintf" "vsnprintf_s"
|
||||
"swprintf" "swprintf_s"
|
||||
"snwprintf_s"
|
||||
"vswprintf" "vswprintf_s"
|
||||
"vsnwprintf_s"
|
||||
"mvprintw"
|
||||
"mvscanw")
|
||||
(#set! injection.language "printf"))
|
||||
|
||||
((call_expression
|
||||
function: (identifier) @_function
|
||||
arguments: (argument_list
|
||||
(_)
|
||||
.
|
||||
(_)
|
||||
.
|
||||
(_)
|
||||
.
|
||||
[
|
||||
(string_literal
|
||||
(string_content) @injection.content)
|
||||
(concatenated_string
|
||||
(string_literal
|
||||
(string_content) @injection.content))
|
||||
]))
|
||||
(#any-of? @_function "mvwprintw" "mvwscanw")
|
||||
(#set! injection.language "printf"))
|
||||
|
||||
; TODO: add when asm is added
|
||||
; (gnu_asm_expression assembly_code: (string_literal) @injection.content
|
||||
; (#set! injection.language "asm"))
|
||||
; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @injection.content)
|
||||
; (#set! injection.language "asm"))
|
||||
@@ -1,67 +0,0 @@
|
||||
; Functions definitions
|
||||
(function_declarator
|
||||
declarator: (identifier) @local.definition.function)
|
||||
|
||||
(preproc_function_def
|
||||
name: (identifier) @local.definition.macro) @local.scope
|
||||
|
||||
(preproc_def
|
||||
name: (identifier) @local.definition.macro)
|
||||
|
||||
(pointer_declarator
|
||||
declarator: (identifier) @local.definition.var)
|
||||
|
||||
(parameter_declaration
|
||||
declarator: (identifier) @local.definition.parameter)
|
||||
|
||||
(init_declarator
|
||||
declarator: (identifier) @local.definition.var)
|
||||
|
||||
(array_declarator
|
||||
declarator: (identifier) @local.definition.var)
|
||||
|
||||
(declaration
|
||||
declarator: (identifier) @local.definition.var)
|
||||
|
||||
(enum_specifier
|
||||
name: (_) @local.definition.type
|
||||
(enumerator_list
|
||||
(enumerator
|
||||
name: (identifier) @local.definition.var)))
|
||||
|
||||
; Type / Struct / Enum
|
||||
(field_declaration
|
||||
declarator: (field_identifier) @local.definition.field)
|
||||
|
||||
(type_definition
|
||||
declarator: (type_identifier) @local.definition.type)
|
||||
|
||||
(struct_specifier
|
||||
name: (type_identifier) @local.definition.type)
|
||||
|
||||
; goto
|
||||
(labeled_statement
|
||||
(statement_identifier) @local.definition)
|
||||
|
||||
; References
|
||||
(identifier) @local.reference
|
||||
|
||||
((field_identifier) @local.reference
|
||||
(#set! reference.kind "field"))
|
||||
|
||||
((type_identifier) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
(goto_statement
|
||||
(statement_identifier) @local.reference)
|
||||
|
||||
; Scope
|
||||
[
|
||||
(for_statement)
|
||||
(if_statement)
|
||||
(while_statement)
|
||||
(translation_unit)
|
||||
(function_definition)
|
||||
(compound_statement) ; a block in curly braces
|
||||
(struct_specifier)
|
||||
] @local.scope
|
||||
@@ -1,151 +0,0 @@
|
||||
(declaration
|
||||
declarator: (function_declarator)) @function.outer
|
||||
|
||||
(function_definition
|
||||
body: (compound_statement)) @function.outer
|
||||
|
||||
(function_definition
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
(struct_specifier
|
||||
body: (_) @class.inner) @class.outer
|
||||
|
||||
(enum_specifier
|
||||
body: (_) @class.inner) @class.outer
|
||||
|
||||
; conditionals
|
||||
(if_statement
|
||||
consequence: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @conditional.inner
|
||||
"}")) @conditional.outer
|
||||
|
||||
(if_statement
|
||||
alternative: (else_clause
|
||||
(compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @conditional.inner
|
||||
"}"))) @conditional.outer
|
||||
|
||||
(if_statement) @conditional.outer
|
||||
|
||||
(if_statement
|
||||
condition: (_) @conditional.inner
|
||||
(#offset! @conditional.inner 0 1 0 -1))
|
||||
|
||||
(while_statement
|
||||
condition: (_) @conditional.inner
|
||||
(#offset! @conditional.inner 0 1 0 -1))
|
||||
|
||||
(do_statement
|
||||
condition: (_) @conditional.inner
|
||||
(#offset! @conditional.inner 0 1 0 -1))
|
||||
|
||||
(for_statement
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
; loops
|
||||
(while_statement) @loop.outer
|
||||
|
||||
(while_statement
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
(for_statement) @loop.outer
|
||||
|
||||
(for_statement
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
(do_statement) @loop.outer
|
||||
|
||||
(do_statement
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
(compound_statement) @block.outer
|
||||
|
||||
(comment) @comment.outer
|
||||
|
||||
(call_expression) @call.outer
|
||||
|
||||
(call_expression
|
||||
arguments: (argument_list
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
(return_statement
|
||||
(_)? @return.inner) @return.outer
|
||||
|
||||
; Statements
|
||||
;(expression_statement ;; this is what we actually want to capture in most cases (";" is missing) probably
|
||||
;(_) @statement.inner) ;; the other statement like node type is declaration but declaration has a ";"
|
||||
(compound_statement
|
||||
(_) @statement.outer)
|
||||
|
||||
(field_declaration_list
|
||||
(_) @statement.outer)
|
||||
|
||||
(preproc_if
|
||||
(_) @statement.outer)
|
||||
|
||||
(preproc_elif
|
||||
(_) @statement.outer)
|
||||
|
||||
(preproc_else
|
||||
(_) @statement.outer)
|
||||
|
||||
(parameter_list
|
||||
"," @parameter.outer
|
||||
.
|
||||
(parameter_declaration) @parameter.inner @parameter.outer)
|
||||
|
||||
(parameter_list
|
||||
.
|
||||
(parameter_declaration) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
(argument_list
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(argument_list
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
(number_literal) @number.inner
|
||||
|
||||
(declaration
|
||||
declarator: (init_declarator
|
||||
declarator: (_) @assignment.lhs
|
||||
value: (_) @assignment.rhs) @assignment.inner) @assignment.outer
|
||||
|
||||
(declaration
|
||||
type: (primitive_type)
|
||||
declarator: (_) @assignment.inner)
|
||||
|
||||
(expression_statement
|
||||
(assignment_expression
|
||||
left: (_) @assignment.lhs
|
||||
right: (_) @assignment.rhs) @assignment.inner) @assignment.outer
|
||||
@@ -1,24 +0,0 @@
|
||||
[
|
||||
(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
|
||||
@@ -1,392 +0,0 @@
|
||||
; 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)
|
||||
@@ -1,203 +0,0 @@
|
||||
(((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))
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @_name
|
||||
(#eq? @_name "gql")
|
||||
arguments: (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`<css>`, keyframes`<css>`
|
||||
(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`<css>`
|
||||
(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)`<css>`
|
||||
(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" })`<css>`
|
||||
(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" })`<css>`
|
||||
(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 = `<html>`
|
||||
(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 = '<html>'
|
||||
(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: `<html>`
|
||||
; })
|
||||
(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: [`<css>`]
|
||||
; })
|
||||
(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: `<css>`
|
||||
; })
|
||||
(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")))))))
|
||||
@@ -1,42 +0,0 @@
|
||||
; 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)
|
||||
|
||||
(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
|
||||
@@ -1,372 +0,0 @@
|
||||
(function_declaration
|
||||
body: (statement_block)) @function.outer
|
||||
|
||||
(generator_function_declaration
|
||||
body: (statement_block)) @function.outer
|
||||
|
||||
(function_expression
|
||||
body: (statement_block)) @function.outer
|
||||
|
||||
(function_declaration
|
||||
body: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
(generator_function_declaration
|
||||
body: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
(function_expression
|
||||
body: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
(export_statement
|
||||
(function_declaration)) @function.outer
|
||||
|
||||
(arrow_function
|
||||
body: (_) @function.inner) @function.outer
|
||||
|
||||
(arrow_function
|
||||
body: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
(method_definition
|
||||
body: (statement_block)) @function.outer
|
||||
|
||||
(method_definition
|
||||
body: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
(class_declaration
|
||||
body: (class_body)) @class.outer
|
||||
|
||||
(class_declaration
|
||||
body: (class_body
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(export_statement
|
||||
(class_declaration)) @class.outer
|
||||
|
||||
(for_in_statement
|
||||
body: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
(for_statement
|
||||
body: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
(while_statement
|
||||
body: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
(do_statement
|
||||
body: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
(if_statement
|
||||
consequence: (statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @conditional.inner
|
||||
"}")) @conditional.outer
|
||||
|
||||
(if_statement
|
||||
alternative: (else_clause
|
||||
(statement_block
|
||||
.
|
||||
"{"
|
||||
_+ @conditional.inner
|
||||
"}"))) @conditional.outer
|
||||
|
||||
(if_statement) @conditional.outer
|
||||
|
||||
(switch_statement
|
||||
body: (_)? @conditional.inner) @conditional.outer
|
||||
|
||||
(call_expression) @call.outer
|
||||
|
||||
(call_expression
|
||||
arguments: (arguments
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
(new_expression
|
||||
constructor: (identifier) @call.outer
|
||||
arguments: (arguments
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")") @call.outer)
|
||||
|
||||
; blocks
|
||||
(statement_block
|
||||
(_)* @block.inner) @block.outer
|
||||
|
||||
; parameters
|
||||
; function ({ x }) ...
|
||||
; function ([ x ]) ...
|
||||
; function (v = default_value)
|
||||
(formal_parameters
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(formal_parameters
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element with trailing comma
|
||||
(formal_parameters
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
; If the array/object pattern is the first parameter, treat its elements as the argument list
|
||||
(formal_parameters
|
||||
.
|
||||
(_
|
||||
[
|
||||
(object_pattern
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
(array_pattern
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
]))
|
||||
|
||||
(formal_parameters
|
||||
.
|
||||
(_
|
||||
[
|
||||
(object_pattern
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
(array_pattern
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
]))
|
||||
|
||||
; last element with trailing comma
|
||||
(formal_parameters
|
||||
.
|
||||
(_
|
||||
[
|
||||
(object_pattern
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
(array_pattern
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
]))
|
||||
|
||||
; arguments
|
||||
(arguments
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(arguments
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element with trailing comma
|
||||
(arguments
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
; comment
|
||||
(comment) @comment.outer
|
||||
|
||||
; regex
|
||||
(regex
|
||||
(regex_pattern) @regex.inner) @regex.outer
|
||||
|
||||
; number
|
||||
(number) @number.inner
|
||||
|
||||
(lexical_declaration
|
||||
(variable_declarator
|
||||
name: (_) @assignment.lhs
|
||||
value: (_) @assignment.inner @assignment.rhs)) @assignment.outer
|
||||
|
||||
(variable_declarator
|
||||
name: (_) @assignment.inner)
|
||||
|
||||
(object
|
||||
(pair
|
||||
key: (_) @assignment.lhs
|
||||
value: (_) @assignment.inner @assignment.rhs) @assignment.outer)
|
||||
|
||||
(return_statement
|
||||
(_) @return.inner) @return.outer
|
||||
|
||||
(return_statement) @statement.outer
|
||||
|
||||
[
|
||||
(if_statement)
|
||||
(expression_statement)
|
||||
(for_statement)
|
||||
(while_statement)
|
||||
(do_statement)
|
||||
(for_in_statement)
|
||||
(export_statement)
|
||||
(lexical_declaration)
|
||||
] @statement.outer
|
||||
|
||||
; 1. default import
|
||||
(import_statement
|
||||
(import_clause
|
||||
(identifier) @parameter.inner @parameter.outer))
|
||||
|
||||
; 2. namespace import e.g. `* as React`
|
||||
(import_statement
|
||||
(import_clause
|
||||
(namespace_import
|
||||
(identifier) @parameter.inner) @parameter.outer))
|
||||
|
||||
; 3. named import e.g. `import { Bar, Baz } from ...`
|
||||
(import_statement
|
||||
(import_clause
|
||||
(named_imports
|
||||
(import_specifier) @parameter.inner)))
|
||||
|
||||
; 3‑A. named import followed by a comma
|
||||
(import_statement
|
||||
(import_clause
|
||||
(named_imports
|
||||
(import_specifier) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer)))
|
||||
|
||||
; 3‑B. comma followed by named import
|
||||
(import_statement
|
||||
(import_clause
|
||||
(named_imports
|
||||
"," @parameter.outer
|
||||
.
|
||||
(import_specifier) @parameter.outer)))
|
||||
|
||||
; 3-C. only one named import without a comma
|
||||
(import_statement
|
||||
(import_clause
|
||||
(named_imports
|
||||
.
|
||||
(import_specifier) @parameter.outer .)))
|
||||
|
||||
; Treat list or object elements as @parameter
|
||||
; 1. parameter.inner
|
||||
(object
|
||||
(_) @parameter.inner)
|
||||
|
||||
(array
|
||||
(_) @parameter.inner)
|
||||
|
||||
(object_pattern
|
||||
(_) @parameter.inner)
|
||||
|
||||
(array_pattern
|
||||
(_) @parameter.inner)
|
||||
|
||||
; 2. parameter.outer: Only one element, no comma
|
||||
(object
|
||||
.
|
||||
(_) @parameter.outer .)
|
||||
|
||||
(array
|
||||
.
|
||||
(_) @parameter.outer .)
|
||||
|
||||
(object_pattern
|
||||
.
|
||||
(_) @parameter.outer .)
|
||||
|
||||
(array_pattern
|
||||
.
|
||||
(_) @parameter.outer .)
|
||||
|
||||
; 3. parameter.outer: Comma before or after
|
||||
[
|
||||
(object
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.outer)
|
||||
(array
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.outer)
|
||||
(object_pattern
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.outer)
|
||||
(array_pattern
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.outer)
|
||||
]
|
||||
|
||||
[
|
||||
(object
|
||||
.
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer)
|
||||
(array
|
||||
.
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer)
|
||||
(object_pattern
|
||||
.
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer)
|
||||
(array_pattern
|
||||
.
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer)
|
||||
]
|
||||
@@ -1,19 +0,0 @@
|
||||
[
|
||||
(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
|
||||
@@ -1,254 +0,0 @@
|
||||
; 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.delimiter
|
||||
|
||||
":" @punctuation.delimiter
|
||||
|
||||
";" @punctuation.delimiter
|
||||
|
||||
"(" @punctuation.bracket
|
||||
|
||||
")" @punctuation.bracket
|
||||
|
||||
"{" @punctuation.bracket
|
||||
|
||||
"}" @punctuation.bracket
|
||||
|
||||
"[" @punctuation.bracket
|
||||
|
||||
"]" @punctuation.bracket
|
||||
|
||||
; Literals
|
||||
(interpreted_string_literal) @string
|
||||
|
||||
(raw_string_literal) @string
|
||||
|
||||
(rune_literal) @string
|
||||
|
||||
(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)
|
||||
]))
|
||||
@@ -1,42 +0,0 @@
|
||||
((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"))
|
||||
@@ -1,88 +0,0 @@
|
||||
((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
|
||||
@@ -1,153 +0,0 @@
|
||||
; inner function textobject
|
||||
(function_declaration
|
||||
body: (block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
; inner function literals
|
||||
(func_literal
|
||||
body: (block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
; method as inner function textobject
|
||||
(method_declaration
|
||||
body: (block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
; outer function textobject
|
||||
(function_declaration) @function.outer
|
||||
|
||||
; outer function literals
|
||||
(func_literal
|
||||
(_)?) @function.outer
|
||||
|
||||
; method as outer function textobject
|
||||
(method_declaration
|
||||
body: (block)?) @function.outer
|
||||
|
||||
; struct and interface declaration as class textobject?
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(struct_type
|
||||
(field_declaration_list
|
||||
(_)?) @class.inner))) @class.outer
|
||||
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(interface_type) @class.inner)) @class.outer
|
||||
|
||||
; struct literals as class textobject
|
||||
(composite_literal
|
||||
(type_identifier)?
|
||||
(struct_type
|
||||
(_))?
|
||||
(literal_value
|
||||
(_)) @class.inner) @class.outer
|
||||
|
||||
; conditionals
|
||||
(if_statement
|
||||
alternative: (_
|
||||
(_) @conditional.inner)?) @conditional.outer
|
||||
|
||||
(if_statement
|
||||
consequence: (block)? @conditional.inner)
|
||||
|
||||
(if_statement
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
; loops
|
||||
(for_statement
|
||||
body: (block)? @loop.inner) @loop.outer
|
||||
|
||||
; blocks
|
||||
(_
|
||||
(block) @block.inner) @block.outer
|
||||
|
||||
; statements
|
||||
(block
|
||||
(_) @statement.outer)
|
||||
|
||||
; comments
|
||||
(comment) @comment.outer
|
||||
|
||||
; calls
|
||||
(call_expression) @call.outer
|
||||
|
||||
(call_expression
|
||||
arguments: (argument_list
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
; parameters
|
||||
(parameter_list
|
||||
"," @parameter.outer
|
||||
.
|
||||
(parameter_declaration) @parameter.inner @parameter.outer)
|
||||
|
||||
(parameter_list
|
||||
.
|
||||
(parameter_declaration) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
(parameter_declaration
|
||||
name: (identifier)
|
||||
type: (_)) @parameter.inner
|
||||
|
||||
(parameter_declaration
|
||||
name: (identifier)
|
||||
type: (_)) @parameter.inner
|
||||
|
||||
(parameter_list
|
||||
"," @parameter.outer
|
||||
.
|
||||
(variadic_parameter_declaration) @parameter.inner @parameter.outer)
|
||||
|
||||
; arguments
|
||||
(argument_list
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(argument_list
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; assignments
|
||||
(short_var_declaration
|
||||
left: (_) @assignment.lhs
|
||||
right: (_) @assignment.rhs @assignment.inner) @assignment.outer
|
||||
|
||||
(assignment_statement
|
||||
left: (_) @assignment.lhs
|
||||
right: (_) @assignment.rhs @assignment.inner) @assignment.outer
|
||||
|
||||
(var_spec
|
||||
name: (_) @assignment.lhs
|
||||
value: (_) @assignment.rhs @assignment.inner) @assignment.outer
|
||||
|
||||
(var_spec
|
||||
name: (_) @assignment.inner
|
||||
type: (_)) @assignment.outer
|
||||
|
||||
(const_spec
|
||||
name: (_) @assignment.lhs
|
||||
value: (_) @assignment.rhs @assignment.inner) @assignment.outer
|
||||
|
||||
(const_spec
|
||||
name: (_) @assignment.inner
|
||||
type: (_)) @assignment.outer
|
||||
@@ -1,55 +0,0 @@
|
||||
; Keywords
|
||||
"let" @keyword
|
||||
"if" @keyword.conditional
|
||||
"then" @keyword.conditional
|
||||
"else" @keyword.conditional
|
||||
"import" @keyword.import
|
||||
|
||||
; Literals
|
||||
(string) @string
|
||||
(string_content) @string
|
||||
(escape_sequence) @string.escape
|
||||
(number) @number
|
||||
(boolean) @boolean
|
||||
|
||||
; Identifiers
|
||||
(identifier) @variable
|
||||
|
||||
; Types
|
||||
(type_annotation) @type
|
||||
|
||||
; Fields
|
||||
(record_field
|
||||
key: (identifier) @property)
|
||||
|
||||
(field_access
|
||||
(identifier) @property)
|
||||
|
||||
; Functions
|
||||
(call_expression
|
||||
function: (identifier) @function.call)
|
||||
|
||||
; Operators
|
||||
"=" @operator
|
||||
":" @punctuation.delimiter
|
||||
"?" @operator
|
||||
"..." @operator
|
||||
"." @punctuation.delimiter
|
||||
|
||||
; Punctuation
|
||||
"{" @punctuation.bracket
|
||||
"}" @punctuation.bracket
|
||||
"[" @punctuation.bracket
|
||||
"]" @punctuation.bracket
|
||||
"(" @punctuation.bracket
|
||||
")" @punctuation.bracket
|
||||
";" @punctuation.delimiter
|
||||
"," @punctuation.delimiter
|
||||
|
||||
; Interpolation
|
||||
(interpolation
|
||||
"${" @punctuation.special
|
||||
"}" @punctuation.special)
|
||||
|
||||
; Comments
|
||||
(comment) @comment
|
||||
@@ -1 +0,0 @@
|
||||
; inherits: ecma,jsx
|
||||
@@ -1,56 +0,0 @@
|
||||
; inherits: ecma,jsx
|
||||
|
||||
; Parameters
|
||||
(formal_parameters
|
||||
(identifier) @variable.parameter)
|
||||
|
||||
(formal_parameters
|
||||
(rest_pattern
|
||||
(identifier) @variable.parameter))
|
||||
|
||||
; ({ a }) => null
|
||||
(formal_parameters
|
||||
(object_pattern
|
||||
(shorthand_property_identifier_pattern) @variable.parameter))
|
||||
|
||||
; ({ a = b }) => null
|
||||
(formal_parameters
|
||||
(object_pattern
|
||||
(object_assignment_pattern
|
||||
(shorthand_property_identifier_pattern) @variable.parameter)))
|
||||
|
||||
; ({ a: b }) => null
|
||||
(formal_parameters
|
||||
(object_pattern
|
||||
(pair_pattern
|
||||
value: (identifier) @variable.parameter)))
|
||||
|
||||
; ([ a ]) => null
|
||||
(formal_parameters
|
||||
(array_pattern
|
||||
(identifier) @variable.parameter))
|
||||
|
||||
; ({ a } = { a }) => null
|
||||
(formal_parameters
|
||||
(assignment_pattern
|
||||
(object_pattern
|
||||
(shorthand_property_identifier_pattern) @variable.parameter)))
|
||||
|
||||
; ({ a = b } = { a }) => null
|
||||
(formal_parameters
|
||||
(assignment_pattern
|
||||
(object_pattern
|
||||
(object_assignment_pattern
|
||||
(shorthand_property_identifier_pattern) @variable.parameter))))
|
||||
|
||||
; a => null
|
||||
(arrow_function
|
||||
parameter: (identifier) @variable.parameter)
|
||||
|
||||
; optional parameters
|
||||
(formal_parameters
|
||||
(assignment_pattern
|
||||
left: (identifier) @variable.parameter))
|
||||
|
||||
; punctuation
|
||||
(optional_chain) @punctuation.delimiter
|
||||
@@ -1 +0,0 @@
|
||||
; inherits: ecma,jsx
|
||||
@@ -1,69 +0,0 @@
|
||||
; inherits: ecma,jsx
|
||||
|
||||
; Both properties are matched here.
|
||||
;
|
||||
; class Foo {
|
||||
; this.#bar = "baz";
|
||||
; this.quuz = "qux";
|
||||
; }
|
||||
(field_definition
|
||||
property: [
|
||||
(property_identifier)
|
||||
(private_property_identifier)
|
||||
] @local.definition.var)
|
||||
|
||||
; this.foo = "bar"
|
||||
(assignment_expression
|
||||
left: (member_expression
|
||||
object: (this)
|
||||
property: (property_identifier) @local.definition.var))
|
||||
|
||||
(formal_parameters
|
||||
(identifier) @local.definition.parameter)
|
||||
|
||||
; function(arg = []) {
|
||||
(formal_parameters
|
||||
(assignment_pattern
|
||||
left: (identifier) @local.definition.parameter))
|
||||
|
||||
; x => x
|
||||
(arrow_function
|
||||
parameter: (identifier) @local.definition.parameter)
|
||||
|
||||
; ({ a }) => null
|
||||
(formal_parameters
|
||||
(object_pattern
|
||||
(shorthand_property_identifier_pattern) @local.definition.parameter))
|
||||
|
||||
; ({ a: b }) => null
|
||||
(formal_parameters
|
||||
(object_pattern
|
||||
(pair_pattern
|
||||
value: (identifier) @local.definition.parameter)))
|
||||
|
||||
; ([ a ]) => null
|
||||
(formal_parameters
|
||||
(array_pattern
|
||||
(identifier) @local.definition.parameter))
|
||||
|
||||
(formal_parameters
|
||||
(rest_pattern
|
||||
(identifier) @local.definition.parameter))
|
||||
|
||||
; Both methods are matched here.
|
||||
;
|
||||
; class Foo {
|
||||
; #bar(x) { x }
|
||||
; baz(y) { y }
|
||||
; }
|
||||
(method_definition
|
||||
[
|
||||
(property_identifier)
|
||||
(private_property_identifier)
|
||||
] @local.definition.function
|
||||
(#set! definition.var.scope parent))
|
||||
|
||||
; this.foo()
|
||||
(member_expression
|
||||
object: (this)
|
||||
property: (property_identifier) @local.reference)
|
||||
@@ -1 +0,0 @@
|
||||
; inherits: ecma,jsx
|
||||
@@ -1 +0,0 @@
|
||||
(jsx_element) @fold
|
||||
@@ -1,157 +0,0 @@
|
||||
(jsx_element
|
||||
open_tag: (jsx_opening_element
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @tag.delimiter))
|
||||
|
||||
(jsx_element
|
||||
close_tag: (jsx_closing_element
|
||||
[
|
||||
"</"
|
||||
">"
|
||||
] @tag.delimiter))
|
||||
|
||||
(jsx_self_closing_element
|
||||
[
|
||||
"<"
|
||||
"/>"
|
||||
] @tag.delimiter)
|
||||
|
||||
(jsx_attribute
|
||||
(property_identifier) @tag.attribute)
|
||||
|
||||
(jsx_opening_element
|
||||
name: (identifier) @tag.builtin)
|
||||
|
||||
(jsx_closing_element
|
||||
name: (identifier) @tag.builtin)
|
||||
|
||||
(jsx_self_closing_element
|
||||
name: (identifier) @tag.builtin)
|
||||
|
||||
(jsx_opening_element
|
||||
((identifier) @tag
|
||||
(#lua-match? @tag "^[A-Z]")))
|
||||
|
||||
; Handle the dot operator effectively - <My.Component>
|
||||
(jsx_opening_element
|
||||
(member_expression
|
||||
(identifier) @tag.builtin
|
||||
(property_identifier) @tag))
|
||||
|
||||
(jsx_closing_element
|
||||
((identifier) @tag
|
||||
(#lua-match? @tag "^[A-Z]")))
|
||||
|
||||
; Handle the dot operator effectively - </My.Component>
|
||||
(jsx_closing_element
|
||||
(member_expression
|
||||
(identifier) @tag.builtin
|
||||
(property_identifier) @tag))
|
||||
|
||||
(jsx_self_closing_element
|
||||
((identifier) @tag
|
||||
(#lua-match? @tag "^[A-Z]")))
|
||||
|
||||
; Handle the dot operator effectively - <My.Component />
|
||||
(jsx_self_closing_element
|
||||
(member_expression
|
||||
(identifier) @tag.builtin
|
||||
(property_identifier) @tag))
|
||||
|
||||
(html_character_reference) @tag
|
||||
|
||||
(jsx_text) @none @spell
|
||||
|
||||
(html_character_reference) @character.special
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.heading)
|
||||
(#eq? @_tag "title"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.heading.1)
|
||||
(#eq? @_tag "h1"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.heading.2)
|
||||
(#eq? @_tag "h2"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.heading.3)
|
||||
(#eq? @_tag "h3"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.heading.4)
|
||||
(#eq? @_tag "h4"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.heading.5)
|
||||
(#eq? @_tag "h5"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.heading.6)
|
||||
(#eq? @_tag "h6"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.strong)
|
||||
(#any-of? @_tag "strong" "b"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.italic)
|
||||
(#any-of? @_tag "em" "i"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.strikethrough)
|
||||
(#any-of? @_tag "s" "del"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.underline)
|
||||
(#eq? @_tag "u"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.raw)
|
||||
(#any-of? @_tag "code" "kbd"))
|
||||
|
||||
((jsx_element
|
||||
(jsx_opening_element
|
||||
name: (identifier) @_tag)
|
||||
(jsx_text) @markup.link.label)
|
||||
(#eq? @_tag "a"))
|
||||
|
||||
((jsx_attribute
|
||||
(property_identifier) @_attr
|
||||
(string
|
||||
(string_fragment) @string.special.url))
|
||||
(#any-of? @_attr "href" "src"))
|
||||
|
||||
((jsx_element) @_jsx_element
|
||||
(#set! @_jsx_element bo.commentstring "{/* %s */}"))
|
||||
|
||||
((jsx_attribute) @_jsx_attribute
|
||||
(#set! @_jsx_attribute bo.commentstring "// %s"))
|
||||
@@ -1,11 +0,0 @@
|
||||
; Styled Jsx <style jsx>
|
||||
(jsx_element
|
||||
(jsx_opening_element
|
||||
(identifier) @_name
|
||||
(#eq? @_name "style")
|
||||
(jsx_attribute) @_attr
|
||||
(#eq? @_attr "jsx"))
|
||||
(jsx_expression
|
||||
((template_string) @injection.content
|
||||
(#set! injection.language "css"))
|
||||
(#offset! @injection.content 0 1 0 -1)))
|
||||
@@ -1,8 +0,0 @@
|
||||
; inherits: ecma
|
||||
|
||||
(jsx_attribute) @attribute.outer
|
||||
|
||||
(jsx_attribute
|
||||
(property_identifier)
|
||||
(_
|
||||
(_) @attribute.inner))
|
||||
@@ -1,12 +0,0 @@
|
||||
[
|
||||
(do_statement)
|
||||
(while_statement)
|
||||
(repeat_statement)
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(function_declaration)
|
||||
(function_definition)
|
||||
(parameters)
|
||||
(arguments)
|
||||
(table_constructor)
|
||||
] @fold
|
||||
@@ -1,265 +0,0 @@
|
||||
; Keywords
|
||||
"return" @keyword.return
|
||||
|
||||
[
|
||||
"goto"
|
||||
"in"
|
||||
"local"
|
||||
] @keyword
|
||||
|
||||
(break_statement) @keyword
|
||||
|
||||
(do_statement
|
||||
[
|
||||
"do"
|
||||
"end"
|
||||
] @keyword)
|
||||
|
||||
(while_statement
|
||||
[
|
||||
"while"
|
||||
"do"
|
||||
"end"
|
||||
] @keyword.repeat)
|
||||
|
||||
(repeat_statement
|
||||
[
|
||||
"repeat"
|
||||
"until"
|
||||
] @keyword.repeat)
|
||||
|
||||
(if_statement
|
||||
[
|
||||
"if"
|
||||
"elseif"
|
||||
"else"
|
||||
"then"
|
||||
"end"
|
||||
] @keyword.conditional)
|
||||
|
||||
(elseif_statement
|
||||
[
|
||||
"elseif"
|
||||
"then"
|
||||
"end"
|
||||
] @keyword.conditional)
|
||||
|
||||
(else_statement
|
||||
[
|
||||
"else"
|
||||
"end"
|
||||
] @keyword.conditional)
|
||||
|
||||
(for_statement
|
||||
[
|
||||
"for"
|
||||
"do"
|
||||
"end"
|
||||
] @keyword.repeat)
|
||||
|
||||
(function_declaration
|
||||
[
|
||||
"function"
|
||||
"end"
|
||||
] @keyword.function)
|
||||
|
||||
(function_definition
|
||||
[
|
||||
"function"
|
||||
"end"
|
||||
] @keyword.function)
|
||||
|
||||
; Operators
|
||||
[
|
||||
"and"
|
||||
"not"
|
||||
"or"
|
||||
] @keyword.operator
|
||||
|
||||
[
|
||||
"+"
|
||||
"-"
|
||||
"*"
|
||||
"/"
|
||||
"%"
|
||||
"^"
|
||||
"#"
|
||||
"=="
|
||||
"~="
|
||||
"<="
|
||||
">="
|
||||
"<"
|
||||
">"
|
||||
"="
|
||||
"&"
|
||||
"~"
|
||||
"|"
|
||||
"<<"
|
||||
">>"
|
||||
"//"
|
||||
".."
|
||||
] @operator
|
||||
|
||||
; Punctuations
|
||||
[
|
||||
";"
|
||||
":"
|
||||
"::"
|
||||
","
|
||||
"."
|
||||
] @punctuation.delimiter
|
||||
|
||||
; Brackets
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
; Variables
|
||||
(identifier) @variable
|
||||
|
||||
((identifier) @constant.builtin
|
||||
(#eq? @constant.builtin "_VERSION"))
|
||||
|
||||
((identifier) @variable.builtin
|
||||
(#eq? @variable.builtin "self"))
|
||||
|
||||
((identifier) @module.builtin
|
||||
(#any-of? @module.builtin "_G" "debug" "io" "jit" "math" "os" "package" "string" "table" "utf8"))
|
||||
|
||||
((identifier) @keyword.coroutine
|
||||
(#eq? @keyword.coroutine "coroutine"))
|
||||
|
||||
(variable_list
|
||||
(attribute
|
||||
"<" @punctuation.bracket
|
||||
(identifier) @attribute
|
||||
">" @punctuation.bracket))
|
||||
|
||||
; Labels
|
||||
(label_statement
|
||||
(identifier) @label)
|
||||
|
||||
(goto_statement
|
||||
(identifier) @label)
|
||||
|
||||
; Constants
|
||||
((identifier) @constant
|
||||
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||
|
||||
(nil) @constant.builtin
|
||||
|
||||
[
|
||||
(false)
|
||||
(true)
|
||||
] @boolean
|
||||
|
||||
; Tables
|
||||
(field
|
||||
name: (identifier) @property)
|
||||
|
||||
(dot_index_expression
|
||||
field: (identifier) @variable.member)
|
||||
|
||||
(table_constructor
|
||||
[
|
||||
"{"
|
||||
"}"
|
||||
] @constructor)
|
||||
|
||||
; Functions
|
||||
(parameters
|
||||
(identifier) @variable.parameter)
|
||||
|
||||
(vararg_expression) @variable.parameter.builtin
|
||||
|
||||
(function_declaration
|
||||
name: [
|
||||
(identifier) @function
|
||||
(dot_index_expression
|
||||
field: (identifier) @function)
|
||||
])
|
||||
|
||||
(function_declaration
|
||||
name: (method_index_expression
|
||||
method: (identifier) @function.method))
|
||||
|
||||
(assignment_statement
|
||||
(variable_list
|
||||
.
|
||||
name: [
|
||||
(identifier) @function
|
||||
(dot_index_expression
|
||||
field: (identifier) @function)
|
||||
])
|
||||
(expression_list
|
||||
.
|
||||
value: (function_definition)))
|
||||
|
||||
(table_constructor
|
||||
(field
|
||||
name: (identifier) @function
|
||||
value: (function_definition)))
|
||||
|
||||
(function_call
|
||||
name: [
|
||||
(identifier) @function.call
|
||||
(dot_index_expression
|
||||
field: (identifier) @function.call)
|
||||
(method_index_expression
|
||||
method: (identifier) @function.method.call)
|
||||
])
|
||||
|
||||
(function_call
|
||||
(identifier) @function.builtin
|
||||
(#any-of? @function.builtin
|
||||
; built-in functions in Lua 5.1
|
||||
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" "load" "loadfile"
|
||||
"loadstring" "module" "next" "pairs" "pcall" "print" "rawequal" "rawget" "rawlen" "rawset"
|
||||
"require" "select" "setfenv" "setmetatable" "tonumber" "tostring" "type" "unpack" "xpcall"
|
||||
"__add" "__band" "__bnot" "__bor" "__bxor" "__call" "__concat" "__div" "__eq" "__gc" "__idiv"
|
||||
"__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex" "__pairs"
|
||||
"__pow" "__shl" "__shr" "__sub" "__tostring" "__unm"))
|
||||
|
||||
; Others
|
||||
(comment) @comment @spell
|
||||
|
||||
((comment) @comment.documentation
|
||||
(#lua-match? @comment.documentation "^[-][-][-]"))
|
||||
|
||||
((comment) @comment.documentation
|
||||
(#lua-match? @comment.documentation "^[-][-](%s?)@"))
|
||||
|
||||
(hash_bang_line) @keyword.directive
|
||||
|
||||
(number) @number
|
||||
|
||||
(string) @string
|
||||
|
||||
(escape_sequence) @string.escape
|
||||
|
||||
; string.match("123", "%d+")
|
||||
(function_call
|
||||
(dot_index_expression
|
||||
field: (identifier) @_method
|
||||
(#any-of? @_method "find" "match" "gmatch" "gsub"))
|
||||
arguments: (arguments
|
||||
.
|
||||
(_)
|
||||
.
|
||||
(string
|
||||
content: (string_content) @string.regexp)))
|
||||
|
||||
;("123"):match("%d+")
|
||||
(function_call
|
||||
(method_index_expression
|
||||
method: (identifier) @_method
|
||||
(#any-of? @_method "find" "match" "gmatch" "gsub"))
|
||||
arguments: (arguments
|
||||
.
|
||||
(string
|
||||
content: (string_content) @string.regexp)))
|
||||
@@ -1,202 +0,0 @@
|
||||
((function_call
|
||||
name: [
|
||||
(identifier) @_cdef_identifier
|
||||
(_
|
||||
_
|
||||
(identifier) @_cdef_identifier)
|
||||
]
|
||||
arguments: (arguments
|
||||
(string
|
||||
content: _ @injection.content)))
|
||||
(#set! injection.language "c")
|
||||
(#eq? @_cdef_identifier "cdef"))
|
||||
|
||||
((function_call
|
||||
name: (_) @_vimcmd_identifier
|
||||
arguments: (arguments
|
||||
(string
|
||||
content: _ @injection.content)))
|
||||
(#set! injection.language "vim")
|
||||
(#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec2"))
|
||||
|
||||
((function_call
|
||||
name: (_) @_vimcmd_identifier
|
||||
arguments: (arguments
|
||||
(string
|
||||
content: _ @injection.content) .))
|
||||
(#set! injection.language "query")
|
||||
(#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse"))
|
||||
|
||||
((function_call
|
||||
name: (_) @_vimcmd_identifier
|
||||
arguments: (arguments
|
||||
.
|
||||
(_)
|
||||
.
|
||||
(string
|
||||
content: _ @_method)
|
||||
.
|
||||
(string
|
||||
content: _ @injection.content)))
|
||||
(#any-of? @_vimcmd_identifier "vim.rpcrequest" "vim.rpcnotify")
|
||||
(#eq? @_method "nvim_exec_lua")
|
||||
(#set! injection.language "lua"))
|
||||
|
||||
; exec_lua [[ ... ]] in functionaltests
|
||||
((function_call
|
||||
name: (identifier) @_function
|
||||
arguments: (arguments
|
||||
(string
|
||||
content: (string_content) @injection.content)))
|
||||
(#eq? @_function "exec_lua")
|
||||
(#set! injection.language "lua"))
|
||||
|
||||
; vim.api.nvim_create_autocmd("FileType", { command = "injected here" })
|
||||
(function_call
|
||||
name: (_) @_vimcmd_identifier
|
||||
arguments: (arguments
|
||||
.
|
||||
(_)
|
||||
.
|
||||
(table_constructor
|
||||
(field
|
||||
name: (identifier) @_command
|
||||
value: (string
|
||||
content: (_) @injection.content))) .)
|
||||
; limit so only 2-argument functions gets matched before pred handle
|
||||
(#eq? @_vimcmd_identifier "vim.api.nvim_create_autocmd")
|
||||
(#eq? @_command "command")
|
||||
(#set! injection.language "vim"))
|
||||
|
||||
(function_call
|
||||
name: (_) @_user_cmd
|
||||
arguments: (arguments
|
||||
.
|
||||
(_)
|
||||
.
|
||||
(string
|
||||
content: (_) @injection.content)
|
||||
.
|
||||
(_) .)
|
||||
(#eq? @_user_cmd "vim.api.nvim_create_user_command")
|
||||
(#set! injection.language "vim"))
|
||||
|
||||
(function_call
|
||||
name: (_) @_user_cmd
|
||||
arguments: (arguments
|
||||
.
|
||||
(_)
|
||||
.
|
||||
(_)
|
||||
.
|
||||
(string
|
||||
content: (_) @injection.content)
|
||||
.
|
||||
(_) .)
|
||||
; Limiting predicate handling to only functions with 4 arguments
|
||||
(#eq? @_user_cmd "vim.api.nvim_buf_create_user_command")
|
||||
(#set! injection.language "vim"))
|
||||
|
||||
; rhs highlighting for vim.keymap.set/vim.api.nvim_set_keymap/vim.api.nvim_buf_set_keymap
|
||||
; (function_call
|
||||
; name: (_) @_map
|
||||
; arguments:
|
||||
; (arguments
|
||||
; . (_)
|
||||
; . (_)
|
||||
; .
|
||||
; (string
|
||||
; content: (_) @injection.content))
|
||||
; (#any-of? @_map "vim.api.nvim_set_keymap" "vim.keymap.set")
|
||||
; (#set! injection.language "vim"))
|
||||
;
|
||||
; (function_call
|
||||
; name: (_) @_map
|
||||
; arguments:
|
||||
; (arguments
|
||||
; . (_)
|
||||
; . (_)
|
||||
; . (_)
|
||||
; .
|
||||
; (string
|
||||
; content: (_) @injection.content)
|
||||
; . (_) .)
|
||||
; (#eq? @_map "vim.api.nvim_buf_set_keymap")
|
||||
; (#set! injection.language "vim"))
|
||||
; highlight string as query if starts with `;; query`
|
||||
(string
|
||||
content: _ @injection.content
|
||||
(#lua-match? @injection.content "^%s*;+%s?query")
|
||||
(#set! injection.language "query"))
|
||||
|
||||
(comment
|
||||
content: (_) @injection.content
|
||||
(#lua-match? @injection.content "^[-][%s]*[@|]")
|
||||
(#set! injection.language "luadoc")
|
||||
(#offset! @injection.content 0 1 0 0))
|
||||
|
||||
; string.match("123", "%d+")
|
||||
(function_call
|
||||
(dot_index_expression
|
||||
field: (identifier) @_method
|
||||
(#any-of? @_method "find" "match" "gmatch" "gsub"))
|
||||
arguments: (arguments
|
||||
.
|
||||
(_)
|
||||
.
|
||||
(string
|
||||
content: (string_content) @injection.content
|
||||
(#set! injection.language "luap")
|
||||
(#set! injection.include-children))))
|
||||
|
||||
;("123"):match("%d+")
|
||||
(function_call
|
||||
(method_index_expression
|
||||
method: (identifier) @_method
|
||||
(#any-of? @_method "find" "match" "gmatch" "gsub"))
|
||||
arguments: (arguments
|
||||
.
|
||||
(string
|
||||
content: (string_content) @injection.content
|
||||
(#set! injection.language "luap")
|
||||
(#set! injection.include-children))))
|
||||
|
||||
; string.format("pi = %.2f", 3.14159)
|
||||
((function_call
|
||||
(dot_index_expression
|
||||
field: (identifier) @_method)
|
||||
arguments: (arguments
|
||||
.
|
||||
(string
|
||||
(string_content) @injection.content)))
|
||||
(#eq? @_method "format")
|
||||
(#set! injection.language "printf"))
|
||||
|
||||
; ("pi = %.2f"):format(3.14159)
|
||||
((function_call
|
||||
(method_index_expression
|
||||
table: (_
|
||||
(string
|
||||
(string_content) @injection.content))
|
||||
method: (identifier) @_method))
|
||||
(#eq? @_method "format")
|
||||
(#set! injection.language "printf"))
|
||||
|
||||
(comment
|
||||
content: (_) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
||||
; vim.filetype.add({ pattern = { ["some lua pattern here"] = "filetype" } })
|
||||
((function_call
|
||||
name: (_) @_filetypeadd_identifier
|
||||
arguments: (arguments
|
||||
(table_constructor
|
||||
(field
|
||||
name: (_) @_pattern_key
|
||||
value: (table_constructor
|
||||
(field
|
||||
name: (string
|
||||
content: _ @injection.content)))))))
|
||||
(#set! injection.language "luap")
|
||||
(#eq? @_filetypeadd_identifier "vim.filetype.add")
|
||||
(#eq? @_pattern_key "pattern"))
|
||||
@@ -1,54 +0,0 @@
|
||||
; Scopes
|
||||
[
|
||||
(chunk)
|
||||
(do_statement)
|
||||
(while_statement)
|
||||
(repeat_statement)
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(function_declaration)
|
||||
(function_definition)
|
||||
] @local.scope
|
||||
|
||||
; Definitions
|
||||
(assignment_statement
|
||||
(variable_list
|
||||
(identifier) @local.definition.var))
|
||||
|
||||
(assignment_statement
|
||||
(variable_list
|
||||
(dot_index_expression
|
||||
.
|
||||
(_) @local.definition.associated
|
||||
(identifier) @local.definition.var)))
|
||||
|
||||
((function_declaration
|
||||
name: (identifier) @local.definition.function)
|
||||
(#set! definition.function.scope "parent"))
|
||||
|
||||
((function_declaration
|
||||
name: (dot_index_expression
|
||||
.
|
||||
(_) @local.definition.associated
|
||||
(identifier) @local.definition.function))
|
||||
(#set! definition.method.scope "parent"))
|
||||
|
||||
((function_declaration
|
||||
name: (method_index_expression
|
||||
.
|
||||
(_) @local.definition.associated
|
||||
(identifier) @local.definition.method))
|
||||
(#set! definition.method.scope "parent"))
|
||||
|
||||
(for_generic_clause
|
||||
(variable_list
|
||||
(identifier) @local.definition.var))
|
||||
|
||||
(for_numeric_clause
|
||||
name: (identifier) @local.definition.var)
|
||||
|
||||
(parameters
|
||||
(identifier) @local.definition.parameter)
|
||||
|
||||
; References
|
||||
(identifier) @local.reference
|
||||
@@ -1,109 +0,0 @@
|
||||
; block
|
||||
(_
|
||||
(block) @block.inner) @block.outer
|
||||
|
||||
; call
|
||||
(function_call) @call.outer
|
||||
|
||||
(function_call
|
||||
(arguments) @call.inner
|
||||
(#match? @call.inner "^[^\\(]"))
|
||||
|
||||
(function_call
|
||||
arguments: (arguments
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
; class
|
||||
; comment
|
||||
(comment
|
||||
(comment_content) @comment.inner) @comment.outer
|
||||
|
||||
; conditional
|
||||
(if_statement
|
||||
alternative: (_
|
||||
(_) @conditional.inner)?) @conditional.outer
|
||||
|
||||
(if_statement
|
||||
consequence: (block)? @conditional.inner)
|
||||
|
||||
(if_statement
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
; frame
|
||||
; function
|
||||
[
|
||||
(function_declaration)
|
||||
(function_definition)
|
||||
] @function.outer
|
||||
|
||||
(function_declaration
|
||||
body: (_) @function.inner)
|
||||
|
||||
(function_definition
|
||||
body: (_) @function.inner)
|
||||
|
||||
; return
|
||||
(return_statement
|
||||
(_)? @return.inner) @return.outer
|
||||
|
||||
; loop
|
||||
[
|
||||
(while_statement)
|
||||
(for_statement)
|
||||
(repeat_statement)
|
||||
] @loop.outer
|
||||
|
||||
(while_statement
|
||||
body: (_) @loop.inner)
|
||||
|
||||
(for_statement
|
||||
body: (_) @loop.inner)
|
||||
|
||||
(repeat_statement
|
||||
body: (_) @loop.inner)
|
||||
|
||||
; parameter
|
||||
(arguments
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
(parameters
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
(table_constructor
|
||||
(field) @parameter.inner @parameter.outer
|
||||
","? @parameter.outer)
|
||||
|
||||
(arguments
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(parameters
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
; number
|
||||
(number) @number.inner
|
||||
|
||||
(assignment_statement
|
||||
(variable_list) @assignment.lhs
|
||||
(expression_list) @assignment.inner @assignment.rhs) @assignment.outer
|
||||
|
||||
(assignment_statement
|
||||
(variable_list) @assignment.inner)
|
||||
|
||||
; scopename
|
||||
; statement
|
||||
(statement) @statement.outer
|
||||
|
||||
(return_statement) @statement.outer
|
||||
@@ -1,11 +0,0 @@
|
||||
; Nix doesn't really have blocks, so just guess what people might want folds for
|
||||
[
|
||||
(if_expression)
|
||||
(with_expression)
|
||||
(let_expression)
|
||||
(function_expression)
|
||||
(attrset_expression)
|
||||
(rec_attrset_expression)
|
||||
(list_expression)
|
||||
(indented_string_expression)
|
||||
] @fold
|
||||
@@ -1,210 +0,0 @@
|
||||
; basic keywords
|
||||
[
|
||||
"assert"
|
||||
"in"
|
||||
"inherit"
|
||||
"let"
|
||||
"rec"
|
||||
"with"
|
||||
] @keyword
|
||||
|
||||
; if/then/else
|
||||
[
|
||||
"if"
|
||||
"then"
|
||||
"else"
|
||||
] @keyword.conditional
|
||||
|
||||
; field access default (`a.b or c`)
|
||||
"or" @keyword.operator
|
||||
|
||||
; comments
|
||||
(comment) @comment @spell
|
||||
|
||||
; strings
|
||||
(string_fragment) @string
|
||||
|
||||
(string_expression
|
||||
"\"" @string)
|
||||
|
||||
(indented_string_expression
|
||||
"''" @string)
|
||||
|
||||
; paths and URLs
|
||||
[
|
||||
(path_expression)
|
||||
(hpath_expression)
|
||||
(spath_expression)
|
||||
] @string.special.path
|
||||
|
||||
(uri_expression) @string.special.url
|
||||
|
||||
; escape sequences
|
||||
(escape_sequence) @string.escape
|
||||
|
||||
; delimiters
|
||||
[
|
||||
"."
|
||||
";"
|
||||
":"
|
||||
","
|
||||
] @punctuation.delimiter
|
||||
|
||||
; brackets
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
; `?` in `{ x ? y }:`, used to set defaults for named function arguments
|
||||
(formal
|
||||
name: (identifier) @variable.parameter
|
||||
"?"? @operator)
|
||||
|
||||
; `...` in `{ ... }`, used to ignore unknown named function arguments (see above)
|
||||
(ellipses) @variable.parameter.builtin
|
||||
|
||||
; universal is the parameter of the function expression
|
||||
; `:` in `x: y`, used to separate function argument from body (see above)
|
||||
(function_expression
|
||||
universal: (identifier) @variable.parameter
|
||||
":" @punctuation.special)
|
||||
|
||||
; function calls
|
||||
(apply_expression
|
||||
function: (variable_expression
|
||||
name: (identifier) @function.call))
|
||||
|
||||
; basic identifiers
|
||||
(variable_expression) @variable
|
||||
|
||||
(variable_expression
|
||||
name: (identifier) @keyword.import
|
||||
(#eq? @keyword.import "import"))
|
||||
|
||||
(variable_expression
|
||||
name: (identifier) @boolean
|
||||
(#any-of? @boolean "true" "false"))
|
||||
|
||||
; string interpolation (this was very annoying to get working properly)
|
||||
(interpolation
|
||||
"${" @punctuation.special
|
||||
(_)
|
||||
"}" @punctuation.special) @none
|
||||
|
||||
(select_expression
|
||||
expression: (_) @_expr
|
||||
attrpath: (attrpath
|
||||
attr: (identifier) @variable.member)
|
||||
(#not-eq? @_expr "builtins"))
|
||||
|
||||
(attrset_expression
|
||||
(binding_set
|
||||
(binding
|
||||
.
|
||||
(attrpath
|
||||
(identifier) @variable.member))))
|
||||
|
||||
(rec_attrset_expression
|
||||
(binding_set
|
||||
(binding
|
||||
.
|
||||
(attrpath
|
||||
(identifier) @variable.member))))
|
||||
|
||||
function: (select_expression
|
||||
attrpath: (attrpath
|
||||
attr: (identifier) @function.call .))
|
||||
|
||||
; builtin functions (with builtins prefix)
|
||||
(select_expression
|
||||
expression: (variable_expression
|
||||
name: (identifier) @_id)
|
||||
attrpath: (attrpath
|
||||
attr: (identifier) @function.builtin)
|
||||
(#eq? @_id "builtins"))
|
||||
|
||||
; builtin functions (without builtins prefix)
|
||||
(variable_expression
|
||||
name: (identifier) @function.builtin
|
||||
(#any-of? @function.builtin
|
||||
; nix eval --impure --expr 'with builtins; filter (x: !(elem x [ "abort" "import" "throw" ]) && isFunction builtins.${x}) (attrNames builtins)'
|
||||
"add" "addErrorContext" "all" "any" "appendContext" "attrNames" "attrValues" "baseNameOf"
|
||||
"bitAnd" "bitOr" "bitXor" "break" "catAttrs" "ceil" "compareVersions" "concatLists" "concatMap"
|
||||
"concatStringsSep" "deepSeq" "derivation" "derivationStrict" "dirOf" "div" "elem" "elemAt"
|
||||
"fetchGit" "fetchMercurial" "fetchTarball" "fetchTree" "fetchurl" "filter" "filterSource"
|
||||
"findFile" "floor" "foldl'" "fromJSON" "fromTOML" "functionArgs" "genList" "genericClosure"
|
||||
"getAttr" "getContext" "getEnv" "getFlake" "groupBy" "hasAttr" "hasContext" "hashFile"
|
||||
"hashString" "head" "intersectAttrs" "isAttrs" "isBool" "isFloat" "isFunction" "isInt" "isList"
|
||||
"isNull" "isPath" "isString" "length" "lessThan" "listToAttrs" "map" "mapAttrs" "match" "mul"
|
||||
"parseDrvName" "partition" "path" "pathExists" "placeholder" "readDir" "readFile" "removeAttrs"
|
||||
"replaceStrings" "scopedImport" "seq" "sort" "split" "splitVersion" "storePath" "stringLength"
|
||||
"sub" "substring" "tail" "toFile" "toJSON" "toPath" "toString" "toXML" "trace" "traceVerbose"
|
||||
"tryEval" "typeOf" "unsafeDiscardOutputDependency" "unsafeDiscardStringContext"
|
||||
"unsafeGetAttrPos" "zipAttrsWith"
|
||||
; primops, `__<tab>` in `nix repl`
|
||||
"__add" "__filter" "__isFunction" "__split" "__addErrorContext" "__filterSource" "__isInt"
|
||||
"__splitVersion" "__all" "__findFile" "__isList" "__storeDir" "__any" "__floor" "__isPath"
|
||||
"__storePath" "__appendContext" "__foldl'" "__isString" "__stringLength" "__attrNames"
|
||||
"__fromJSON" "__langVersion" "__sub" "__attrValues" "__functionArgs" "__length" "__substring"
|
||||
"__bitAnd" "__genList" "__lessThan" "__tail" "__bitOr" "__genericClosure" "__listToAttrs"
|
||||
"__toFile" "__bitXor" "__getAttr" "__mapAttrs" "__toJSON" "__catAttrs" "__getContext" "__match"
|
||||
"__toPath" "__ceil" "__getEnv" "__mul" "__toXML" "__compareVersions" "__getFlake" "__nixPath"
|
||||
"__trace" "__concatLists" "__groupBy" "__nixVersion" "__traceVerbose" "__concatMap" "__hasAttr"
|
||||
"__parseDrvName" "__tryEval" "__concatStringsSep" "__hasContext" "__partition" "__typeOf"
|
||||
"__currentSystem" "__hashFile" "__path" "__unsafeDiscardOutputDependency" "__currentTime"
|
||||
"__hashString" "__pathExists" "__unsafeDiscardStringContext" "__deepSeq" "__head" "__readDir"
|
||||
"__unsafeGetAttrPos" "__div" "__intersectAttrs" "__readFile" "__zipAttrsWith" "__elem"
|
||||
"__isAttrs" "__replaceStrings" "__elemAt" "__isBool" "__seq" "__fetchurl" "__isFloat" "__sort"))
|
||||
|
||||
; constants
|
||||
(variable_expression
|
||||
name: (identifier) @constant.builtin
|
||||
(#any-of? @constant.builtin
|
||||
; nix eval --impure --expr 'with builtins; filter (x: !(isFunction builtins.${x} || isBool builtins.${x})) (attrNames builtins)'
|
||||
"builtins" "currentSystem" "currentTime" "langVersion" "nixPath" "nixVersion" "null" "storeDir"))
|
||||
|
||||
; function definition
|
||||
(binding
|
||||
attrpath: (attrpath
|
||||
attr: (identifier) @function)
|
||||
expression: (function_expression))
|
||||
|
||||
; unary operators
|
||||
(unary_expression
|
||||
operator: _ @operator)
|
||||
|
||||
; binary operators
|
||||
(binary_expression
|
||||
operator: _ @operator)
|
||||
|
||||
[
|
||||
"="
|
||||
"@"
|
||||
"?"
|
||||
] @operator
|
||||
|
||||
; integers, also highlight a unary -
|
||||
[
|
||||
(unary_expression
|
||||
"-"
|
||||
(integer_expression))
|
||||
(integer_expression)
|
||||
] @number
|
||||
|
||||
; floats, also highlight a unary -
|
||||
[
|
||||
(unary_expression
|
||||
"-"
|
||||
(float_expression))
|
||||
(float_expression)
|
||||
] @number.float
|
||||
|
||||
; exceptions
|
||||
(variable_expression
|
||||
name: (identifier) @keyword.exception
|
||||
(#any-of? @keyword.exception "abort" "throw"))
|
||||
@@ -1,190 +0,0 @@
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
||||
((comment) @injection.language
|
||||
. ; this is to make sure only adjacent comments are accounted for the injections
|
||||
[
|
||||
(string_expression
|
||||
(string_fragment) @injection.content)
|
||||
(indented_string_expression
|
||||
(string_fragment) @injection.content)
|
||||
]
|
||||
(#gsub! @injection.language "/%*%s*([%w%p]+)%s*%*/" "%1")
|
||||
(#set! injection.combined))
|
||||
|
||||
; #-style Comments
|
||||
((comment) @injection.language
|
||||
. ; this is to make sure only adjacent comments are accounted for the injections
|
||||
[
|
||||
(string_expression
|
||||
(string_fragment) @injection.content)
|
||||
(indented_string_expression
|
||||
(string_fragment) @injection.content)
|
||||
]
|
||||
(#gsub! @injection.language "#%s*([%w%p]+)%s*" "%1")
|
||||
(#set! injection.combined))
|
||||
|
||||
(apply_expression
|
||||
function: (_) @_func
|
||||
argument: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "regex")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "regex")))
|
||||
]
|
||||
(#match? @_func "(^|\\.)match$")
|
||||
(#set! injection.combined))
|
||||
|
||||
(binding
|
||||
attrpath: (attrpath
|
||||
(identifier) @_path)
|
||||
expression: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "bash")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "bash")))
|
||||
]
|
||||
(#match? @_path "(^\\w+(Phase|Hook|Check)|(pre|post)[A-Z]\\w+|script)$"))
|
||||
|
||||
(apply_expression
|
||||
function: (_) @_func
|
||||
argument: (_
|
||||
(_)*
|
||||
(_
|
||||
(_)*
|
||||
(binding
|
||||
attrpath: (attrpath
|
||||
(identifier) @_path)
|
||||
expression: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "bash")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "bash")))
|
||||
])))
|
||||
(#match? @_func "(^|\\.)writeShellApplication$")
|
||||
(#match? @_path "^text$")
|
||||
(#set! injection.combined))
|
||||
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: (apply_expression
|
||||
function: (_) @_func))
|
||||
argument: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "bash")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "bash")))
|
||||
]
|
||||
(#match? @_func "(^|\\.)runCommand((No)?CC)?(Local)?$")
|
||||
(#set! injection.combined))
|
||||
|
||||
((apply_expression
|
||||
function: (apply_expression
|
||||
function: (_) @_func)
|
||||
argument: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "bash")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "bash")))
|
||||
])
|
||||
(#match? @_func "(^|\\.)write(Bash|Dash|ShellScript)(Bin)?$")
|
||||
(#set! injection.combined))
|
||||
|
||||
((apply_expression
|
||||
function: (apply_expression
|
||||
function: (_) @_func)
|
||||
argument: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "fish")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "fish")))
|
||||
])
|
||||
(#match? @_func "(^|\\.)writeFish(Bin)?$")
|
||||
(#set! injection.combined))
|
||||
|
||||
((apply_expression
|
||||
function: (apply_expression
|
||||
function: (apply_expression
|
||||
function: (_) @_func))
|
||||
argument: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "haskell")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "haskell")))
|
||||
])
|
||||
(#match? @_func "(^|\\.)writeHaskell(Bin)?$")
|
||||
(#set! injection.combined))
|
||||
|
||||
((apply_expression
|
||||
function: (apply_expression
|
||||
function: (apply_expression
|
||||
function: (_) @_func))
|
||||
argument: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "javascript")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "javascript")))
|
||||
])
|
||||
(#match? @_func "(^|\\.)writeJS(Bin)?$")
|
||||
(#set! injection.combined))
|
||||
|
||||
((apply_expression
|
||||
function: (apply_expression
|
||||
function: (apply_expression
|
||||
function: (_) @_func))
|
||||
argument: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "perl")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "perl")))
|
||||
])
|
||||
(#match? @_func "(^|\\.)writePerl(Bin)?$")
|
||||
(#set! injection.combined))
|
||||
|
||||
((apply_expression
|
||||
function: (apply_expression
|
||||
function: (apply_expression
|
||||
function: (_) @_func))
|
||||
argument: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "python")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "python")))
|
||||
])
|
||||
(#match? @_func "(^|\\.)write(PyPy|Python)[23](Bin)?$")
|
||||
(#set! injection.combined))
|
||||
|
||||
((apply_expression
|
||||
function: (apply_expression
|
||||
function: (apply_expression
|
||||
function: (_) @_func))
|
||||
argument: [
|
||||
(string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "rust")))
|
||||
(indented_string_expression
|
||||
((string_fragment) @injection.content
|
||||
(#set! injection.language "rust")))
|
||||
])
|
||||
(#match? @_func "(^|\\.)writeRust(Bin)?$")
|
||||
(#set! injection.combined))
|
||||
@@ -1,34 +0,0 @@
|
||||
; let bindings
|
||||
(let_expression
|
||||
(binding_set
|
||||
(binding
|
||||
.
|
||||
(attrpath) @local.definition.var))) @local.scope
|
||||
|
||||
; rec attrsets
|
||||
(rec_attrset_expression
|
||||
(binding_set
|
||||
(binding
|
||||
.
|
||||
(attrpath) @local.definition.field))) @local.scope
|
||||
|
||||
; functions and parameters
|
||||
(function_expression
|
||||
.
|
||||
[
|
||||
(identifier) @local.definition.parameter
|
||||
(formals
|
||||
(formal
|
||||
.
|
||||
(identifier) @local.definition.parameter))
|
||||
]) @local.scope
|
||||
|
||||
((formals)
|
||||
"@"
|
||||
(identifier) @local.definition.parameter) ; I couldn't get this to work properly inside the (function)
|
||||
|
||||
(variable_expression
|
||||
(identifier) @local.reference)
|
||||
|
||||
(inherited_attrs
|
||||
attr: (identifier) @local.reference)
|
||||
@@ -1,26 +0,0 @@
|
||||
; named function
|
||||
(binding
|
||||
(function_expression)) @function.outer
|
||||
|
||||
; anonymous function
|
||||
(function_expression
|
||||
(_) ; argument
|
||||
(_) @function.inner) @function.outer
|
||||
|
||||
(function_expression
|
||||
(formals
|
||||
(formal) @parameter.inner))
|
||||
|
||||
(function_expression
|
||||
(_) @parameter.outer
|
||||
(_))
|
||||
|
||||
(comment) @comment.outer
|
||||
|
||||
(if_expression
|
||||
(_) @conditional.inner) @conditional.outer
|
||||
|
||||
[
|
||||
(integer_expression)
|
||||
(float_expression)
|
||||
] @number.inner
|
||||
@@ -1 +0,0 @@
|
||||
; inherits: php_only
|
||||
@@ -1 +0,0 @@
|
||||
; inherits: php_only
|
||||
@@ -1,5 +0,0 @@
|
||||
; inherits: php_only
|
||||
|
||||
((text) @injection.content
|
||||
(#set! injection.language "html")
|
||||
(#set! injection.combined))
|
||||
@@ -1 +0,0 @@
|
||||
; inherits: php_only
|
||||
@@ -1,235 +0,0 @@
|
||||
; functions
|
||||
(function_definition
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
(function_definition) @function.outer
|
||||
|
||||
(anonymous_function
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
(anonymous_function) @function.outer
|
||||
|
||||
; methods
|
||||
(method_declaration
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
(method_declaration) @function.outer
|
||||
|
||||
; traits
|
||||
(trait_declaration
|
||||
body: (declaration_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(trait_declaration) @class.outer
|
||||
|
||||
; interfaces
|
||||
(interface_declaration
|
||||
body: (declaration_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(interface_declaration) @class.outer
|
||||
|
||||
; enums
|
||||
(enum_declaration
|
||||
body: (enum_declaration_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(enum_declaration) @class.outer
|
||||
|
||||
; classes
|
||||
(class_declaration
|
||||
body: (declaration_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(class_declaration) @class.outer
|
||||
|
||||
; loops
|
||||
(for_statement
|
||||
(compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}"))
|
||||
|
||||
(for_statement) @loop.outer
|
||||
|
||||
(foreach_statement
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}"))
|
||||
|
||||
(foreach_statement) @loop.outer
|
||||
|
||||
(while_statement
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}"))
|
||||
|
||||
(while_statement) @loop.outer
|
||||
|
||||
(do_statement
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}"))
|
||||
|
||||
(do_statement) @loop.outer
|
||||
|
||||
; conditionals
|
||||
(switch_statement
|
||||
body: (switch_block
|
||||
.
|
||||
"{"
|
||||
_+ @conditional.inner
|
||||
"}"))
|
||||
|
||||
(switch_statement) @conditional.outer
|
||||
|
||||
(if_statement
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @conditional.inner
|
||||
"}"))
|
||||
|
||||
(if_statement) @conditional.outer
|
||||
|
||||
(else_clause
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @conditional.inner
|
||||
"}"))
|
||||
|
||||
(else_if_clause
|
||||
body: (compound_statement
|
||||
.
|
||||
"{"
|
||||
_+ @conditional.inner
|
||||
"}"))
|
||||
|
||||
; blocks
|
||||
(_
|
||||
(switch_block) @block.inner) @block.outer
|
||||
|
||||
; parameters
|
||||
(arguments
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(arguments
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
(formal_parameters
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(formal_parameters
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; comments
|
||||
(comment) @comment.outer
|
||||
|
||||
; call
|
||||
(function_call_expression) @call.outer
|
||||
|
||||
(member_call_expression) @call.outer
|
||||
|
||||
(nullsafe_member_call_expression) @call.outer
|
||||
|
||||
(scoped_call_expression) @call.outer
|
||||
|
||||
(function_call_expression
|
||||
arguments: (arguments
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
(member_call_expression
|
||||
arguments: (arguments
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
(nullsafe_member_call_expression
|
||||
arguments: (arguments
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
(scoped_call_expression
|
||||
arguments: (arguments
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
; statement
|
||||
[
|
||||
(expression_statement)
|
||||
(declare_statement)
|
||||
(return_statement)
|
||||
(namespace_use_declaration)
|
||||
(namespace_definition)
|
||||
(if_statement)
|
||||
(empty_statement)
|
||||
(switch_statement)
|
||||
(while_statement)
|
||||
(do_statement)
|
||||
(for_statement)
|
||||
(foreach_statement)
|
||||
(goto_statement)
|
||||
(continue_statement)
|
||||
(break_statement)
|
||||
(try_statement)
|
||||
(echo_statement)
|
||||
(unset_statement)
|
||||
(const_declaration)
|
||||
(function_definition)
|
||||
(class_declaration)
|
||||
(interface_declaration)
|
||||
(trait_declaration)
|
||||
(enum_declaration)
|
||||
(global_declaration)
|
||||
(function_static_declaration)
|
||||
] @statement.outer
|
||||
@@ -1,17 +0,0 @@
|
||||
[
|
||||
(if_statement)
|
||||
(switch_statement)
|
||||
(while_statement)
|
||||
(do_statement)
|
||||
(for_statement)
|
||||
(foreach_statement)
|
||||
(try_statement)
|
||||
(function_definition)
|
||||
(class_declaration)
|
||||
(interface_declaration)
|
||||
(trait_declaration)
|
||||
(enum_declaration)
|
||||
(function_static_declaration)
|
||||
(method_declaration)
|
||||
(namespace_use_declaration)+
|
||||
] @fold
|
||||
@@ -1,479 +0,0 @@
|
||||
; Keywords
|
||||
[
|
||||
"and"
|
||||
"as"
|
||||
"instanceof"
|
||||
"or"
|
||||
"xor"
|
||||
] @keyword.operator
|
||||
|
||||
[
|
||||
"fn"
|
||||
"function"
|
||||
] @keyword.function
|
||||
|
||||
[
|
||||
"clone"
|
||||
"declare"
|
||||
"default"
|
||||
"echo"
|
||||
"enddeclare"
|
||||
"extends"
|
||||
"global"
|
||||
"goto"
|
||||
"implements"
|
||||
"insteadof"
|
||||
"print"
|
||||
"new"
|
||||
"unset"
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"enum"
|
||||
"class"
|
||||
"interface"
|
||||
"namespace"
|
||||
"trait"
|
||||
] @keyword.type
|
||||
|
||||
[
|
||||
"abstract"
|
||||
"const"
|
||||
"final"
|
||||
"private"
|
||||
"protected"
|
||||
"public"
|
||||
"readonly"
|
||||
(static_modifier)
|
||||
] @keyword.modifier
|
||||
|
||||
(function_static_declaration
|
||||
"static" @keyword.modifier)
|
||||
|
||||
[
|
||||
"return"
|
||||
"exit"
|
||||
"yield"
|
||||
] @keyword.return
|
||||
|
||||
(yield_expression
|
||||
"from" @keyword.return)
|
||||
|
||||
[
|
||||
"case"
|
||||
"else"
|
||||
"elseif"
|
||||
"endif"
|
||||
"endswitch"
|
||||
"if"
|
||||
"switch"
|
||||
"match"
|
||||
"??"
|
||||
] @keyword.conditional
|
||||
|
||||
[
|
||||
"break"
|
||||
"continue"
|
||||
"do"
|
||||
"endfor"
|
||||
"endforeach"
|
||||
"endwhile"
|
||||
"for"
|
||||
"foreach"
|
||||
"while"
|
||||
] @keyword.repeat
|
||||
|
||||
[
|
||||
"catch"
|
||||
"finally"
|
||||
"throw"
|
||||
"try"
|
||||
] @keyword.exception
|
||||
|
||||
[
|
||||
"include_once"
|
||||
"include"
|
||||
"require_once"
|
||||
"require"
|
||||
"use"
|
||||
] @keyword.import
|
||||
|
||||
[
|
||||
","
|
||||
";"
|
||||
":"
|
||||
"\\"
|
||||
] @punctuation.delimiter
|
||||
|
||||
[
|
||||
(php_tag)
|
||||
"?>"
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
"#["
|
||||
] @punctuation.bracket
|
||||
|
||||
[
|
||||
"="
|
||||
"."
|
||||
"-"
|
||||
"*"
|
||||
"/"
|
||||
"+"
|
||||
"%"
|
||||
"**"
|
||||
"~"
|
||||
"|"
|
||||
"^"
|
||||
"&"
|
||||
"<<"
|
||||
">>"
|
||||
"<<<"
|
||||
"->"
|
||||
"?->"
|
||||
"=>"
|
||||
"<"
|
||||
"<="
|
||||
">="
|
||||
">"
|
||||
"<>"
|
||||
"<=>"
|
||||
"=="
|
||||
"!="
|
||||
"==="
|
||||
"!=="
|
||||
"!"
|
||||
"&&"
|
||||
"||"
|
||||
".="
|
||||
"-="
|
||||
"+="
|
||||
"*="
|
||||
"/="
|
||||
"%="
|
||||
"**="
|
||||
"&="
|
||||
"|="
|
||||
"^="
|
||||
"<<="
|
||||
">>="
|
||||
"??="
|
||||
"--"
|
||||
"++"
|
||||
"@"
|
||||
"::"
|
||||
] @operator
|
||||
|
||||
; Variables
|
||||
(variable_name) @variable
|
||||
|
||||
; Constants
|
||||
((name) @constant
|
||||
(#lua-match? @constant "^_?[A-Z][A-Z%d_]*$"))
|
||||
|
||||
((name) @constant.builtin
|
||||
(#lua-match? @constant.builtin "^__[A-Z][A-Z%d_]+__$"))
|
||||
|
||||
(const_declaration
|
||||
(const_element
|
||||
(name) @constant))
|
||||
|
||||
; Types
|
||||
[
|
||||
(primitive_type)
|
||||
(cast_type)
|
||||
(bottom_type)
|
||||
] @type.builtin
|
||||
|
||||
(named_type
|
||||
[
|
||||
(name) @type
|
||||
(qualified_name
|
||||
(name) @type)
|
||||
(relative_name
|
||||
(name) @type)
|
||||
])
|
||||
|
||||
(named_type
|
||||
(name) @type.builtin
|
||||
(#any-of? @type.builtin "static" "self"))
|
||||
|
||||
(class_declaration
|
||||
name: (name) @type)
|
||||
|
||||
(base_clause
|
||||
[
|
||||
(name) @type
|
||||
(qualified_name
|
||||
(name) @type)
|
||||
(relative_name
|
||||
(name) @type)
|
||||
])
|
||||
|
||||
(enum_declaration
|
||||
name: (name) @type)
|
||||
|
||||
(interface_declaration
|
||||
name: (name) @type)
|
||||
|
||||
(namespace_use_clause
|
||||
[
|
||||
(name) @type
|
||||
(qualified_name
|
||||
(name) @type)
|
||||
alias: (name) @type.definition
|
||||
])
|
||||
|
||||
(namespace_use_clause
|
||||
type: "function"
|
||||
[
|
||||
(name) @function
|
||||
(qualified_name
|
||||
(name) @function)
|
||||
alias: (name) @function
|
||||
])
|
||||
|
||||
(namespace_use_declaration
|
||||
type: "function"
|
||||
body: (namespace_use_group
|
||||
(namespace_use_clause
|
||||
[
|
||||
(name) @function
|
||||
(qualified_name
|
||||
(name) @function)
|
||||
alias: (name) @function
|
||||
])))
|
||||
|
||||
(namespace_use_clause
|
||||
type: "const"
|
||||
[
|
||||
(name) @constant
|
||||
(qualified_name
|
||||
(name) @constant)
|
||||
alias: (name) @constant
|
||||
])
|
||||
|
||||
(namespace_use_declaration
|
||||
type: "const"
|
||||
body: (namespace_use_group
|
||||
(namespace_use_clause
|
||||
[
|
||||
(name) @constant
|
||||
(qualified_name
|
||||
(name) @constant)
|
||||
alias: (name) @constant
|
||||
])))
|
||||
|
||||
(class_interface_clause
|
||||
[
|
||||
(name) @type
|
||||
(qualified_name
|
||||
(name) @type)
|
||||
(relative_name
|
||||
(name) @type)
|
||||
])
|
||||
|
||||
(scoped_call_expression
|
||||
scope: [
|
||||
(name) @type
|
||||
(qualified_name
|
||||
(name) @type)
|
||||
(relative_name
|
||||
(name) @type)
|
||||
])
|
||||
|
||||
(class_constant_access_expression
|
||||
.
|
||||
[
|
||||
(name) @type
|
||||
(qualified_name
|
||||
(name) @type)
|
||||
(relative_name
|
||||
(name) @type)
|
||||
]
|
||||
(name) @constant)
|
||||
|
||||
(scoped_property_access_expression
|
||||
scope: [
|
||||
(name) @type
|
||||
(qualified_name
|
||||
(name) @type)
|
||||
(relative_name
|
||||
(name) @type)
|
||||
])
|
||||
|
||||
(scoped_property_access_expression
|
||||
name: (variable_name) @variable.member)
|
||||
|
||||
(trait_declaration
|
||||
name: (name) @type)
|
||||
|
||||
(use_declaration
|
||||
(name) @type)
|
||||
|
||||
(binary_expression
|
||||
operator: "instanceof"
|
||||
right: [
|
||||
(name) @type
|
||||
(qualified_name
|
||||
(name) @type)
|
||||
(relative_name
|
||||
(name) @type)
|
||||
])
|
||||
|
||||
; Functions, methods, constructors
|
||||
(array_creation_expression
|
||||
"array" @function.builtin)
|
||||
|
||||
(list_literal
|
||||
"list" @function.builtin)
|
||||
|
||||
(exit_statement
|
||||
"exit" @function.builtin
|
||||
"(")
|
||||
|
||||
(method_declaration
|
||||
name: (name) @function.method)
|
||||
|
||||
(function_call_expression
|
||||
function: [
|
||||
(name) @function.call
|
||||
(qualified_name
|
||||
(name) @function.call)
|
||||
(relative_name
|
||||
(name) @function.call)
|
||||
])
|
||||
|
||||
(scoped_call_expression
|
||||
name: (name) @function.call)
|
||||
|
||||
(member_call_expression
|
||||
name: (name) @function.method.call)
|
||||
|
||||
(function_definition
|
||||
name: (name) @function)
|
||||
|
||||
(nullsafe_member_call_expression
|
||||
name: (name) @function.method)
|
||||
|
||||
(use_instead_of_clause
|
||||
(class_constant_access_expression
|
||||
(_)
|
||||
(name) @function.method)
|
||||
(name) @type)
|
||||
|
||||
(use_as_clause
|
||||
(class_constant_access_expression
|
||||
(_)
|
||||
(name) @function.method)*
|
||||
(name) @function.method)
|
||||
|
||||
(method_declaration
|
||||
name: (name) @constructor
|
||||
(#eq? @constructor "__construct"))
|
||||
|
||||
(object_creation_expression
|
||||
[
|
||||
(name) @constructor
|
||||
(qualified_name
|
||||
(name) @constructor)
|
||||
(relative_name
|
||||
(name) @constructor)
|
||||
])
|
||||
|
||||
; Parameters
|
||||
(variadic_parameter
|
||||
"..." @operator
|
||||
name: (variable_name) @variable.parameter)
|
||||
|
||||
(simple_parameter
|
||||
name: (variable_name) @variable.parameter)
|
||||
|
||||
(argument
|
||||
(name) @variable.parameter)
|
||||
|
||||
; Member
|
||||
(property_element
|
||||
(variable_name) @property)
|
||||
|
||||
(member_access_expression
|
||||
name: (variable_name
|
||||
(name)) @variable.member)
|
||||
|
||||
(member_access_expression
|
||||
name: (name) @variable.member)
|
||||
|
||||
(nullsafe_member_access_expression
|
||||
name: (variable_name
|
||||
(name)) @variable.member)
|
||||
|
||||
(nullsafe_member_access_expression
|
||||
name: (name) @variable.member)
|
||||
|
||||
; Variables
|
||||
(relative_scope) @variable.builtin
|
||||
|
||||
((variable_name) @variable.builtin
|
||||
(#eq? @variable.builtin "$this"))
|
||||
|
||||
; Namespace
|
||||
(namespace_definition
|
||||
name: (namespace_name
|
||||
(name) @module))
|
||||
|
||||
(namespace_name
|
||||
(name) @module)
|
||||
|
||||
(relative_name
|
||||
"namespace" @module.builtin)
|
||||
|
||||
; Attributes
|
||||
(attribute_list) @attribute
|
||||
|
||||
; Conditions ( ? : )
|
||||
(conditional_expression
|
||||
"?" @keyword.conditional.ternary
|
||||
":" @keyword.conditional.ternary)
|
||||
|
||||
; Directives
|
||||
(declare_directive
|
||||
[
|
||||
"strict_types"
|
||||
"ticks"
|
||||
"encoding"
|
||||
] @variable.parameter)
|
||||
|
||||
; Basic tokens
|
||||
[
|
||||
(string)
|
||||
(encapsed_string)
|
||||
(heredoc_body)
|
||||
(nowdoc_body)
|
||||
(shell_command_expression) ; backtick operator: `ls -la`
|
||||
] @string
|
||||
|
||||
(escape_sequence) @string.escape
|
||||
|
||||
[
|
||||
(heredoc_start)
|
||||
(heredoc_end)
|
||||
] @label
|
||||
|
||||
(nowdoc
|
||||
"'" @label)
|
||||
|
||||
(boolean) @boolean
|
||||
|
||||
(null) @constant.builtin
|
||||
|
||||
(integer) @number
|
||||
|
||||
(float) @number.float
|
||||
|
||||
(comment) @comment @spell
|
||||
|
||||
(named_label_statement) @label
|
||||
@@ -1,43 +0,0 @@
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "phpdoc"))
|
||||
|
||||
(heredoc
|
||||
(heredoc_body) @injection.content
|
||||
(heredoc_end) @injection.language
|
||||
(#set! injection.include-children)
|
||||
(#downcase! @injection.language))
|
||||
|
||||
(nowdoc
|
||||
(nowdoc_body) @injection.content
|
||||
(heredoc_end) @injection.language
|
||||
(#set! injection.include-children)
|
||||
(#downcase! @injection.language))
|
||||
|
||||
; regex
|
||||
((function_call_expression
|
||||
function: (_) @_preg_func_identifier
|
||||
arguments: (arguments
|
||||
.
|
||||
(argument
|
||||
(_
|
||||
(string_content) @injection.content))))
|
||||
(#set! injection.language "regex")
|
||||
(#lua-match? @_preg_func_identifier "^preg_"))
|
||||
|
||||
; bash
|
||||
((function_call_expression
|
||||
function: (_) @_shell_func_identifier
|
||||
arguments: (arguments
|
||||
.
|
||||
(argument
|
||||
(_
|
||||
(string_content) @injection.content))))
|
||||
(#set! injection.language "bash")
|
||||
(#any-of? @_shell_func_identifier
|
||||
"shell_exec" "escapeshellarg" "escapeshellcmd" "exec" "passthru" "proc_open" "shell_exec"
|
||||
"system"))
|
||||
|
||||
(expression_statement
|
||||
(shell_command_expression
|
||||
(string_content) @injection.content)
|
||||
(#set! injection.language "bash"))
|
||||
@@ -1,84 +0,0 @@
|
||||
; Scopes
|
||||
;-------
|
||||
((class_declaration
|
||||
name: (name) @local.definition.type) @local.scope
|
||||
(#set! definition.type.scope "parent"))
|
||||
|
||||
((method_declaration
|
||||
name: (name) @local.definition.method) @local.scope
|
||||
(#set! definition.method.scope "parent"))
|
||||
|
||||
((function_definition
|
||||
name: (name) @local.definition.function) @local.scope
|
||||
(#set! definition.function.scope "parent"))
|
||||
|
||||
(anonymous_function
|
||||
(anonymous_function_use_clause
|
||||
(variable_name
|
||||
(name) @local.definition.var))) @local.scope
|
||||
|
||||
; Definitions
|
||||
;------------
|
||||
(simple_parameter
|
||||
(variable_name
|
||||
(name) @local.definition.var))
|
||||
|
||||
(foreach_statement
|
||||
(pair
|
||||
(variable_name
|
||||
(name) @local.definition.var)))
|
||||
|
||||
(foreach_statement
|
||||
(variable_name
|
||||
(name) @local.reference
|
||||
(#set! reference.kind "var"))
|
||||
(variable_name
|
||||
(name) @local.definition.var))
|
||||
|
||||
(property_declaration
|
||||
(property_element
|
||||
(variable_name
|
||||
(name) @local.definition.field)))
|
||||
|
||||
(namespace_use_clause
|
||||
(qualified_name
|
||||
(name) @local.definition.type))
|
||||
|
||||
; References
|
||||
;------------
|
||||
(named_type
|
||||
(name) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
(named_type
|
||||
(qualified_name) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
(variable_name
|
||||
(name) @local.reference
|
||||
(#set! reference.kind "var"))
|
||||
|
||||
(member_access_expression
|
||||
name: (name) @local.reference
|
||||
(#set! reference.kind "field"))
|
||||
|
||||
(member_call_expression
|
||||
name: (name) @local.reference
|
||||
(#set! reference.kind "method"))
|
||||
|
||||
(function_call_expression
|
||||
function: (qualified_name
|
||||
(name) @local.reference
|
||||
(#set! reference.kind "function")))
|
||||
|
||||
(object_creation_expression
|
||||
(qualified_name
|
||||
(name) @local.reference
|
||||
(#set! reference.kind "type")))
|
||||
|
||||
(scoped_call_expression
|
||||
scope: (qualified_name
|
||||
(name) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
name: (name) @local.reference
|
||||
(#set! reference.kind "method"))
|
||||
@@ -1 +0,0 @@
|
||||
; inherits php
|
||||
@@ -1,25 +0,0 @@
|
||||
[
|
||||
(mod_item)
|
||||
(foreign_mod_item)
|
||||
(function_item)
|
||||
(struct_item)
|
||||
(trait_item)
|
||||
(enum_item)
|
||||
(impl_item)
|
||||
(type_item)
|
||||
(union_item)
|
||||
(const_item)
|
||||
(let_declaration)
|
||||
(loop_expression)
|
||||
(for_expression)
|
||||
(while_expression)
|
||||
(if_expression)
|
||||
(match_expression)
|
||||
(call_expression)
|
||||
(array_expression)
|
||||
(macro_definition)
|
||||
(macro_invocation)
|
||||
(attribute_item)
|
||||
(block)
|
||||
(use_declaration)+
|
||||
] @fold
|
||||
@@ -1,531 +0,0 @@
|
||||
; Forked from https://github.com/tree-sitter/tree-sitter-rust
|
||||
; Copyright (c) 2017 Maxim Sokolov
|
||||
; Licensed under the MIT license.
|
||||
; Identifier conventions
|
||||
(shebang) @keyword.directive
|
||||
|
||||
(identifier) @variable
|
||||
|
||||
((identifier) @type
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
(const_item
|
||||
name: (identifier) @constant)
|
||||
|
||||
; Assume all-caps names are constants
|
||||
((identifier) @constant
|
||||
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
|
||||
|
||||
; Other identifiers
|
||||
(type_identifier) @type
|
||||
|
||||
(primitive_type) @type.builtin
|
||||
|
||||
(field_identifier) @variable.member
|
||||
|
||||
(shorthand_field_identifier) @variable.member
|
||||
|
||||
(shorthand_field_initializer
|
||||
(identifier) @variable.member)
|
||||
|
||||
(mod_item
|
||||
name: (identifier) @module)
|
||||
|
||||
(self) @variable.builtin
|
||||
|
||||
"_" @character.special
|
||||
|
||||
(label
|
||||
[
|
||||
"'"
|
||||
(identifier)
|
||||
] @label)
|
||||
|
||||
; Function definitions
|
||||
(function_item
|
||||
(identifier) @function)
|
||||
|
||||
(function_signature_item
|
||||
(identifier) @function)
|
||||
|
||||
(parameter
|
||||
[
|
||||
(identifier)
|
||||
"_"
|
||||
] @variable.parameter)
|
||||
|
||||
(parameter
|
||||
(ref_pattern
|
||||
[
|
||||
(mut_pattern
|
||||
(identifier) @variable.parameter)
|
||||
(identifier) @variable.parameter
|
||||
]))
|
||||
|
||||
(closure_parameters
|
||||
(_) @variable.parameter)
|
||||
|
||||
; Function calls
|
||||
(call_expression
|
||||
function: (identifier) @function.call)
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
(identifier) @function.call .))
|
||||
|
||||
(call_expression
|
||||
function: (field_expression
|
||||
field: (field_identifier) @function.call))
|
||||
|
||||
(generic_function
|
||||
function: (identifier) @function.call)
|
||||
|
||||
(generic_function
|
||||
function: (scoped_identifier
|
||||
name: (identifier) @function.call))
|
||||
|
||||
(generic_function
|
||||
function: (field_expression
|
||||
field: (field_identifier) @function.call))
|
||||
|
||||
; Assume other uppercase names are enum constructors
|
||||
((field_identifier) @constant
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
(enum_variant
|
||||
name: (identifier) @constant)
|
||||
|
||||
; Assume that uppercase names in paths are types
|
||||
(scoped_identifier
|
||||
path: (identifier) @module)
|
||||
|
||||
(scoped_identifier
|
||||
(scoped_identifier
|
||||
name: (identifier) @module))
|
||||
|
||||
(scoped_type_identifier
|
||||
path: (identifier) @module)
|
||||
|
||||
(scoped_type_identifier
|
||||
path: (identifier) @type
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
(scoped_type_identifier
|
||||
(scoped_identifier
|
||||
name: (identifier) @module))
|
||||
|
||||
((scoped_identifier
|
||||
path: (identifier) @type)
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
((scoped_identifier
|
||||
name: (identifier) @type)
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
((scoped_identifier
|
||||
name: (identifier) @constant)
|
||||
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
|
||||
|
||||
((scoped_identifier
|
||||
path: (identifier) @type
|
||||
name: (identifier) @constant)
|
||||
(#lua-match? @type "^[A-Z]")
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
((scoped_type_identifier
|
||||
path: (identifier) @type
|
||||
name: (type_identifier) @constant)
|
||||
(#lua-match? @type "^[A-Z]")
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
[
|
||||
(crate)
|
||||
(super)
|
||||
] @module
|
||||
|
||||
(scoped_use_list
|
||||
path: (identifier) @module)
|
||||
|
||||
(scoped_use_list
|
||||
path: (scoped_identifier
|
||||
(identifier) @module))
|
||||
|
||||
(use_list
|
||||
(scoped_identifier
|
||||
(identifier) @module
|
||||
.
|
||||
(_)))
|
||||
|
||||
(use_list
|
||||
(identifier) @type
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
(use_as_clause
|
||||
alias: (identifier) @type
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
; Correct enum constructors
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
"::"
|
||||
name: (identifier) @constant)
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
; Assume uppercase names in a match arm are constants.
|
||||
((match_arm
|
||||
pattern: (match_pattern
|
||||
(identifier) @constant))
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
((match_arm
|
||||
pattern: (match_pattern
|
||||
(scoped_identifier
|
||||
name: (identifier) @constant)))
|
||||
(#lua-match? @constant "^[A-Z]"))
|
||||
|
||||
((identifier) @constant.builtin
|
||||
(#any-of? @constant.builtin "Some" "None" "Ok" "Err"))
|
||||
|
||||
; Macro definitions
|
||||
"$" @function.macro
|
||||
|
||||
(metavariable) @function.macro
|
||||
|
||||
(macro_definition
|
||||
"macro_rules!" @function.macro)
|
||||
|
||||
; Attribute macros
|
||||
(attribute_item
|
||||
(attribute
|
||||
(identifier) @function.macro))
|
||||
|
||||
(inner_attribute_item
|
||||
(attribute
|
||||
(identifier) @function.macro))
|
||||
|
||||
(attribute
|
||||
(scoped_identifier
|
||||
(identifier) @function.macro .))
|
||||
|
||||
; Derive macros (assume all arguments are types)
|
||||
; (attribute
|
||||
; (identifier) @_name
|
||||
; arguments: (attribute (attribute (identifier) @type))
|
||||
; (#eq? @_name "derive"))
|
||||
; Function-like macros
|
||||
(macro_invocation
|
||||
macro: (identifier) @function.macro)
|
||||
|
||||
(macro_invocation
|
||||
macro: (scoped_identifier
|
||||
(identifier) @function.macro .))
|
||||
|
||||
; Literals
|
||||
(boolean_literal) @boolean
|
||||
|
||||
(integer_literal) @number
|
||||
|
||||
(float_literal) @number.float
|
||||
|
||||
[
|
||||
(raw_string_literal)
|
||||
(string_literal)
|
||||
] @string
|
||||
|
||||
(escape_sequence) @string.escape
|
||||
|
||||
(char_literal) @character
|
||||
|
||||
; Keywords
|
||||
[
|
||||
"use"
|
||||
"mod"
|
||||
] @keyword.import
|
||||
|
||||
(use_as_clause
|
||||
"as" @keyword.import)
|
||||
|
||||
[
|
||||
"default"
|
||||
"impl"
|
||||
"let"
|
||||
"move"
|
||||
"unsafe"
|
||||
"where"
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"enum"
|
||||
"struct"
|
||||
"union"
|
||||
"trait"
|
||||
"type"
|
||||
] @keyword.type
|
||||
|
||||
[
|
||||
"async"
|
||||
"await"
|
||||
"gen"
|
||||
] @keyword.coroutine
|
||||
|
||||
"try" @keyword.exception
|
||||
|
||||
[
|
||||
"ref"
|
||||
"pub"
|
||||
"raw"
|
||||
(mutable_specifier)
|
||||
"const"
|
||||
"static"
|
||||
"dyn"
|
||||
"extern"
|
||||
] @keyword.modifier
|
||||
|
||||
(lifetime
|
||||
"'" @keyword.modifier)
|
||||
|
||||
(lifetime
|
||||
(identifier) @attribute)
|
||||
|
||||
(lifetime
|
||||
(identifier) @attribute.builtin
|
||||
(#any-of? @attribute.builtin "static" "_"))
|
||||
|
||||
"fn" @keyword.function
|
||||
|
||||
[
|
||||
"return"
|
||||
"yield"
|
||||
] @keyword.return
|
||||
|
||||
(type_cast_expression
|
||||
"as" @keyword.operator)
|
||||
|
||||
(qualified_type
|
||||
"as" @keyword.operator)
|
||||
|
||||
(use_list
|
||||
(self) @module)
|
||||
|
||||
(scoped_use_list
|
||||
(self) @module)
|
||||
|
||||
(scoped_identifier
|
||||
[
|
||||
(crate)
|
||||
(super)
|
||||
(self)
|
||||
] @module)
|
||||
|
||||
(visibility_modifier
|
||||
[
|
||||
(crate)
|
||||
(super)
|
||||
(self)
|
||||
] @module)
|
||||
|
||||
[
|
||||
"if"
|
||||
"else"
|
||||
"match"
|
||||
] @keyword.conditional
|
||||
|
||||
[
|
||||
"break"
|
||||
"continue"
|
||||
"in"
|
||||
"loop"
|
||||
"while"
|
||||
] @keyword.repeat
|
||||
|
||||
"for" @keyword
|
||||
|
||||
(for_expression
|
||||
"for" @keyword.repeat)
|
||||
|
||||
; Operators
|
||||
[
|
||||
"!"
|
||||
"!="
|
||||
"%"
|
||||
"%="
|
||||
"&"
|
||||
"&&"
|
||||
"&="
|
||||
"*"
|
||||
"*="
|
||||
"+"
|
||||
"+="
|
||||
"-"
|
||||
"-="
|
||||
".."
|
||||
"..="
|
||||
"..."
|
||||
"/"
|
||||
"/="
|
||||
"<"
|
||||
"<<"
|
||||
"<<="
|
||||
"<="
|
||||
"="
|
||||
"=="
|
||||
">"
|
||||
">="
|
||||
">>"
|
||||
">>="
|
||||
"?"
|
||||
"@"
|
||||
"^"
|
||||
"^="
|
||||
"|"
|
||||
"|="
|
||||
"||"
|
||||
] @operator
|
||||
|
||||
(use_wildcard
|
||||
"*" @character.special)
|
||||
|
||||
(remaining_field_pattern
|
||||
".." @character.special)
|
||||
|
||||
(range_pattern
|
||||
[
|
||||
".."
|
||||
"..="
|
||||
"..."
|
||||
] @character.special)
|
||||
|
||||
; Punctuation
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
(closure_parameters
|
||||
"|" @punctuation.bracket)
|
||||
|
||||
(type_arguments
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket)
|
||||
|
||||
(type_parameters
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket)
|
||||
|
||||
(bracketed_type
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket)
|
||||
|
||||
(for_lifetimes
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket)
|
||||
|
||||
[
|
||||
","
|
||||
"."
|
||||
":"
|
||||
"::"
|
||||
";"
|
||||
"->"
|
||||
"=>"
|
||||
] @punctuation.delimiter
|
||||
|
||||
(attribute_item
|
||||
"#" @punctuation.special)
|
||||
|
||||
(inner_attribute_item
|
||||
[
|
||||
"!"
|
||||
"#"
|
||||
] @punctuation.special)
|
||||
|
||||
(macro_invocation
|
||||
"!" @function.macro)
|
||||
|
||||
(never_type
|
||||
"!" @type.builtin)
|
||||
|
||||
(macro_invocation
|
||||
macro: (identifier) @_identifier @keyword.exception
|
||||
"!" @keyword.exception
|
||||
(#eq? @_identifier "panic"))
|
||||
|
||||
(macro_invocation
|
||||
macro: (identifier) @_identifier @keyword.exception
|
||||
"!" @keyword.exception
|
||||
(#contains? @_identifier "assert"))
|
||||
|
||||
(macro_invocation
|
||||
macro: (identifier) @_identifier @keyword.debug
|
||||
"!" @keyword.debug
|
||||
(#eq? @_identifier "dbg"))
|
||||
|
||||
; Comments
|
||||
[
|
||||
(line_comment)
|
||||
(block_comment)
|
||||
(outer_doc_comment_marker)
|
||||
(inner_doc_comment_marker)
|
||||
] @comment @spell
|
||||
|
||||
(line_comment
|
||||
(doc_comment)) @comment.documentation
|
||||
|
||||
(block_comment
|
||||
(doc_comment)) @comment.documentation
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
path: (identifier) @_regex
|
||||
(#any-of? @_regex "Regex" "ByteRegexBuilder")
|
||||
name: (identifier) @_new
|
||||
(#eq? @_new "new"))
|
||||
arguments: (arguments
|
||||
(raw_string_literal
|
||||
(string_content) @string.regexp)))
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
path: (scoped_identifier
|
||||
(identifier) @_regex
|
||||
(#any-of? @_regex "Regex" "ByteRegexBuilder") .)
|
||||
name: (identifier) @_new
|
||||
(#eq? @_new "new"))
|
||||
arguments: (arguments
|
||||
(raw_string_literal
|
||||
(string_content) @string.regexp)))
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
path: (identifier) @_regex
|
||||
(#any-of? @_regex "RegexSet" "RegexSetBuilder")
|
||||
name: (identifier) @_new
|
||||
(#eq? @_new "new"))
|
||||
arguments: (arguments
|
||||
(array_expression
|
||||
(raw_string_literal
|
||||
(string_content) @string.regexp))))
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
path: (scoped_identifier
|
||||
(identifier) @_regex
|
||||
(#any-of? @_regex "RegexSet" "RegexSetBuilder") .)
|
||||
name: (identifier) @_new
|
||||
(#eq? @_new "new"))
|
||||
arguments: (arguments
|
||||
(array_expression
|
||||
(raw_string_literal
|
||||
(string_content) @string.regexp))))
|
||||
@@ -1,89 +0,0 @@
|
||||
(macro_invocation
|
||||
macro: [
|
||||
(scoped_identifier
|
||||
name: (_) @_macro_name)
|
||||
(identifier) @_macro_name
|
||||
]
|
||||
(token_tree) @injection.content
|
||||
(#not-any-of? @_macro_name "slint" "html" "json")
|
||||
(#set! injection.language "rust")
|
||||
(#set! injection.include-children))
|
||||
|
||||
(macro_invocation
|
||||
macro: [
|
||||
(scoped_identifier
|
||||
name: (_) @injection.language)
|
||||
(identifier) @injection.language
|
||||
]
|
||||
(token_tree) @injection.content
|
||||
(#any-of? @injection.language "slint" "html" "json")
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.include-children))
|
||||
|
||||
(macro_definition
|
||||
(macro_rule
|
||||
left: (token_tree_pattern) @injection.content
|
||||
(#set! injection.language "rust")))
|
||||
|
||||
(macro_definition
|
||||
(macro_rule
|
||||
right: (token_tree) @injection.content
|
||||
(#set! injection.language "rust")))
|
||||
|
||||
([
|
||||
(line_comment)
|
||||
(block_comment)
|
||||
] @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
path: (identifier) @_regex
|
||||
(#any-of? @_regex "Regex" "RegexBuilder")
|
||||
name: (identifier) @_new
|
||||
(#eq? @_new "new"))
|
||||
arguments: (arguments
|
||||
(raw_string_literal
|
||||
(string_content) @injection.content))
|
||||
(#set! injection.language "regex"))
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
path: (scoped_identifier
|
||||
(identifier) @_regex
|
||||
(#any-of? @_regex "Regex" "RegexBuilder") .)
|
||||
name: (identifier) @_new
|
||||
(#eq? @_new "new"))
|
||||
arguments: (arguments
|
||||
(raw_string_literal
|
||||
(string_content) @injection.content))
|
||||
(#set! injection.language "regex"))
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
path: (identifier) @_regex
|
||||
(#any-of? @_regex "RegexSet" "RegexSetBuilder")
|
||||
name: (identifier) @_new
|
||||
(#eq? @_new "new"))
|
||||
arguments: (arguments
|
||||
(array_expression
|
||||
(raw_string_literal
|
||||
(string_content) @injection.content)))
|
||||
(#set! injection.language "regex"))
|
||||
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
path: (scoped_identifier
|
||||
(identifier) @_regex
|
||||
(#any-of? @_regex "RegexSet" "RegexSetBuilder") .)
|
||||
name: (identifier) @_new
|
||||
(#eq? @_new "new"))
|
||||
arguments: (arguments
|
||||
(array_expression
|
||||
(raw_string_literal
|
||||
(string_content) @injection.content)))
|
||||
(#set! injection.language "regex"))
|
||||
|
||||
((block_comment) @injection.content
|
||||
(#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c")
|
||||
(#set! injection.language "re2c"))
|
||||
@@ -1,98 +0,0 @@
|
||||
; Imports
|
||||
(extern_crate_declaration
|
||||
name: (identifier) @local.definition.import)
|
||||
|
||||
(use_declaration
|
||||
argument: (scoped_identifier
|
||||
name: (identifier) @local.definition.import))
|
||||
|
||||
(use_as_clause
|
||||
alias: (identifier) @local.definition.import)
|
||||
|
||||
(use_list
|
||||
(identifier) @local.definition.import) ; use std::process::{Child, Command, Stdio};
|
||||
|
||||
; Functions
|
||||
(function_item
|
||||
name: (identifier) @local.definition.function)
|
||||
|
||||
(function_item
|
||||
name: (identifier) @local.definition.method
|
||||
parameters: (parameters
|
||||
(self_parameter)))
|
||||
|
||||
; Variables
|
||||
(parameter
|
||||
pattern: (identifier) @local.definition.var)
|
||||
|
||||
(let_declaration
|
||||
pattern: (identifier) @local.definition.var)
|
||||
|
||||
(const_item
|
||||
name: (identifier) @local.definition.var)
|
||||
|
||||
(tuple_pattern
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(let_condition
|
||||
pattern: (_
|
||||
(identifier) @local.definition.var))
|
||||
|
||||
(tuple_struct_pattern
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(closure_parameters
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(self_parameter
|
||||
(self) @local.definition.var)
|
||||
|
||||
(for_expression
|
||||
pattern: (identifier) @local.definition.var)
|
||||
|
||||
; Types
|
||||
(struct_item
|
||||
name: (type_identifier) @local.definition.type)
|
||||
|
||||
(enum_item
|
||||
name: (type_identifier) @local.definition.type)
|
||||
|
||||
; Fields
|
||||
(field_declaration
|
||||
name: (field_identifier) @local.definition.field)
|
||||
|
||||
(enum_variant
|
||||
name: (identifier) @local.definition.field)
|
||||
|
||||
; References
|
||||
(identifier) @local.reference
|
||||
|
||||
((type_identifier) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
((field_identifier) @local.reference
|
||||
(#set! reference.kind "field"))
|
||||
|
||||
; Macros
|
||||
(macro_definition
|
||||
name: (identifier) @local.definition.macro)
|
||||
|
||||
; Module
|
||||
(mod_item
|
||||
name: (identifier) @local.definition.namespace)
|
||||
|
||||
; Scopes
|
||||
[
|
||||
(block)
|
||||
(function_item)
|
||||
(closure_expression)
|
||||
(while_expression)
|
||||
(for_expression)
|
||||
(loop_expression)
|
||||
(if_expression)
|
||||
(match_expression)
|
||||
(match_arm)
|
||||
(struct_item)
|
||||
(enum_item)
|
||||
(impl_item)
|
||||
] @local.scope
|
||||
@@ -1,409 +0,0 @@
|
||||
; functions
|
||||
(function_signature_item) @function.outer
|
||||
|
||||
(function_item) @function.outer
|
||||
|
||||
(function_item
|
||||
body: (block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
; quantifies as class(es)
|
||||
(struct_item) @class.outer
|
||||
|
||||
(struct_item
|
||||
body: (field_declaration_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(enum_item) @class.outer
|
||||
|
||||
(enum_item
|
||||
body: (enum_variant_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(union_item) @class.outer
|
||||
|
||||
(union_item
|
||||
body: (field_declaration_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(trait_item) @class.outer
|
||||
|
||||
(trait_item
|
||||
body: (declaration_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(impl_item) @class.outer
|
||||
|
||||
(impl_item
|
||||
body: (declaration_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
(mod_item) @class.outer
|
||||
|
||||
(mod_item
|
||||
body: (declaration_list
|
||||
.
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
; conditionals
|
||||
(if_expression
|
||||
alternative: (_
|
||||
(_) @conditional.inner)?) @conditional.outer
|
||||
|
||||
(if_expression
|
||||
alternative: (else_clause
|
||||
(block) @conditional.inner))
|
||||
|
||||
(if_expression
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
(if_expression
|
||||
consequence: (block) @conditional.inner)
|
||||
|
||||
(match_arm
|
||||
(_)) @conditional.inner
|
||||
|
||||
(match_expression) @conditional.outer
|
||||
|
||||
; loops
|
||||
(loop_expression
|
||||
body: (block
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
(while_expression
|
||||
body: (block
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
(for_expression
|
||||
body: (block
|
||||
.
|
||||
"{"
|
||||
_+ @loop.inner
|
||||
"}")) @loop.outer
|
||||
|
||||
; blocks
|
||||
(block
|
||||
(_)* @block.inner) @block.outer
|
||||
|
||||
(unsafe_block
|
||||
(_)* @block.inner) @block.outer
|
||||
|
||||
; calls
|
||||
(macro_invocation) @call.outer
|
||||
|
||||
(macro_invocation
|
||||
(token_tree
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
(call_expression) @call.outer
|
||||
|
||||
(call_expression
|
||||
arguments: (arguments
|
||||
.
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
|
||||
; returns
|
||||
(return_expression
|
||||
(_)? @return.inner) @return.outer
|
||||
|
||||
; statements
|
||||
(block
|
||||
(_) @statement.outer)
|
||||
|
||||
; comments
|
||||
(line_comment) @comment.outer
|
||||
|
||||
(block_comment) @comment.outer
|
||||
|
||||
; parameter
|
||||
(parameters
|
||||
"," @parameter.outer
|
||||
.
|
||||
[
|
||||
(self_parameter)
|
||||
(parameter)
|
||||
(type_identifier)
|
||||
] @parameter.inner @parameter.outer)
|
||||
|
||||
(parameters
|
||||
.
|
||||
[
|
||||
(self_parameter)
|
||||
(parameter)
|
||||
(type_identifier)
|
||||
] @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(parameters
|
||||
[
|
||||
(self_parameter)
|
||||
(parameter)
|
||||
(type_identifier)
|
||||
] @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(type_parameters
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(type_parameters
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(type_parameters
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(tuple_pattern
|
||||
"," @parameter.outer
|
||||
.
|
||||
(identifier) @parameter.inner @parameter.outer)
|
||||
|
||||
(tuple_pattern
|
||||
.
|
||||
(identifier) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(tuple_pattern
|
||||
(identifier) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(tuple_struct_pattern
|
||||
"," @parameter.outer
|
||||
.
|
||||
(identifier) @parameter.inner @parameter.outer)
|
||||
|
||||
(tuple_struct_pattern
|
||||
.
|
||||
(identifier) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(tuple_struct_pattern
|
||||
(identifier) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(tuple_expression
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(tuple_expression
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(tuple_expression
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(tuple_type
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(tuple_type
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(tuple_type
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(struct_item
|
||||
body: (field_declaration_list
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer))
|
||||
|
||||
(struct_item
|
||||
body: (field_declaration_list
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer))
|
||||
|
||||
; last element, with trailing comma
|
||||
(struct_item
|
||||
body: (field_declaration_list
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .))
|
||||
|
||||
(struct_expression
|
||||
body: (field_initializer_list
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer))
|
||||
|
||||
(struct_expression
|
||||
body: (field_initializer_list
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer))
|
||||
|
||||
; last element, with trailing comma
|
||||
(struct_expression
|
||||
body: (field_initializer_list
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .))
|
||||
|
||||
(closure_parameters
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(closure_parameters
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(closure_parameters
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(arguments
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(arguments
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(arguments
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(type_arguments
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(type_arguments
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(type_arguments
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(token_tree
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer)
|
||||
|
||||
(token_tree
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; last element, with trailing comma
|
||||
(token_tree
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .)
|
||||
|
||||
(scoped_use_list
|
||||
list: (use_list
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer))
|
||||
|
||||
(scoped_use_list
|
||||
list: (use_list
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer))
|
||||
|
||||
; last element, with trailing comma
|
||||
(scoped_use_list
|
||||
list: (use_list
|
||||
(_) @parameter.outer
|
||||
.
|
||||
"," @parameter.outer .))
|
||||
|
||||
[
|
||||
(integer_literal)
|
||||
(float_literal)
|
||||
] @number.inner
|
||||
|
||||
(let_declaration
|
||||
pattern: (_) @assignment.lhs
|
||||
value: (_) @assignment.inner @assignment.rhs) @assignment.outer
|
||||
|
||||
(let_declaration
|
||||
pattern: (_) @assignment.inner)
|
||||
|
||||
(assignment_expression
|
||||
left: (_) @assignment.lhs
|
||||
right: (_) @assignment.inner @assignment.rhs) @assignment.outer
|
||||
|
||||
(assignment_expression
|
||||
left: (_) @assignment.inner)
|
||||
@@ -1,23 +0,0 @@
|
||||
[
|
||||
(block)
|
||||
(switch_expression)
|
||||
(initializer_list)
|
||||
(asm_expression)
|
||||
(multiline_string)
|
||||
(if_statement)
|
||||
(while_statement)
|
||||
(for_statement)
|
||||
(if_expression)
|
||||
(else_clause)
|
||||
(for_expression)
|
||||
(while_expression)
|
||||
(if_type_expression)
|
||||
(function_signature)
|
||||
(parameters)
|
||||
(call_expression)
|
||||
(struct_declaration)
|
||||
(opaque_declaration)
|
||||
(enum_declaration)
|
||||
(union_declaration)
|
||||
(error_set_declaration)
|
||||
] @fold
|
||||
@@ -1,283 +0,0 @@
|
||||
; Variables
|
||||
(identifier) @variable
|
||||
|
||||
; Parameters
|
||||
(parameter
|
||||
name: (identifier) @variable.parameter)
|
||||
|
||||
(payload
|
||||
(identifier) @variable.parameter)
|
||||
|
||||
; Types
|
||||
(parameter
|
||||
type: (identifier) @type)
|
||||
|
||||
((identifier) @type
|
||||
(#lua-match? @type "^[A-Z_][a-zA-Z0-9_]*"))
|
||||
|
||||
(variable_declaration
|
||||
(identifier) @type
|
||||
"="
|
||||
[
|
||||
(struct_declaration)
|
||||
(enum_declaration)
|
||||
(union_declaration)
|
||||
(opaque_declaration)
|
||||
])
|
||||
|
||||
[
|
||||
(builtin_type)
|
||||
"anyframe"
|
||||
] @type.builtin
|
||||
|
||||
; Constants
|
||||
((identifier) @constant
|
||||
(#lua-match? @constant "^[A-Z][A-Z_0-9]+$"))
|
||||
|
||||
[
|
||||
"null"
|
||||
"unreachable"
|
||||
"undefined"
|
||||
] @constant.builtin
|
||||
|
||||
(field_expression
|
||||
.
|
||||
member: (identifier) @constant)
|
||||
|
||||
(enum_declaration
|
||||
(container_field
|
||||
type: (identifier) @constant))
|
||||
|
||||
; Labels
|
||||
(block_label
|
||||
(identifier) @label)
|
||||
|
||||
(break_label
|
||||
(identifier) @label)
|
||||
|
||||
; Fields
|
||||
(field_initializer
|
||||
.
|
||||
(identifier) @variable.member)
|
||||
|
||||
(field_expression
|
||||
(_)
|
||||
member: (identifier) @variable.member)
|
||||
|
||||
(container_field
|
||||
name: (identifier) @variable.member)
|
||||
|
||||
(initializer_list
|
||||
(assignment_expression
|
||||
left: (field_expression
|
||||
.
|
||||
member: (identifier) @variable.member)))
|
||||
|
||||
; Functions
|
||||
(builtin_identifier) @function.builtin
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function.call)
|
||||
|
||||
(call_expression
|
||||
function: (field_expression
|
||||
member: (identifier) @function.call))
|
||||
|
||||
(function_declaration
|
||||
name: (identifier) @function)
|
||||
|
||||
; Modules
|
||||
(variable_declaration
|
||||
(identifier) @module
|
||||
(builtin_function
|
||||
(builtin_identifier) @keyword.import
|
||||
(#any-of? @keyword.import "@import" "@cImport")))
|
||||
|
||||
; Builtins
|
||||
[
|
||||
"c"
|
||||
"..."
|
||||
] @variable.builtin
|
||||
|
||||
((identifier) @variable.builtin
|
||||
(#eq? @variable.builtin "_"))
|
||||
|
||||
(calling_convention
|
||||
(identifier) @variable.builtin)
|
||||
|
||||
; Keywords
|
||||
[
|
||||
"asm"
|
||||
"defer"
|
||||
"errdefer"
|
||||
"test"
|
||||
"error"
|
||||
"const"
|
||||
"var"
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"struct"
|
||||
"union"
|
||||
"enum"
|
||||
"opaque"
|
||||
] @keyword.type
|
||||
|
||||
[
|
||||
"async"
|
||||
"await"
|
||||
"suspend"
|
||||
"nosuspend"
|
||||
"resume"
|
||||
] @keyword.coroutine
|
||||
|
||||
"fn" @keyword.function
|
||||
|
||||
[
|
||||
"and"
|
||||
"or"
|
||||
"orelse"
|
||||
] @keyword.operator
|
||||
|
||||
"return" @keyword.return
|
||||
|
||||
[
|
||||
"if"
|
||||
"else"
|
||||
"switch"
|
||||
] @keyword.conditional
|
||||
|
||||
[
|
||||
"for"
|
||||
"while"
|
||||
"break"
|
||||
"continue"
|
||||
] @keyword.repeat
|
||||
|
||||
[
|
||||
"usingnamespace"
|
||||
"export"
|
||||
] @keyword.import
|
||||
|
||||
[
|
||||
"try"
|
||||
"catch"
|
||||
] @keyword.exception
|
||||
|
||||
[
|
||||
"volatile"
|
||||
"allowzero"
|
||||
"noalias"
|
||||
"addrspace"
|
||||
"align"
|
||||
"callconv"
|
||||
"linksection"
|
||||
"pub"
|
||||
"inline"
|
||||
"noinline"
|
||||
"extern"
|
||||
"comptime"
|
||||
"packed"
|
||||
"threadlocal"
|
||||
] @keyword.modifier
|
||||
|
||||
; Operator
|
||||
[
|
||||
"="
|
||||
"*="
|
||||
"*%="
|
||||
"*|="
|
||||
"/="
|
||||
"%="
|
||||
"+="
|
||||
"+%="
|
||||
"+|="
|
||||
"-="
|
||||
"-%="
|
||||
"-|="
|
||||
"<<="
|
||||
"<<|="
|
||||
">>="
|
||||
"&="
|
||||
"^="
|
||||
"|="
|
||||
"!"
|
||||
"~"
|
||||
"-"
|
||||
"-%"
|
||||
"&"
|
||||
"=="
|
||||
"!="
|
||||
">"
|
||||
">="
|
||||
"<="
|
||||
"<"
|
||||
"&"
|
||||
"^"
|
||||
"|"
|
||||
"<<"
|
||||
">>"
|
||||
"<<|"
|
||||
"+"
|
||||
"++"
|
||||
"+%"
|
||||
"-%"
|
||||
"+|"
|
||||
"-|"
|
||||
"*"
|
||||
"/"
|
||||
"%"
|
||||
"**"
|
||||
"*%"
|
||||
"*|"
|
||||
"||"
|
||||
".*"
|
||||
".?"
|
||||
"?"
|
||||
".."
|
||||
] @operator
|
||||
|
||||
; Literals
|
||||
(character) @character
|
||||
|
||||
([
|
||||
(string)
|
||||
(multiline_string)
|
||||
] @string
|
||||
(#set! "priority" 95))
|
||||
|
||||
(integer) @number
|
||||
|
||||
(float) @number.float
|
||||
|
||||
(boolean) @boolean
|
||||
|
||||
(escape_sequence) @string.escape
|
||||
|
||||
; Punctuation
|
||||
[
|
||||
"["
|
||||
"]"
|
||||
"("
|
||||
")"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
[
|
||||
";"
|
||||
"."
|
||||
","
|
||||
":"
|
||||
"=>"
|
||||
"->"
|
||||
] @punctuation.delimiter
|
||||
|
||||
(payload
|
||||
"|" @punctuation.bracket)
|
||||
|
||||
; Comments
|
||||
(comment) @comment @spell
|
||||
|
||||
((comment) @comment.documentation
|
||||
(#lua-match? @comment.documentation "^//!"))
|
||||
@@ -1,10 +0,0 @@
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
||||
; TODO: add when asm is added
|
||||
; (asm_output_item (string) @injection.content
|
||||
; (#set! injection.language "asm"))
|
||||
; (asm_input_item (string) @injection.content
|
||||
; (#set! injection.language "asm"))
|
||||
; (asm_clobbers (string) @injection.content
|
||||
; (#set! injection.language "asm"))
|
||||
@@ -1,96 +0,0 @@
|
||||
; Definitions
|
||||
(function_declaration
|
||||
name: (identifier) @local.definition.function)
|
||||
|
||||
(parameter
|
||||
name: (identifier) @local.definition.parameter)
|
||||
|
||||
(variable_declaration
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(variable_declaration
|
||||
(identifier) @local.definition.type
|
||||
(enum_declaration))
|
||||
|
||||
(container_field
|
||||
type: (identifier) @local.definition.field)
|
||||
|
||||
(enum_declaration
|
||||
(function_declaration
|
||||
name: (identifier) @local.definition.method))
|
||||
|
||||
(variable_declaration
|
||||
(identifier) @local.definition.type
|
||||
(struct_declaration))
|
||||
|
||||
(struct_declaration
|
||||
(function_declaration
|
||||
name: (identifier) @local.definition.method))
|
||||
|
||||
(container_field
|
||||
name: (identifier) @local.definition.field)
|
||||
|
||||
(variable_declaration
|
||||
(identifier) @local.definition.type
|
||||
(union_declaration))
|
||||
|
||||
(union_declaration
|
||||
(function_declaration
|
||||
name: (identifier) @local.definition.method))
|
||||
|
||||
(payload
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(block_label
|
||||
(identifier) @local.definition)
|
||||
|
||||
; References
|
||||
(identifier) @local.reference
|
||||
|
||||
(parameter
|
||||
type: (identifier) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
(pointer_type
|
||||
(identifier) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
(nullable_type
|
||||
(identifier) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
(struct_initializer
|
||||
(identifier) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
(array_type
|
||||
(_)
|
||||
(identifier) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
(slice_type
|
||||
(identifier) @local.reference
|
||||
(#set! reference.kind "type"))
|
||||
|
||||
(field_expression
|
||||
member: (identifier) @local.reference
|
||||
(#set! reference.kind "field"))
|
||||
|
||||
(call_expression
|
||||
function: (field_expression
|
||||
member: (identifier) @local.reference
|
||||
(#set! reference.kind "function")))
|
||||
|
||||
(break_label
|
||||
(identifier) @local.reference)
|
||||
|
||||
[
|
||||
(for_statement)
|
||||
(if_statement)
|
||||
(while_statement)
|
||||
(function_declaration)
|
||||
(block)
|
||||
(source_file)
|
||||
(enum_declaration)
|
||||
(struct_declaration)
|
||||
] @local.scope
|
||||
@@ -1,110 +0,0 @@
|
||||
; "Classes"
|
||||
(variable_declaration
|
||||
(struct_declaration)) @class.outer
|
||||
|
||||
(variable_declaration
|
||||
(struct_declaration
|
||||
"struct"
|
||||
"{"
|
||||
_+ @class.inner
|
||||
"}"))
|
||||
|
||||
; functions
|
||||
(function_declaration) @function.outer
|
||||
|
||||
(function_declaration
|
||||
body: (block
|
||||
.
|
||||
"{"
|
||||
_+ @function.inner
|
||||
"}"))
|
||||
|
||||
; loops
|
||||
(for_statement) @loop.outer
|
||||
|
||||
(for_statement
|
||||
body: (_) @loop.inner)
|
||||
|
||||
(while_statement) @loop.outer
|
||||
|
||||
(while_statement
|
||||
body: (_) @loop.inner)
|
||||
|
||||
; blocks
|
||||
(block) @block.outer
|
||||
|
||||
(block
|
||||
"{"
|
||||
_+ @block.inner
|
||||
"}")
|
||||
|
||||
; statements
|
||||
(statement) @statement.outer
|
||||
|
||||
; parameters
|
||||
(parameters
|
||||
"," @parameter.outer
|
||||
.
|
||||
(parameter) @parameter.inner @parameter.outer)
|
||||
|
||||
(parameters
|
||||
.
|
||||
(parameter) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer)
|
||||
|
||||
; arguments
|
||||
(call_expression
|
||||
function: (_)
|
||||
arguments: (arguments
|
||||
"("
|
||||
"," @parameter.outer
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
")"))
|
||||
|
||||
(call_expression
|
||||
function: (_)
|
||||
arguments: (arguments
|
||||
"("
|
||||
.
|
||||
(_) @parameter.inner @parameter.outer
|
||||
.
|
||||
","? @parameter.outer
|
||||
")"))
|
||||
|
||||
; comments
|
||||
(comment) @comment.outer
|
||||
|
||||
; conditionals
|
||||
(if_statement) @conditional.outer
|
||||
|
||||
(if_statement
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
(if_statement
|
||||
body: (_) @conditional.inner)
|
||||
|
||||
(switch_expression) @conditional.outer
|
||||
|
||||
(switch_expression
|
||||
"("
|
||||
(_) @conditional.inner
|
||||
")")
|
||||
|
||||
(switch_expression
|
||||
"{"
|
||||
_+ @conditional.inner
|
||||
"}")
|
||||
|
||||
(while_statement
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
; calls
|
||||
(call_expression) @call.outer
|
||||
|
||||
(call_expression
|
||||
arguments: (arguments
|
||||
"("
|
||||
_+ @call.inner
|
||||
")"))
|
||||
Reference in New Issue
Block a user