mirror of
https://github.com/neovim/neovim.git
synced 2025-12-11 09:02:40 +00:00
refactor(treesitter): rename x_position => x_pos
"pos" has a long precedent as "position" in vim, and there is no reason to use a verbose name here.
This commit is contained in:
@@ -251,6 +251,12 @@ Use existing common {action} names if possible:
|
|||||||
list Get all things
|
list Get all things
|
||||||
set Set a thing (or group of things)
|
set Set a thing (or group of things)
|
||||||
|
|
||||||
|
Use existing common {thing} names if possible:
|
||||||
|
buf Buffer
|
||||||
|
pos Position
|
||||||
|
tab Tabpage
|
||||||
|
win Window
|
||||||
|
|
||||||
Use consistent names for {thing} in all API functions. E.g. a buffer is called
|
Use consistent names for {thing} in all API functions. E.g. a buffer is called
|
||||||
"buf" everywhere, not "buffer" in some places and "buf" in others.
|
"buf" everywhere, not "buffer" in some places and "buf" in others.
|
||||||
|
|
||||||
|
|||||||
@@ -434,8 +434,7 @@ get_captures_at_cursor({winnr}) *get_captures_at_cursor()*
|
|||||||
Return: ~
|
Return: ~
|
||||||
string[] List of capture names
|
string[] List of capture names
|
||||||
|
|
||||||
*get_captures_at_position()*
|
get_captures_at_pos({bufnr}, {row}, {col}) *get_captures_at_pos()*
|
||||||
get_captures_at_position({bufnr}, {row}, {col})
|
|
||||||
Returns a list of highlight captures at the given position
|
Returns a list of highlight captures at the given position
|
||||||
|
|
||||||
Each capture is represented by a table containing the capture name as a
|
Each capture is represented by a table containing the capture name as a
|
||||||
@@ -460,8 +459,7 @@ get_node_at_cursor({winnr}) *get_node_at_cursor()*
|
|||||||
Return: ~
|
Return: ~
|
||||||
(string) Name of node under the cursor
|
(string) Name of node under the cursor
|
||||||
|
|
||||||
*get_node_at_position()*
|
get_node_at_pos({bufnr}, {row}, {col}, {opts}) *get_node_at_pos()*
|
||||||
get_node_at_position({bufnr}, {row}, {col}, {opts})
|
|
||||||
Returns the smallest named node at the given position
|
Returns the smallest named node at the given position
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ end
|
|||||||
---@param col number Position column
|
---@param col number Position column
|
||||||
---
|
---
|
||||||
---@return table[] List of captures `{ capture = "capture name", metadata = { ... } }`
|
---@return table[] List of captures `{ capture = "capture name", metadata = { ... } }`
|
||||||
function M.get_captures_at_position(bufnr, row, col)
|
function M.get_captures_at_pos(bufnr, row, col)
|
||||||
if bufnr == 0 then
|
if bufnr == 0 then
|
||||||
bufnr = a.nvim_get_current_buf()
|
bufnr = a.nvim_get_current_buf()
|
||||||
end
|
end
|
||||||
@@ -258,7 +258,7 @@ function M.get_captures_at_cursor(winnr)
|
|||||||
local bufnr = a.nvim_win_get_buf(winnr)
|
local bufnr = a.nvim_win_get_buf(winnr)
|
||||||
local cursor = a.nvim_win_get_cursor(winnr)
|
local cursor = a.nvim_win_get_cursor(winnr)
|
||||||
|
|
||||||
local data = M.get_captures_at_position(bufnr, cursor[1] - 1, cursor[2])
|
local data = M.get_captures_at_pos(bufnr, cursor[1] - 1, cursor[2])
|
||||||
|
|
||||||
local captures = {}
|
local captures = {}
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ end
|
|||||||
--- - ignore_injections boolean Ignore injected languages (default true)
|
--- - ignore_injections boolean Ignore injected languages (default true)
|
||||||
---
|
---
|
||||||
---@return userdata |tsnode| under the cursor
|
---@return userdata |tsnode| under the cursor
|
||||||
function M.get_node_at_position(bufnr, row, col, opts)
|
function M.get_node_at_pos(bufnr, row, col, opts)
|
||||||
if bufnr == 0 then
|
if bufnr == 0 then
|
||||||
bufnr = a.nvim_get_current_buf()
|
bufnr = a.nvim_get_current_buf()
|
||||||
end
|
end
|
||||||
@@ -302,8 +302,7 @@ function M.get_node_at_cursor(winnr)
|
|||||||
local bufnr = a.nvim_win_get_buf(winnr)
|
local bufnr = a.nvim_win_get_buf(winnr)
|
||||||
local cursor = a.nvim_win_get_cursor(winnr)
|
local cursor = a.nvim_win_get_cursor(winnr)
|
||||||
|
|
||||||
return M.get_node_at_position(bufnr, cursor[1] - 1, cursor[2], { ignore_injections = false })
|
return M.get_node_at_pos(bufnr, cursor[1] - 1, cursor[2], { ignore_injections = false }):type()
|
||||||
:type()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Starts treesitter highlighting for a buffer
|
--- Starts treesitter highlighting for a buffer
|
||||||
|
|||||||
@@ -607,7 +607,7 @@ describe('treesitter highlighting', function()
|
|||||||
eq({
|
eq({
|
||||||
{capture='Error', metadata = { priority='101' }};
|
{capture='Error', metadata = { priority='101' }};
|
||||||
{capture='type', metadata = { } };
|
{capture='type', metadata = { } };
|
||||||
}, exec_lua [[ return vim.treesitter.get_captures_at_position(0, 0, 2) ]])
|
}, exec_lua [[ return vim.treesitter.get_captures_at_pos(0, 0, 2) ]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("allows to use captures with dots (don't use fallback when specialization of foo exists)", function()
|
it("allows to use captures with dots (don't use fallback when specialization of foo exists)", function()
|
||||||
|
|||||||
Reference in New Issue
Block a user