mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-04 12:30:01 -04:00
Remove textobjects module
This commit is contained in:
parent
7f325538cc
commit
3362f45196
16 changed files with 0 additions and 779 deletions
89
README.md
89
README.md
|
|
@ -158,95 +158,6 @@ require'nvim-treesitter.configs'.setup {
|
|||
EOF
|
||||
```
|
||||
|
||||
## Text objects: select
|
||||
|
||||
Define your own text objects mappings
|
||||
similar to `ip` (inner paragraph) and `ap` (a paragraph).
|
||||
|
||||
```lua
|
||||
lua <<EOF
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
textobjects = {
|
||||
select = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
-- You can use the capture groups defined in textobjects.scm
|
||||
["af"] = "@function.outer",
|
||||
["if"] = "@function.inner",
|
||||
["ac"] = "@class.outer",
|
||||
["ic"] = "@class.inner",
|
||||
|
||||
-- Or you can define your own textobjects like this
|
||||
["iF"] = {
|
||||
python = "(function_definition) @function",
|
||||
cpp = "(function_definition) @function",
|
||||
c = "(function_definition) @function",
|
||||
java = "(method_declaration) @function",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
## Text objects: swap
|
||||
|
||||
Define your own mappings to swap the node under the cursor with the next or previous one,
|
||||
like function parameters or arguments.
|
||||
|
||||
```lua
|
||||
lua <<EOF
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
textobjects = {
|
||||
swap = {
|
||||
enable = true,
|
||||
swap_next = {
|
||||
["<leader>a"] = "@parameter.inner",
|
||||
},
|
||||
swap_previous = {
|
||||
["<leader>A"] = "@parameter.inner",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
## Text objects: move
|
||||
|
||||
Define your own mappings to jump to the next or previous text object.
|
||||
This is similar to `]m`, `[m`, `]M`, `[M` Neovim's mappings to jump to the next
|
||||
or previous function.
|
||||
|
||||
```lua
|
||||
lua <<EOF
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
textobjects = {
|
||||
move = {
|
||||
enable = true,
|
||||
goto_next_start = {
|
||||
["]m"] = "@function.outer",
|
||||
["]]"] = "@class.outer",
|
||||
},
|
||||
goto_next_end = {
|
||||
["]M"] = "@function.outer",
|
||||
["]["] = "@class.outer",
|
||||
},
|
||||
goto_previous_start = {
|
||||
["[m"] = "@function.outer",
|
||||
["[["] = "@class.outer",
|
||||
},
|
||||
goto_previous_end = {
|
||||
["[M"] = "@function.outer",
|
||||
["[]"] = "@class.outer",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
# External modules
|
||||
|
||||
Other modules can be installed as plugins.
|
||||
|
|
|
|||
|
|
@ -7,17 +7,6 @@ local caching = require'nvim-treesitter.caching'
|
|||
|
||||
local M = {}
|
||||
|
||||
local function has_some_textobject_mapping(lang)
|
||||
for _, v in pairs(M.get_module('textobjects.select').keymaps) do
|
||||
if type(v) == 'table' then
|
||||
if v[lang] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local config = {
|
||||
modules = {},
|
||||
ensure_installed = {},
|
||||
|
|
@ -47,35 +36,6 @@ local builtin_modules = {
|
|||
},
|
||||
is_supported = queries.has_locals
|
||||
},
|
||||
textobjects = {
|
||||
select = {
|
||||
module_path = 'nvim-treesitter.textobjects.select',
|
||||
enable = false,
|
||||
disable = {},
|
||||
is_supported = function(lang)
|
||||
return queries.has_textobjects(lang) or has_some_textobject_mapping(lang)
|
||||
end,
|
||||
keymaps = {},
|
||||
},
|
||||
move = {
|
||||
module_path = 'nvim-treesitter.textobjects.move',
|
||||
enable = false,
|
||||
disable = {},
|
||||
is_supported = queries.has_textobjects,
|
||||
goto_next_start = {},
|
||||
goto_next_end = {},
|
||||
goto_previous_start = {},
|
||||
goto_previous_end = {},
|
||||
},
|
||||
swap = {
|
||||
module_path = 'nvim-treesitter.textobjects.swap',
|
||||
enable = false,
|
||||
disable = {},
|
||||
is_supported = queries.has_textobjects,
|
||||
swap_next = {},
|
||||
swap_previous = {},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
local attached_buffers_by_module = caching.create_buffer_cache()
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
local configs = require'nvim-treesitter.configs'
|
||||
local parsers = require'nvim-treesitter.parsers'
|
||||
local queries = require'nvim-treesitter.query'
|
||||
local api = vim.api
|
||||
local M = {}
|
||||
|
||||
function M.make_attach(normal_mode_functions, submodule)
|
||||
return function(bufnr, lang)
|
||||
local config = configs.get_module("textobjects."..submodule)
|
||||
local lang = lang or parsers.get_buf_lang(bufnr)
|
||||
|
||||
for _, function_call in pairs(normal_mode_functions) do
|
||||
for mapping, query in pairs(config[function_call] or {}) do
|
||||
if type(query) == 'table' then
|
||||
query = query[lang]
|
||||
elseif not queries.get_query(lang, 'textobjects') then
|
||||
query = nil
|
||||
end
|
||||
if query then
|
||||
local cmd = ":lua require'nvim-treesitter.textobjects."..submodule.."'."..function_call.."('"..query.."')<CR>"
|
||||
api.nvim_buf_set_keymap(bufnr, "n", mapping, cmd, {silent = true, noremap = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.make_detach(normal_mode_functions, submodule)
|
||||
return function(bufnr)
|
||||
local config = configs.get_module("textobjects."..submodule)
|
||||
local lang = parsers.get_buf_lang(bufnr)
|
||||
|
||||
for mapping, query in pairs(config.keymaps) do
|
||||
if type(query) == 'table' then
|
||||
query = query[lang]
|
||||
elseif not queries.get_query(lang, 'textobjects') then
|
||||
query = nil
|
||||
end
|
||||
if query then
|
||||
api.nvim_buf_del_keymap(bufnr, "o", mapping)
|
||||
api.nvim_buf_del_keymap(bufnr, "v", mapping)
|
||||
end
|
||||
end
|
||||
for _, function_call in pairs(normal_mode_functions) do
|
||||
for mapping, query in pairs(config[function_call] or {}) do
|
||||
if type(query) == 'table' then
|
||||
query = query[lang]
|
||||
elseif not queries.get_query(lang, 'textobjects') then
|
||||
query = nil
|
||||
end
|
||||
if query then
|
||||
api.nvim_buf_del_keymap(bufnr, "n", mapping)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
local ts_utils = require'nvim-treesitter.ts_utils'
|
||||
local shared = require'nvim-treesitter.textobjects.shared'
|
||||
local attach = require'nvim-treesitter.textobjects.attach'
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.goto_adjacent(query_string, forward, start, same_parent, overlapping_range_ok)
|
||||
local bufnr, _, node = shared.textobject_at_point(query_string)
|
||||
local adjacent = shared.get_adjacent(forward, node, query_string, same_parent, overlapping_range_ok, bufnr)
|
||||
|
||||
ts_utils.goto_node(adjacent, not start)
|
||||
end
|
||||
|
||||
-- luacheck: push ignore 631
|
||||
M.goto_next_start = function(query_string) M.goto_adjacent(query_string, 'forward', 'start', not 'same_parent', 'overlap ok') end
|
||||
M.goto_next_end = function(query_string) M.goto_adjacent(query_string, 'forward', not 'start', not 'same_parent', 'overlap ok') end
|
||||
M.goto_previous_start = function(query_string) M.goto_adjacent(query_string, not 'forward', 'start', not 'same_parent', 'overlap ok') end
|
||||
M.goto_previous_end = function(query_string) M.goto_adjacent(query_string, not 'forward', not 'start', not 'same_parent', 'overlap ok') end
|
||||
-- luacheck: pop
|
||||
|
||||
local normal_mode_functions = {"goto_next_start",
|
||||
"goto_next_end",
|
||||
"goto_previous_start",
|
||||
"goto_previous_end"}
|
||||
|
||||
M.attach = attach.make_attach(normal_mode_functions, "move")
|
||||
M.deattach = attach.make_detach(normal_mode_functions, "move")
|
||||
|
||||
return M
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
local api = vim.api
|
||||
local configs = require'nvim-treesitter.configs'
|
||||
local parsers = require'nvim-treesitter.parsers'
|
||||
local queries = require'nvim-treesitter.query'
|
||||
|
||||
local shared = require'nvim-treesitter.textobjects.shared'
|
||||
local ts_utils = require'nvim-treesitter.ts_utils'
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.select_textobject(query_string)
|
||||
local bufnr, textobject = shared.textobject_at_point(query_string)
|
||||
if textobject then
|
||||
ts_utils.update_selection(bufnr, textobject)
|
||||
end
|
||||
end
|
||||
|
||||
function M.attach(bufnr, lang)
|
||||
local buf = bufnr or api.nvim_get_current_buf()
|
||||
local config = configs.get_module("textobjects.select")
|
||||
local lang = lang or parsers.get_buf_lang(buf)
|
||||
|
||||
for mapping, query in pairs(config.keymaps) do
|
||||
if type(query) == 'table' then
|
||||
query = query[lang]
|
||||
elseif not queries.get_query(lang, 'textobjects') then
|
||||
query = nil
|
||||
end
|
||||
if query then
|
||||
local cmd = ":lua require'nvim-treesitter.textobjects.select'.select_textobject('"..query.."')<CR>"
|
||||
api.nvim_buf_set_keymap(buf, "o", mapping, cmd, {silent = true, noremap = true })
|
||||
api.nvim_buf_set_keymap(buf, "x", mapping, cmd, {silent = true, noremap = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.detach(bufnr)
|
||||
local buf = bufnr or api.nvim_get_current_buf()
|
||||
local config = configs.get_module("textobjects.select")
|
||||
local lang = parsers.get_buf_lang(bufnr)
|
||||
|
||||
for mapping, query in pairs(config.keymaps) do
|
||||
if type(query) == 'table' then
|
||||
query = query[lang]
|
||||
elseif not queries.get_query(lang, 'textobjects') then
|
||||
query = nil
|
||||
end
|
||||
if query then
|
||||
api.nvim_buf_del_keymap(buf, "o", mapping)
|
||||
api.nvim_buf_del_keymap(buf, "x", mapping)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
local api = vim.api
|
||||
local ts = vim.treesitter
|
||||
|
||||
local parsers = require "nvim-treesitter.parsers"
|
||||
local queries = require'nvim-treesitter.query'
|
||||
local ts_utils = require'nvim-treesitter.ts_utils'
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.textobject_at_point(query_string)
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local lang = parsers.get_buf_lang(bufnr)
|
||||
if not lang then return end
|
||||
|
||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
row = row - 1
|
||||
|
||||
local matches = {}
|
||||
|
||||
if string.match(query_string, '^@.*') then
|
||||
matches = queries.get_capture_matches(bufnr, query_string, 'textobjects')
|
||||
else
|
||||
local parser = parsers.get_parser(bufnr, lang)
|
||||
local root = parser:parse():root()
|
||||
|
||||
local start_row, _, end_row, _ = root:range()
|
||||
|
||||
local query = ts.parse_query(lang, query_string)
|
||||
for m in queries.iter_prepared_matches(query, root, bufnr, start_row, end_row) do
|
||||
for _, n in pairs(m) do
|
||||
if n.node then
|
||||
table.insert(matches, n)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local match_length
|
||||
local smallest_range
|
||||
local earliest_start
|
||||
|
||||
for _, m in pairs(matches) do
|
||||
if m.node and ts_utils.is_in_node_range(m.node, row, col) then
|
||||
local length = ts_utils.node_length(m.node)
|
||||
if not match_length or length < match_length then
|
||||
smallest_range = m
|
||||
match_length = length
|
||||
end
|
||||
-- for nodes with same length take the one with earliest start
|
||||
if match_length and length == smallest_range then
|
||||
local start = m.start
|
||||
if start then
|
||||
local _, _, start_byte = m.start.node:start()
|
||||
if not earliest_start or start_byte < earliest_start then
|
||||
smallest_range = m
|
||||
match_length = length
|
||||
earliest_start = start_byte
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if smallest_range then
|
||||
if smallest_range.start then
|
||||
local start_range = {smallest_range.start.node:range()}
|
||||
local node_range = {smallest_range.node:range()}
|
||||
return bufnr, {start_range[1], start_range[2], node_range[3], node_range[4]}, smallest_range.node
|
||||
else
|
||||
return bufnr, {smallest_range.node:range()}, smallest_range.node
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.get_adjacent(forward, node, query_string, same_parent, overlapping_range_ok, bufnr)
|
||||
local fn = forward and M.next_textobject or M.previous_textobject
|
||||
return fn(node, query_string, same_parent, overlapping_range_ok, bufnr)
|
||||
end
|
||||
|
||||
function M.next_textobject(node, query_string, same_parent, overlapping_range_ok, bufnr)
|
||||
local node = node or ts_utils.get_node_at_cursor()
|
||||
local bufnr = bufnr or api.nvim_get_current_buf()
|
||||
if not node then return end
|
||||
|
||||
local _, _, node_end = node:end_()
|
||||
local search_start, _
|
||||
if overlapping_range_ok then
|
||||
_, _, search_start = node:start()
|
||||
else
|
||||
_, _, search_start = node:end_()
|
||||
end
|
||||
local function filter_function(match)
|
||||
if match.node == node then return end
|
||||
if not same_parent or node:parent() == match.node:parent() then
|
||||
local _, _, start = match.node:start()
|
||||
local _, _, end_ = match.node:end_()
|
||||
return start > search_start and end_ >= node_end
|
||||
end
|
||||
end
|
||||
local function scoring_function(match)
|
||||
local _, _, node_start = match.node:start()
|
||||
return -node_start
|
||||
end
|
||||
|
||||
local next_node = queries.find_best_match(bufnr, query_string, 'textobjects', filter_function, scoring_function)
|
||||
|
||||
return next_node and next_node.node
|
||||
end
|
||||
|
||||
function M.previous_textobject(node, query_string, same_parent, overlapping_range_ok, bufnr)
|
||||
local node = node or ts_utils.get_node_at_cursor()
|
||||
local bufnr = bufnr or api.nvim_get_current_buf()
|
||||
if not node then return end
|
||||
|
||||
local _, _, node_start = node:start()
|
||||
local search_end, _
|
||||
if overlapping_range_ok then
|
||||
_, _, search_end = node:end_()
|
||||
search_end = search_end + 1
|
||||
else
|
||||
_, _, search_end = node:start()
|
||||
end
|
||||
|
||||
local function filter_function(match)
|
||||
if not same_parent or node:parent() == match.node:parent() then
|
||||
local _, _, end_ = match.node:end_()
|
||||
local _, _, start = match.node:start()
|
||||
return end_ < search_end and start < node_start
|
||||
end
|
||||
end
|
||||
|
||||
local function scoring_function(match)
|
||||
local _, _, node_end = match.node:end_()
|
||||
return node_end
|
||||
end
|
||||
|
||||
local previous_node = queries.find_best_match(bufnr, query_string, 'textobjects', filter_function, scoring_function)
|
||||
|
||||
return previous_node and previous_node.node
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
local ts_utils = require'nvim-treesitter.ts_utils'
|
||||
local shared = require'nvim-treesitter.textobjects.shared'
|
||||
local attach = require'nvim-treesitter.textobjects.attach'
|
||||
|
||||
local M = {}
|
||||
|
||||
local function swap_textobject(query_string, direction)
|
||||
local bufnr, textobject_range, node = shared.textobject_at_point(query_string)
|
||||
if not node then return end
|
||||
|
||||
local step = direction > 0 and 1 or -1
|
||||
local overlapping_range_ok = false
|
||||
local same_parent = true
|
||||
for _ = 1, math.abs(direction), step do
|
||||
local forward = direction > 0
|
||||
local adjacent = shared.get_adjacent(forward, node, query_string, same_parent, overlapping_range_ok, bufnr)
|
||||
ts_utils.swap_nodes(textobject_range, adjacent, bufnr, "yes, set cursor!")
|
||||
end
|
||||
end
|
||||
|
||||
function M.swap_next(query_string)
|
||||
swap_textobject(query_string, 1)
|
||||
end
|
||||
|
||||
function M.swap_previous(query_string)
|
||||
swap_textobject(query_string, -1)
|
||||
end
|
||||
|
||||
local normal_mode_functions = {"swap_next",
|
||||
"swap_previous"}
|
||||
|
||||
M.attach = attach.make_attach(normal_mode_functions, "swap")
|
||||
M.deattach = attach.make_detach(normal_mode_functions, "swap")
|
||||
|
||||
return M
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
;; TODO: supported by official Tree-sitter if (_)* is more than one node
|
||||
;; Neovim: will only match if (_) is exactly one node
|
||||
;(function_definition
|
||||
;body: (compound_statement
|
||||
;("{" (_)* @function.inner "}"))?) @function.outer
|
||||
|
||||
(function_definition
|
||||
body: (compound_statement) @function.inner) @function.outer
|
||||
|
||||
(struct_specifier
|
||||
body: (_) @class.inner) @class.outer
|
||||
|
||||
; conditional
|
||||
(if_statement
|
||||
consequence: (_)? @conditional.inner
|
||||
alternative: (_)? @conditional.inner
|
||||
) @conditional.outer
|
||||
|
||||
(if_statement
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
; loops
|
||||
(for_statement
|
||||
(_)? @loop.inner) @loop.outer
|
||||
(while_statement
|
||||
(_)? @loop.inner) @loop.outer
|
||||
(do_statement
|
||||
(_)? @loop.inner) @loop.outer
|
||||
|
||||
|
||||
(compound_statement) @block.outer
|
||||
(comment) @comment.outer
|
||||
|
||||
(call_expression) @call.outer
|
||||
(call_expression (_) @call.inner)
|
||||
|
||||
; Statements
|
||||
|
||||
;(expression_statement ;; this is what we actually want to capture in most cases (";" is missing) probaly
|
||||
;(_) @statement.inner) ;; the otther 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_declaration) @parameter.inner)
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
(method_declaration
|
||||
body: (block) ? @function.inner) @function.outer
|
||||
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
|
||||
(class_specifier
|
||||
body: (_) @class.inner) @class.outer
|
||||
|
||||
(for_range_loop
|
||||
(_)? @loop.inner) @loop.outer
|
||||
|
||||
(template_declaration
|
||||
(function_definition) @function.outer) @function.outer.start
|
||||
|
||||
(template_declaration
|
||||
(struct_specifier) @class.outer) @class.outer.start
|
||||
|
||||
(template_declaration
|
||||
(class_specifier) @class.outer) @class.outer.start
|
||||
|
||||
(parameter_list
|
||||
(optional_parameter_declaration) @parameter.inner)
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
;; function textobject
|
||||
(function_declaration
|
||||
body: (block)? @function.inner) @function.outer
|
||||
|
||||
;; function literals
|
||||
(func_literal
|
||||
(_)? @function.inner) @function.outer
|
||||
|
||||
;; method as function textobject
|
||||
(method_declaration
|
||||
body: (block)? @function.inner) @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 (method_spec_list (_)?) @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.inner) @call.outer
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
(function_declaration
|
||||
body: (statement_block) @function.inner) @function.outer
|
||||
|
||||
(export_statement
|
||||
(function_declaration) @function.outer) @function.outer.start
|
||||
|
||||
(arrow_function
|
||||
body: (_) @function.inner) @function.outer
|
||||
|
||||
(method_definition
|
||||
body: (statement_block) @function.inner) @function.outer
|
||||
|
||||
(class_declaration
|
||||
body: (class_body) @class.inner) @class.outer
|
||||
|
||||
(export_statement
|
||||
(class_declaration) @class.outer) @class.outer.start
|
||||
|
||||
(for_in_statement
|
||||
body: (_)? @loop.inner) @loop.outer
|
||||
|
||||
(while_statement
|
||||
body: (_)? @loop.inner) @loop.outer
|
||||
|
||||
(do_statement
|
||||
body: (_)? @loop.inner) @loop.outer
|
||||
|
||||
(if_statement
|
||||
consequence: (_)? @conditional.inner
|
||||
alternative: (_)? @conditional.inner) @conditional.outer
|
||||
|
||||
(switch_statement
|
||||
body: (_)? @conditional.inner) @conditional.outer
|
||||
|
||||
(call_expression) @call.outer
|
||||
(call_expression (arguments) @call.inner)
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
(function) @function.outer
|
||||
|
||||
(local_function) @function.outer
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
(function_definition
|
||||
body: (block)? @function.inner) @function.outer
|
||||
|
||||
(decorated_definition
|
||||
(function_definition) @function.outer) @function.outer.start
|
||||
|
||||
(class_definition
|
||||
body: (block)? @class.inner) @class.outer
|
||||
|
||||
(decorated_definition
|
||||
(class_definition) @class.outer) @class.outer.start
|
||||
|
||||
(while_statement
|
||||
body: (block)? @loop.inner) @loop.outer
|
||||
|
||||
(for_statement
|
||||
body: (block)? @loop.inner) @loop.outer
|
||||
|
||||
(if_statement
|
||||
alternative: (_ (_) @conditional.inner)?) @conditional.outer
|
||||
|
||||
(if_statement
|
||||
consequence: (block)? @conditional.inner)
|
||||
|
||||
(if_statement
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
(_ (block) @block.inner) @block.outer
|
||||
(comment) @comment.outer
|
||||
|
||||
(block (_) @statement.outer)
|
||||
|
||||
(call) @call.outer
|
||||
(call (_) @call.inner)
|
||||
|
||||
;; Parameters
|
||||
(parameters
|
||||
[(identifier)
|
||||
(tuple)
|
||||
(typed_parameter)
|
||||
(default_parameter)
|
||||
(typed_default_parameter)
|
||||
(list_splat)
|
||||
(dictionary_splat)] @parameter.inner)
|
||||
|
||||
(lambda_parameters
|
||||
[(identifier)
|
||||
(tuple)
|
||||
(typed_parameter)
|
||||
(default_parameter)
|
||||
(typed_default_parameter)
|
||||
(list_splat)
|
||||
(dictionary_splat)] @parameter.inner)
|
||||
|
||||
; TODO: exclude comments using the future negate syntax from tree-sitter
|
||||
(argument_list (_) @parameter.inner)
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
(directive
|
||||
body: (body) @function.inner) @function.outer
|
||||
|
||||
(section (title) @class.inner) @class.outer
|
||||
|
||||
(transition) @class.outer
|
||||
|
||||
[
|
||||
(bullet_list)
|
||||
(enumerated_list)
|
||||
(definition_list)
|
||||
(field_list)
|
||||
|
||||
(literal_block)
|
||||
(line_block)
|
||||
(block_quote)
|
||||
(doctest_block)
|
||||
] @block.outer
|
||||
|
||||
(footnote
|
||||
body: (body) @block.inner) @block.outer
|
||||
|
||||
(citation
|
||||
body: (body) @block.inner) @block.outer
|
||||
|
||||
(target
|
||||
link: (link) @block.inner) @block.outer
|
||||
|
||||
(substitution_definition
|
||||
body: (body) @block.inner) @block.outer
|
||||
|
||||
(comment) @comment.outer
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
;; functions
|
||||
(function_item
|
||||
(_) @function.inner) @function.outer
|
||||
|
||||
;; quantifies as class(es)
|
||||
(struct_item
|
||||
(_) @class.inner) @class.outer
|
||||
|
||||
(enum_item
|
||||
(_) @class.inner) @class.outer
|
||||
|
||||
(union_item
|
||||
(_) @class.inner) @class.outer
|
||||
|
||||
(trait_item
|
||||
(_) @class.inner) @class.outer
|
||||
|
||||
(impl_item
|
||||
(_) @class.inner) @class.outer
|
||||
|
||||
;; conditionals
|
||||
(if_expression
|
||||
alternative: (_ (_)? @conditional.inner)?
|
||||
) @conditional.outer
|
||||
|
||||
(if_expression
|
||||
alternative: (block)? @conditional.inner)
|
||||
|
||||
(if_expression
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
(if_expression
|
||||
consequence: (block)? @conditional.inner)
|
||||
|
||||
(match_arm
|
||||
(_)) @conditional.inner
|
||||
|
||||
(match_expression
|
||||
(match_arm)?
|
||||
) @conditional.outer
|
||||
|
||||
(if_let_expression
|
||||
consequence: (block)?
|
||||
@conditional.inner) @conditional.outer
|
||||
|
||||
(if_let_expression
|
||||
alternative: (block)? @conditional.inner)
|
||||
|
||||
(if_let_expression
|
||||
condition: (_) @conditional.inner)
|
||||
|
||||
;; loops
|
||||
(loop_expression
|
||||
(_)? @loop.inner) @loop.outer
|
||||
|
||||
(while_expression
|
||||
(_)? @loop.inner) @loop.outer
|
||||
|
||||
(while_let_expression
|
||||
(_)? @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
|
||||
(call_expression (_)? @call.inner) @call.outer
|
||||
|
||||
;; statements
|
||||
(block (_) @statement.outer)
|
||||
Loading…
Add table
Add a link
Reference in a new issue