mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor: rename local API alias from a to api
Problem: Codebase inconsistently binds vim.api onto a or api. Solution: Use api everywhere. a as an identifier is too short to have at the module level.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
local a = vim.api
|
||||
local api = vim.api
|
||||
|
||||
-- TODO(tjdevries): Improve option metadata so that this doesn't have to be hardcoded.
|
||||
-- Can be done in a separate PR.
|
||||
@@ -30,7 +30,7 @@ end
|
||||
|
||||
local options_info = setmetatable({}, {
|
||||
__index = function(t, k)
|
||||
local info = a.nvim_get_option_info(k)
|
||||
local info = api.nvim_get_option_info(k)
|
||||
info.metatype = get_option_metatype(k, info)
|
||||
rawset(t, k, info)
|
||||
return rawget(t, k)
|
||||
@@ -74,12 +74,12 @@ local function new_opt_accessor(handle, scope)
|
||||
return new_opt_accessor(k, scope)
|
||||
end
|
||||
opt_validate(k, scope)
|
||||
return a.nvim_get_option_value(k, { [scope] = handle or 0 })
|
||||
return api.nvim_get_option_value(k, { [scope] = handle or 0 })
|
||||
end,
|
||||
|
||||
__newindex = function(_, k, v)
|
||||
opt_validate(k, scope)
|
||||
return a.nvim_set_option_value(k, v, { [scope] = handle or 0 })
|
||||
return api.nvim_set_option_value(k, v, { [scope] = handle or 0 })
|
||||
end,
|
||||
})
|
||||
end
|
||||
@@ -91,10 +91,10 @@ vim.wo = new_opt_accessor(nil, 'win')
|
||||
-- this ONLY sets the global option. like `setglobal`
|
||||
vim.go = setmetatable({}, {
|
||||
__index = function(_, k)
|
||||
return a.nvim_get_option_value(k, { scope = 'global' })
|
||||
return api.nvim_get_option_value(k, { scope = 'global' })
|
||||
end,
|
||||
__newindex = function(_, k, v)
|
||||
return a.nvim_set_option_value(k, v, { scope = 'global' })
|
||||
return api.nvim_set_option_value(k, v, { scope = 'global' })
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -102,10 +102,10 @@ vim.go = setmetatable({}, {
|
||||
-- it has no additional metamethod magic.
|
||||
vim.o = setmetatable({}, {
|
||||
__index = function(_, k)
|
||||
return a.nvim_get_option_value(k, {})
|
||||
return api.nvim_get_option_value(k, {})
|
||||
end,
|
||||
__newindex = function(_, k, v)
|
||||
return a.nvim_set_option_value(k, v, {})
|
||||
return api.nvim_set_option_value(k, v, {})
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -488,7 +488,7 @@ local function create_option_accessor(scope)
|
||||
-- opt[my_option] = value
|
||||
_set = function(self)
|
||||
local value = convert_value_to_vim(self._name, self._info, self._value)
|
||||
a.nvim_set_option_value(self._name, value, { scope = scope })
|
||||
api.nvim_set_option_value(self._name, value, { scope = scope })
|
||||
end,
|
||||
|
||||
get = function(self)
|
||||
@@ -526,7 +526,7 @@ local function create_option_accessor(scope)
|
||||
|
||||
return setmetatable({}, {
|
||||
__index = function(_, k)
|
||||
return make_option(k, a.nvim_get_option_value(k, {}))
|
||||
return make_option(k, api.nvim_get_option_value(k, {}))
|
||||
end,
|
||||
|
||||
__newindex = function(_, k, v)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local a = vim.api
|
||||
local api = vim.api
|
||||
local LanguageTree = require('vim.treesitter.languagetree')
|
||||
local Range = require('vim.treesitter._range')
|
||||
|
||||
@@ -80,7 +80,7 @@ function M._create_parser(bufnr, lang, opts)
|
||||
|
||||
local source = self:source() --[[@as integer]]
|
||||
|
||||
a.nvim_buf_attach(
|
||||
api.nvim_buf_attach(
|
||||
source,
|
||||
false,
|
||||
{ on_bytes = bytes_cb, on_detach = detach_cb, on_reload = reload_cb, preview = true }
|
||||
@@ -109,7 +109,7 @@ function M.get_parser(bufnr, lang, opts)
|
||||
opts = opts or {}
|
||||
|
||||
if bufnr == nil or bufnr == 0 then
|
||||
bufnr = a.nvim_get_current_buf()
|
||||
bufnr = api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
if not valid_lang(lang) then
|
||||
@@ -141,7 +141,7 @@ end
|
||||
---@return boolean
|
||||
function M._has_parser(bufnr)
|
||||
if bufnr == nil or bufnr == 0 then
|
||||
bufnr = a.nvim_get_current_buf()
|
||||
bufnr = api.nvim_get_current_buf()
|
||||
end
|
||||
return parsers[bufnr] ~= nil
|
||||
end
|
||||
@@ -229,7 +229,7 @@ local function buf_range_get_text(buf, range)
|
||||
end_col = -1
|
||||
end_row = end_row - 1
|
||||
end
|
||||
local lines = a.nvim_buf_get_text(buf, start_row, start_col, end_row, end_col, {})
|
||||
local lines = api.nvim_buf_get_text(buf, start_row, start_col, end_row, end_col, {})
|
||||
return table.concat(lines, '\n')
|
||||
end
|
||||
|
||||
@@ -294,7 +294,7 @@ end
|
||||
---@return table[] List of captures `{ capture = "name", metadata = { ... } }`
|
||||
function M.get_captures_at_pos(bufnr, row, col)
|
||||
if bufnr == 0 then
|
||||
bufnr = a.nvim_get_current_buf()
|
||||
bufnr = api.nvim_get_current_buf()
|
||||
end
|
||||
local buf_highlighter = M.highlighter.active[bufnr]
|
||||
|
||||
@@ -345,8 +345,8 @@ end
|
||||
---@return string[] List of capture names
|
||||
function M.get_captures_at_cursor(winnr)
|
||||
winnr = winnr or 0
|
||||
local bufnr = a.nvim_win_get_buf(winnr)
|
||||
local cursor = a.nvim_win_get_cursor(winnr)
|
||||
local bufnr = api.nvim_win_get_buf(winnr)
|
||||
local cursor = api.nvim_win_get_cursor(winnr)
|
||||
|
||||
local data = M.get_captures_at_pos(bufnr, cursor[1] - 1, cursor[2])
|
||||
|
||||
@@ -374,7 +374,7 @@ function M.get_node(opts)
|
||||
local bufnr = opts.bufnr
|
||||
|
||||
if not bufnr or bufnr == 0 then
|
||||
bufnr = a.nvim_get_current_buf()
|
||||
bufnr = api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
local row, col
|
||||
@@ -383,10 +383,10 @@ function M.get_node(opts)
|
||||
row, col = opts.pos[1], opts.pos[2]
|
||||
else
|
||||
assert(
|
||||
bufnr == a.nvim_get_current_buf(),
|
||||
bufnr == api.nvim_get_current_buf(),
|
||||
'Position must be explicitly provided when not using the current buffer'
|
||||
)
|
||||
local pos = a.nvim_win_get_cursor(0)
|
||||
local pos = api.nvim_win_get_cursor(0)
|
||||
-- Subtract one to account for 1-based row indexing in nvim_win_get_cursor
|
||||
row, col = pos[1] - 1, pos[2]
|
||||
end
|
||||
@@ -417,7 +417,7 @@ end
|
||||
function M.get_node_at_pos(bufnr, row, col, opts)
|
||||
vim.deprecate('vim.treesitter.get_node_at_pos()', 'vim.treesitter.get_node()', '0.10')
|
||||
if bufnr == 0 then
|
||||
bufnr = a.nvim_get_current_buf()
|
||||
bufnr = api.nvim_get_current_buf()
|
||||
end
|
||||
local ts_range = { row, col, row, col }
|
||||
|
||||
@@ -440,7 +440,7 @@ end
|
||||
function M.get_node_at_cursor(winnr)
|
||||
vim.deprecate('vim.treesitter.get_node_at_cursor()', 'vim.treesitter.get_node():type()', '0.10')
|
||||
winnr = winnr or 0
|
||||
local bufnr = a.nvim_win_get_buf(winnr)
|
||||
local bufnr = api.nvim_win_get_buf(winnr)
|
||||
|
||||
return M.get_node({ bufnr = bufnr, ignore_injections = false }):type()
|
||||
end
|
||||
@@ -465,7 +465,7 @@ end
|
||||
---@param bufnr (integer|nil) Buffer to be highlighted (default: current buffer)
|
||||
---@param lang (string|nil) Language of the parser (default: buffer filetype)
|
||||
function M.start(bufnr, lang)
|
||||
bufnr = bufnr or a.nvim_get_current_buf()
|
||||
bufnr = bufnr or api.nvim_get_current_buf()
|
||||
local parser = M.get_parser(bufnr, lang)
|
||||
M.highlighter.new(parser)
|
||||
end
|
||||
@@ -474,7 +474,7 @@ end
|
||||
---
|
||||
---@param bufnr (integer|nil) Buffer to stop highlighting (default: current buffer)
|
||||
function M.stop(bufnr)
|
||||
bufnr = bufnr or a.nvim_get_current_buf()
|
||||
bufnr = bufnr or api.nvim_get_current_buf()
|
||||
|
||||
if M.highlighter.active[bufnr] then
|
||||
M.highlighter.active[bufnr]:destroy()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local a = vim.api
|
||||
local api = vim.api
|
||||
local query = vim.treesitter.query
|
||||
|
||||
---@alias TSHlIter fun(): integer, TSNode, TSMetadata
|
||||
@@ -25,7 +25,7 @@ TSHighlighter.active = TSHighlighter.active or {}
|
||||
local TSHighlighterQuery = {}
|
||||
TSHighlighterQuery.__index = TSHighlighterQuery
|
||||
|
||||
local ns = a.nvim_create_namespace('treesitter/highlighter')
|
||||
local ns = api.nvim_create_namespace('treesitter/highlighter')
|
||||
|
||||
---@private
|
||||
function TSHighlighterQuery.new(lang, query_string)
|
||||
@@ -36,7 +36,7 @@ function TSHighlighterQuery.new(lang, query_string)
|
||||
local name = self._query.captures[capture]
|
||||
local id = 0
|
||||
if not vim.startswith(name, '_') then
|
||||
id = a.nvim_get_hl_id_by_name('@' .. name .. '.' .. lang)
|
||||
id = api.nvim_get_hl_id_by_name('@' .. name .. '.' .. lang)
|
||||
end
|
||||
|
||||
rawset(table, capture, id)
|
||||
@@ -121,7 +121,7 @@ function TSHighlighter.new(tree, opts)
|
||||
vim.cmd.runtime({ 'syntax/synload.vim', bang = true })
|
||||
end
|
||||
|
||||
a.nvim_buf_call(self.bufnr, function()
|
||||
api.nvim_buf_call(self.bufnr, function()
|
||||
vim.opt_local.spelloptions:append('noplainbuffer')
|
||||
end)
|
||||
|
||||
@@ -140,7 +140,7 @@ function TSHighlighter:destroy()
|
||||
vim.bo[self.bufnr].spelloptions = self.orig_spelloptions
|
||||
vim.b[self.bufnr].ts_highlight = nil
|
||||
if vim.g.syntax_on == 1 then
|
||||
a.nvim_exec_autocmds('FileType', { group = 'syntaxset', buffer = self.bufnr })
|
||||
api.nvim_exec_autocmds('FileType', { group = 'syntaxset', buffer = self.bufnr })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -168,7 +168,7 @@ end
|
||||
---@param start_row integer
|
||||
---@param new_end integer
|
||||
function TSHighlighter:on_bytes(_, _, start_row, _, _, _, _, _, new_end)
|
||||
a.nvim__buf_redraw_range(self.bufnr, start_row, start_row + new_end + 1)
|
||||
api.nvim__buf_redraw_range(self.bufnr, start_row, start_row + new_end + 1)
|
||||
end
|
||||
|
||||
---@package
|
||||
@@ -180,7 +180,7 @@ end
|
||||
---@param changes integer[][]?
|
||||
function TSHighlighter:on_changedtree(changes)
|
||||
for _, ch in ipairs(changes or {}) do
|
||||
a.nvim__buf_redraw_range(self.bufnr, ch[1], ch[3] + 1)
|
||||
api.nvim__buf_redraw_range(self.bufnr, ch[1], ch[3] + 1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -252,7 +252,7 @@ local function on_line_impl(self, buf, line, is_spell_nav)
|
||||
local spell_pri_offset = capture_name == 'nospell' and 1 or 0
|
||||
|
||||
if hl and end_row >= line and (not is_spell_nav or spell ~= nil) then
|
||||
a.nvim_buf_set_extmark(buf, ns, start_row, start_col, {
|
||||
api.nvim_buf_set_extmark(buf, ns, start_row, start_col, {
|
||||
end_line = end_row,
|
||||
end_col = end_col,
|
||||
hl_group = hl,
|
||||
@@ -323,7 +323,7 @@ function TSHighlighter._on_win(_, _win, buf, _topline)
|
||||
return true
|
||||
end
|
||||
|
||||
a.nvim_set_decoration_provider(ns, {
|
||||
api.nvim_set_decoration_provider(ns, {
|
||||
on_buf = TSHighlighter._on_buf,
|
||||
on_win = TSHighlighter._on_win,
|
||||
on_line = TSHighlighter._on_line,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local a = vim.api
|
||||
local api = vim.api
|
||||
|
||||
---@class TSLanguageModule
|
||||
local M = {}
|
||||
@@ -89,7 +89,7 @@ function M.add(lang, opts)
|
||||
end
|
||||
|
||||
local fname = 'parser/' .. lang .. '.*'
|
||||
local paths = a.nvim_get_runtime_file(fname, false)
|
||||
local paths = api.nvim_get_runtime_file(fname, false)
|
||||
if #paths == 0 then
|
||||
error("no parser for '" .. lang .. "' language, see :help treesitter-parsers")
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
--- a plugin that does any kind of analysis on a tree should use a timer to throttle too frequent
|
||||
--- updates.
|
||||
|
||||
local a = vim.api
|
||||
local api = vim.api
|
||||
local query = require('vim.treesitter.query')
|
||||
local language = require('vim.treesitter.language')
|
||||
local Range = require('vim.treesitter._range')
|
||||
@@ -141,16 +141,16 @@ function LanguageTree:_log(...)
|
||||
local prefix =
|
||||
string.format('%s:%d: [%s:%d] ', info.name, info.currentline, self:lang(), nregions)
|
||||
|
||||
a.nvim_out_write(prefix)
|
||||
api.nvim_out_write(prefix)
|
||||
for _, x in ipairs(args) do
|
||||
if type(x) == 'string' then
|
||||
a.nvim_out_write(x)
|
||||
api.nvim_out_write(x)
|
||||
else
|
||||
a.nvim_out_write(vim.inspect(x, { newline = ' ', indent = '' }))
|
||||
api.nvim_out_write(vim.inspect(x, { newline = ' ', indent = '' }))
|
||||
end
|
||||
a.nvim_out_write(' ')
|
||||
api.nvim_out_write(' ')
|
||||
end
|
||||
a.nvim_out_write('\n')
|
||||
api.nvim_out_write('\n')
|
||||
end
|
||||
|
||||
--- Invalidates this parser and all its children
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local a = vim.api
|
||||
local api = vim.api
|
||||
local language = require('vim.treesitter.language')
|
||||
|
||||
---@class Query
|
||||
@@ -74,7 +74,7 @@ end
|
||||
---@return string[] query_files List of files to load for given query and language
|
||||
function M.get_files(lang, query_name, is_included)
|
||||
local query_path = string.format('queries/%s/%s.scm', lang, query_name)
|
||||
local lang_files = dedupe_files(a.nvim_get_runtime_file(query_path, true))
|
||||
local lang_files = dedupe_files(api.nvim_get_runtime_file(query_path, true))
|
||||
|
||||
if #lang_files == 0 then
|
||||
return {}
|
||||
@@ -635,7 +635,7 @@ end
|
||||
---@return (fun(): integer, TSNode, TSMetadata): capture id, capture node, metadata
|
||||
function Query:iter_captures(node, source, start, stop)
|
||||
if type(source) == 'number' and source == 0 then
|
||||
source = vim.api.nvim_get_current_buf()
|
||||
source = api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
start, stop = value_or_node_range(start, stop, node)
|
||||
@@ -690,7 +690,7 @@ end
|
||||
---@return (fun(): integer, table<integer,TSNode>, table): pattern id, match, metadata
|
||||
function Query:iter_matches(node, source, start, stop)
|
||||
if type(source) == 'number' and source == 0 then
|
||||
source = vim.api.nvim_get_current_buf()
|
||||
source = api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
start, stop = value_or_node_range(start, stop, node)
|
||||
|
||||
Reference in New Issue
Block a user