build(lint): allow "bufnr" as positional param #39515

Allow `bufnr` as a positional param name because it is very common.
However as a field name, or part of a function name, it is usually
a mistake.
This commit is contained in:
Justin M. Keyes
2026-04-30 07:12:35 -04:00
committed by GitHub
parent 1e7edb2c52
commit 6195624a3f
17 changed files with 213 additions and 322 deletions

View File

@@ -1669,14 +1669,14 @@ function vim._with(context, f)
return vim._with_c(context, callback)
end
--- @param bufnr? integer
--- @param buf? integer
--- @return integer
function vim._resolve_bufnr(bufnr)
if bufnr == nil or bufnr == 0 then
function vim._resolve_bufnr(buf)
if buf == nil or buf == 0 then
return vim.api.nvim_get_current_buf()
end
vim.validate('bufnr', bufnr, 'number')
return bufnr
vim.validate('buf', buf, 'number')
return buf
end
--- @generic T

View File

@@ -30,7 +30,7 @@ local defaults = {
---Can also be pretty-printed with `:Inspect!`. [:Inspect!]()
---
---@since 11
---@param bufnr? integer defaults to the current buffer
---@param buf? integer defaults to the current buffer
---@param row? integer row to inspect, 0-based. Defaults to the row of the current cursor
---@param col? integer col to inspect, 0-based. Defaults to the col of the current cursor
---@param filter? vim._inspector.Filter Table with key-value pairs to filter the items
@@ -42,27 +42,27 @@ local defaults = {
--- - buffer: the buffer used to get the items
--- - row: the row used to get the items
--- - col: the col used to get the items
function vim.inspect_pos(bufnr, row, col, filter)
function vim.inspect_pos(buf, row, col, filter)
filter = vim.tbl_deep_extend('force', defaults, filter or {})
bufnr = bufnr or 0
buf = buf or 0
if row == nil or col == nil then
-- get the row/col from the first window displaying the buffer
local win = bufnr == 0 and vim.api.nvim_get_current_win() or vim.fn.bufwinid(bufnr)
local win = buf == 0 and vim.api.nvim_get_current_win() or vim.fn.bufwinid(buf)
if win == -1 then
error('row/col is required for buffers not visible in a window')
end
local cursor = vim.api.nvim_win_get_cursor(win)
row, col = cursor[1] - 1, cursor[2]
end
bufnr = vim._resolve_bufnr(bufnr)
buf = vim._resolve_bufnr(buf)
local results = {
treesitter = {}, --- @type table[]
syntax = {}, --- @type table[]
extmarks = {},
semantic_tokens = {},
buffer = bufnr,
buffer = buf,
row = row,
col = col,
}
@@ -79,7 +79,7 @@ function vim.inspect_pos(bufnr, row, col, filter)
-- treesitter
if filter.treesitter then
for _, capture in pairs(vim.treesitter.get_captures_at_pos(bufnr, row, col)) do
for _, capture in pairs(vim.treesitter.get_captures_at_pos(buf, row, col)) do
--- @diagnostic disable-next-line: inject-field
capture.hl_group = '@' .. capture.capture .. '.' .. capture.lang
results.treesitter[#results.treesitter + 1] = resolve_hl(capture)
@@ -87,8 +87,8 @@ function vim.inspect_pos(bufnr, row, col, filter)
end
-- syntax
if filter.syntax and vim.api.nvim_buf_is_valid(bufnr) then
vim._with({ buf = bufnr }, function()
if filter.syntax and vim.api.nvim_buf_is_valid(buf) then
vim._with({ buf = buf }, function()
for _, i1 in ipairs(vim.fn.synstack(row + 1, col + 1)) do
results.syntax[#results.syntax + 1] =
resolve_hl({ hl_group = vim.fn.synIDattr(i1, 'name') })
@@ -124,7 +124,7 @@ function vim.inspect_pos(bufnr, row, col, filter)
end
-- All overlapping extmarks at this position:
local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, -1, { row, col }, { row, col }, {
local extmarks = vim.api.nvim_buf_get_extmarks(buf, -1, { row, col }, { row, col }, {
details = true,
overlap = true,
})
@@ -159,12 +159,12 @@ end
---```
---
---@since 11
---@param bufnr? integer defaults to the current buffer
---@param buf? integer defaults to the current buffer
---@param row? integer row to inspect, 0-based. Defaults to the row of the current cursor
---@param col? integer col to inspect, 0-based. Defaults to the col of the current cursor
---@param filter? vim._inspector.Filter
function vim.show_pos(bufnr, row, col, filter)
local items = vim.inspect_pos(bufnr, row, col, filter)
function vim.show_pos(buf, row, col, filter)
local items = vim.inspect_pos(buf, row, col, filter)
local lines = { {} }

View File

@@ -27,13 +27,13 @@ local regex = {} -- luacheck: no unused
--- @return integer? # match end (byte index), or `nil` if no match
function regex:match_str(str) end
--- Matches line at `line_idx` (zero-based) in buffer `bufnr`. Match is restricted to byte index
--- Matches line at `line_idx` (zero-based) in buffer `buf`. Match is restricted to byte index
--- range `start` and `end_` if given, otherwise see |regex:match_str()|. Returned byte indices are
--- relative to `start` if given.
--- @param bufnr integer
--- @param buf integer
--- @param line_idx integer
--- @param start? integer
--- @param end_? integer
--- @return integer? # match start (byte index) relative to `start`, or `nil` if no match
--- @return integer? # match end (byte index) relative to `start`, or `nil` if no match
function regex:match_line(bufnr, line_idx, start, end_) end
function regex:match_line(buf, line_idx, start, end_) end

View File

@@ -446,17 +446,17 @@ end
--- Set diagnostics for the given namespace and buffer.
---
---@param namespace integer The diagnostic namespace
---@param bufnr integer Buffer number
---@param buf integer Buffer number
---@param diagnostics vim.Diagnostic.Set[]
---@param opts? vim.diagnostic.Opts Display options to pass to |vim.diagnostic.show()|
function M.set(namespace, bufnr, diagnostics, opts)
function M.set(namespace, buf, diagnostics, opts)
vim.validate('opts', opts, 'table', true)
M._store.set(namespace, bufnr, diagnostics)
M.show(namespace, bufnr, nil, opts)
M._store.set(namespace, buf, diagnostics)
M.show(namespace, buf, nil, opts)
api.nvim_exec_autocmds('DiagnosticChanged', {
modeline = false,
buf = vim._resolve_bufnr(bufnr),
buf = vim._resolve_bufnr(buf),
-- TODO(lewis6991): should this be deepcopy()'d like they are in vim.diagnostic.get()
data = { diagnostics = diagnostics },
})
@@ -502,24 +502,24 @@ end
--- Modifying diagnostics in the returned table has no effect.
--- To set diagnostics in a buffer, use |vim.diagnostic.set()|.
---
---@param bufnr integer? Buffer number to get diagnostics from. Use 0 for
---@param buf integer? Buffer number to get diagnostics from. Use 0 for
--- current buffer or nil for all buffers.
---@param opts? vim.diagnostic.GetOpts
---@return vim.Diagnostic[] : Fields `bufnr`, `end_lnum`, `end_col`, and `severity`
---@return vim.Diagnostic[] : Fields `buf`, `end_lnum`, `end_col`, and `severity`
--- are guaranteed to be present.
function M.get(bufnr, opts)
return M._store.get(bufnr, opts)
function M.get(buf, opts)
return M._store.get(buf, opts)
end
--- Get current diagnostics count.
---
---@param bufnr? integer Buffer number to get diagnostics from. Use 0 for
---@param buf? integer Buffer number to get diagnostics from. Use 0 for
--- current buffer or nil for all buffers.
---@param opts? vim.diagnostic.GetOpts
---@return table<integer, integer> : Table with actually present severity values as keys
--- (see |diagnostic-severity|) and integer counts as values.
function M.count(bufnr, opts)
return M._store.count(bufnr, opts)
function M.count(buf, opts)
return M._store.count(buf, opts)
end
--- Get the previous diagnostic closest to the cursor position.
@@ -687,10 +687,10 @@ M.handlers.virtual_lines = {
---
---@param namespace integer? Diagnostic namespace. When omitted, hide
--- diagnostics from all namespaces.
---@param bufnr integer? Buffer number, or 0 for current buffer. When
---@param buf integer? Buffer number, or 0 for current buffer. When
--- omitted, hide diagnostics in all buffers.
function M.hide(namespace, bufnr)
return M._display.hide(namespace, bufnr)
function M.hide(namespace, buf)
return M._display.hide(namespace, buf)
end
--- Check whether diagnostics are enabled.
@@ -719,17 +719,17 @@ end
---
---@param namespace integer? Diagnostic namespace. When omitted, show
--- diagnostics from all namespaces.
---@param bufnr integer? Buffer number, or 0 for current buffer. When omitted, show
---@param buf integer? Buffer number, or 0 for current buffer. When omitted, show
--- diagnostics in all buffers.
---@param diagnostics vim.Diagnostic[]? The diagnostics to display. When omitted, use the
--- saved diagnostics for the given namespace and
--- buffer. This can be used to display a list of diagnostics
--- without saving them or to display only a subset of
--- diagnostics. May not be used when {namespace}
--- or {bufnr} is nil.
--- or {buf} is nil.
---@param opts? vim.diagnostic.Opts Display options.
function M.show(namespace, bufnr, diagnostics, opts)
return M._display.show(namespace, bufnr, diagnostics, opts)
function M.show(namespace, buf, diagnostics, opts)
return M._display.show(namespace, buf, diagnostics, opts)
end
--- Show diagnostics in a floating window.
@@ -750,13 +750,13 @@ end
---
---@param namespace integer? Diagnostic namespace. When omitted, remove
--- diagnostics from all namespaces.
---@param bufnr integer? Remove diagnostics for the given buffer. When omitted,
---@param buf integer? Remove diagnostics for the given buffer. When omitted,
--- diagnostics are removed for all buffers.
function M.reset(namespace, bufnr)
function M.reset(namespace, buf)
vim.validate('namespace', namespace, 'number', true)
vim.validate('bufnr', bufnr, 'number', true)
vim.validate('buf', buf, 'number', true)
local buffers = bufnr and { vim._resolve_bufnr(bufnr) } or M._store.get_bufnrs()
local buffers = buf and { vim._resolve_bufnr(buf) } or M._store.get_bufnrs()
for _, iter_bufnr in ipairs(buffers) do
local namespaces = namespace and { namespace } or M._store.get_buf_namespaces(iter_bufnr)
for _, iter_namespace in ipairs(namespaces) do
@@ -1110,17 +1110,17 @@ local default_status_signs = {
---
--- To customise appearance, see |vim.diagnostic.Opts.Status|.
---
---@param bufnr? integer Buffer number to get diagnostics from.
---@param buf? integer Buffer number to get diagnostics from.
--- Defaults to 0 for the current buffer
---
---@return string
function M.status(bufnr)
vim.validate('bufnr', bufnr, 'number', true)
bufnr = bufnr or 0
function M.status(buf)
vim.validate('buf', buf, 'number', true)
buf = buf or 0
local config = assert(vim.diagnostic.config()).status or {} --- @type vim.diagnostic.Opts.Status
vim.validate('config.format', config.format, { 'table', 'function' }, true)
local counts = M.count(bufnr)
local counts = M.count(buf)
local format = config.format or default_status_signs
local result_str --- @type string
if type(format) == 'table' then

View File

@@ -41,34 +41,34 @@ local function starsetf(ft, priority)
end
--- Get a line range from the buffer.
---@param bufnr integer The buffer to get the lines from
---@param buf integer The buffer to get the lines from
---@param start_lnum integer|nil The line number of the first line (inclusive, 1-based)
---@param end_lnum integer|nil The line number of the last line (inclusive, 1-based)
---@return string[] # Array of lines
function M._getlines(bufnr, start_lnum, end_lnum)
if not bufnr or bufnr < 0 then
function M._getlines(buf, start_lnum, end_lnum)
if not buf or buf < 0 then
return {}
end
if start_lnum then
return api.nvim_buf_get_lines(bufnr, start_lnum - 1, end_lnum or start_lnum, false)
return api.nvim_buf_get_lines(buf, start_lnum - 1, end_lnum or start_lnum, false)
end
-- Return all lines
return api.nvim_buf_get_lines(bufnr, 0, -1, false)
return api.nvim_buf_get_lines(buf, 0, -1, false)
end
--- Get a single line from the buffer.
---@param bufnr integer The buffer to get the lines from
---@param buf integer The buffer to get the lines from
---@param start_lnum integer The line number of the first line (inclusive, 1-based)
---@return string
function M._getline(bufnr, start_lnum)
if not bufnr or bufnr < 0 then
function M._getline(buf, start_lnum)
if not buf or buf < 0 then
return ''
end
-- Return a single line
return api.nvim_buf_get_lines(bufnr, start_lnum - 1, start_lnum, false)[1] or ''
return api.nvim_buf_get_lines(buf, start_lnum - 1, start_lnum, false)[1] or ''
end
--- Check whether a string matches any of the given Lua patterns.
@@ -90,12 +90,12 @@ end
--- Get the next non-whitespace line in the buffer.
---
---@param bufnr integer The buffer to get the line from
---@param buf integer The buffer to get the line from
---@param start_lnum integer The line number of the first line to start from (inclusive, 1-based)
---@return string|nil line The first non-blank line if found or `nil` otherwise
---@return integer|nil lnum The line number of the first non-blank line or `nil`
function M._nextnonblank(bufnr, start_lnum)
for off, line in ipairs(M._getlines(bufnr, start_lnum, -1)) do
function M._nextnonblank(buf, start_lnum)
for off, line in ipairs(M._getlines(buf, start_lnum, -1)) do
if not line:find('^%s*$') then
return line, start_lnum + off - 1
end

View File

@@ -38,7 +38,7 @@ M.priorities = {
--- Apply highlight group to range of text.
---
---@param bufnr integer Buffer number to apply highlighting to
---@param buf integer Buffer number to apply highlighting to
---@param ns integer Namespace to add highlight to
---@param higroup string Highlight group to use for highlighting
---@param start [integer,integer]|string Start of region as a (line, column) tuple or string accepted by |getpos()|
@@ -48,7 +48,7 @@ M.priorities = {
--- highlight has left
--- @return fun()? range_clear A function which allows clearing the highlight manually.
--- nil is returned if timeout is not specified
function M.range(bufnr, ns, higroup, start, finish, opts)
function M.range(buf, ns, higroup, start, finish, opts)
opts = opts or {}
local regtype = opts.regtype or 'v'
local inclusive = opts.inclusive or false
@@ -59,20 +59,20 @@ function M.range(bufnr, ns, higroup, start, finish, opts)
local pos1 = type(start) == 'string' and vim.fn.getpos(start)
or {
bufnr,
buf,
start[1] + 1,
start[2] ~= -1 and start[2] ~= v_maxcol and start[2] + 1 or v_maxcol,
0,
}
local pos2 = type(finish) == 'string' and vim.fn.getpos(finish)
or {
bufnr,
buf,
finish[1] + 1,
finish[2] ~= -1 and start[2] ~= v_maxcol and finish[2] + 1 or v_maxcol,
0,
}
local buf_line_count = api.nvim_buf_line_count(bufnr)
local buf_line_count = api.nvim_buf_line_count(buf)
pos1[2] = math.min(pos1[2], buf_line_count)
pos2[2] = math.min(pos2[2], buf_line_count)
@@ -80,7 +80,7 @@ function M.range(bufnr, ns, higroup, start, finish, opts)
return
end
vim._with({ buf = bufnr }, function()
vim._with({ buf = buf }, function()
if pos1[3] ~= v_maxcol then
local max_col1 = vim.fn.col({ pos1[2], '$' })
pos1[3] = math.min(pos1[3], max_col1)
@@ -119,7 +119,7 @@ function M.range(bufnr, ns, higroup, start, finish, opts)
local end_col = res[2][3]
table.insert(
extmarks,
api.nvim_buf_set_extmark(bufnr, ns, start_row, start_col, {
api.nvim_buf_set_extmark(buf, ns, start_row, start_col, {
hl_group = higroup,
end_row = end_row,
end_col = end_col,
@@ -130,11 +130,11 @@ function M.range(bufnr, ns, higroup, start, finish, opts)
end
local range_hl_clear = function()
if not api.nvim_buf_is_valid(bufnr) then
if not api.nvim_buf_is_valid(buf) then
return
end
for _, mark in ipairs(extmarks) do
api.nvim_buf_del_extmark(bufnr, ns, mark)
api.nvim_buf_del_extmark(buf, ns, mark)
end
end

View File

@@ -114,13 +114,13 @@ local Tabstop = {}
---
--- @package
--- @param index integer
--- @param bufnr integer
--- @param buf integer
--- @param placement integer
--- @param range Range4
--- @param choices? string[]
--- @return vim.snippet.Tabstop
function Tabstop.new(index, bufnr, placement, range, choices)
local extmark_id = vim.api.nvim_buf_set_extmark(bufnr, snippet_ns, range[1], range[2], {
function Tabstop.new(index, buf, placement, range, choices)
local extmark_id = vim.api.nvim_buf_set_extmark(buf, snippet_ns, range[1], range[2], {
right_gravity = true,
end_right_gravity = false,
end_line = range[3],
@@ -130,7 +130,7 @@ function Tabstop.new(index, bufnr, placement, range, choices)
local self = setmetatable({
extmark_id = extmark_id,
bufnr = bufnr,
bufnr = buf,
index = index,
placement = placement,
choices = choices,
@@ -216,17 +216,17 @@ local Session = {}
--- Creates a new snippet session in the current buffer.
---
--- @package
--- @param bufnr integer
--- @param buf integer
--- @param snippet_extmark integer
--- @param tabstop_data table<integer, { placement: integer, range: Range4, choices?: string[] }[]>
--- @return vim.snippet.Session
function Session.new(bufnr, snippet_extmark, tabstop_data)
function Session.new(buf, snippet_extmark, tabstop_data)
local self = setmetatable({
bufnr = bufnr,
bufnr = buf,
extmark_id = snippet_extmark,
tabstops = {},
tabstop_placements = {},
current_tabstop = Tabstop.new(0, bufnr, 0, { 0, 0, 0, 0 }),
current_tabstop = Tabstop.new(0, buf, 0, { 0, 0, 0, 0 }),
tab_keymaps = { i = nil, s = nil },
shift_tab_keymaps = { i = nil, s = nil },
}, { __index = Session })

View File

@@ -26,23 +26,23 @@ M.minimum_language_version = vim._ts_get_minimum_language_version()
---
--- It is not recommended to use this; use |get_parser()| instead.
---
---@param bufnr integer Buffer the parser will be tied to (0 for current buffer)
---@param buf integer Buffer the parser will be tied to (0 for current buffer)
---@param lang string Language of the parser
---@param opts (table|nil) Options to pass to the created language tree
---
---@return vim.treesitter.LanguageTree object to use for parsing
function M._create_parser(bufnr, lang, opts)
bufnr = vim._resolve_bufnr(bufnr)
function M._create_parser(buf, lang, opts)
buf = vim._resolve_bufnr(buf)
local self = LanguageTree.new(bufnr, lang, opts)
local self = LanguageTree.new(buf, lang, opts)
local function bytes_cb(_, ...)
self:_on_bytes(...)
end
local function detach_cb(_, ...)
if parsers[bufnr] == self then
parsers[bufnr] = nil
if parsers[buf] == self then
parsers[buf] = nil
end
self:_on_detach(...)
end
@@ -72,41 +72,41 @@ end
---
--- If no parser can be created, nil (and an error message) is returned.
---
---@param bufnr (integer|nil) Buffer the parser should be tied to (default: current buffer)
---@param buf (integer|nil) Buffer the parser should be tied to (default: current buffer)
---@param lang (string|nil) Language of this parser (default: from buffer filetype)
---@param opts (table|nil) Options to pass to the created language tree
---
---@return vim.treesitter.LanguageTree? object to use for parsing
---@return string? error message, if applicable
function M.get_parser(bufnr, lang, opts)
function M.get_parser(buf, lang, opts)
opts = opts or {}
bufnr = vim._resolve_bufnr(bufnr)
buf = vim._resolve_bufnr(buf)
if not valid_lang(lang) then
lang = M.language.get_lang(vim.bo[bufnr].filetype)
lang = M.language.get_lang(vim.bo[buf].filetype)
end
if not valid_lang(lang) then
if not parsers[bufnr] then
if not parsers[buf] then
return nil,
string.format('Parser not found for buffer %s: language could not be determined', bufnr)
string.format('Parser not found for buffer %s: language could not be determined', buf)
end
elseif parsers[bufnr] == nil or parsers[bufnr]:lang() ~= lang then
if not api.nvim_buf_is_loaded(bufnr) then
return nil, string.format('Buffer %s must be loaded to create parser', bufnr)
elseif parsers[buf] == nil or parsers[buf]:lang() ~= lang then
if not api.nvim_buf_is_loaded(buf) then
return nil, string.format('Buffer %s must be loaded to create parser', buf)
end
local parser = vim.F.npcall(M._create_parser, bufnr, lang, opts)
local parser = vim.F.npcall(M._create_parser, buf, lang, opts)
if not parser then
return nil,
string.format('Parser could not be created for buffer %s and language "%s"', bufnr, lang)
string.format('Parser could not be created for buffer %s and language "%s"', buf, lang)
end
parsers[bufnr] = parser
parsers[buf] = parser
end
parsers[bufnr]:register_cbs(opts.buf_attach_cbs)
parsers[buf]:register_cbs(opts.buf_attach_cbs)
return parsers[bufnr]
return parsers[buf]
end
--- Returns a string parser
@@ -268,14 +268,14 @@ end
--- language, a table of metadata (`priority`, `conceal`, ...; empty if none are defined), and the
--- id of the capture.
---
---@param bufnr integer Buffer number (0 for current buffer)
---@param buf integer Buffer number (0 for current buffer)
---@param row integer Position row
---@param col integer Position column
---
---@return {capture: string, lang: string, metadata: vim.treesitter.query.TSMetadata, id: integer}[]
function M.get_captures_at_pos(bufnr, row, col)
bufnr = vim._resolve_bufnr(bufnr)
local buf_highlighter = M.highlighter.active[bufnr]
function M.get_captures_at_pos(buf, row, col)
buf = vim._resolve_bufnr(buf)
local buf_highlighter = M.highlighter.active[buf]
if not buf_highlighter then
return {}
@@ -328,13 +328,13 @@ end
--- Returns a list of highlight capture names under the cursor
---
---@param winnr (integer|nil): |window-ID| or 0 for current window (default)
---@param win (integer|nil): |window-ID| or 0 for current window (default)
---
---@return string[] List of capture names
function M.get_captures_at_cursor(winnr)
winnr = winnr or 0
local bufnr = api.nvim_win_get_buf(winnr)
local cursor = api.nvim_win_get_cursor(winnr)
function M.get_captures_at_cursor(win)
win = win or 0
local bufnr = api.nvim_win_get_buf(win)
local cursor = api.nvim_win_get_cursor(win)
local data = M.get_captures_at_pos(bufnr, cursor[1] - 1, cursor[2])
@@ -434,30 +434,30 @@ end
--- })
--- ```
---
---@param bufnr integer? Buffer to be highlighted (default: current buffer)
---@param buf integer? Buffer to be highlighted (default: current buffer)
---@param lang string? Language of the parser (default: from buffer filetype)
function M.start(bufnr, lang)
bufnr = vim._resolve_bufnr(bufnr)
function M.start(buf, lang)
buf = vim._resolve_bufnr(buf)
-- Ensure buffer is loaded. `:edit` over `bufload()` to show swapfile prompt.
if not api.nvim_buf_is_loaded(bufnr) then
if api.nvim_buf_get_name(bufnr) ~= '' then
pcall(api.nvim_buf_call, bufnr, vim.cmd.edit)
if not api.nvim_buf_is_loaded(buf) then
if api.nvim_buf_get_name(buf) ~= '' then
pcall(api.nvim_buf_call, buf, vim.cmd.edit)
else
vim.fn.bufload(bufnr)
vim.fn.bufload(buf)
end
end
local parser = assert(M.get_parser(bufnr, lang))
local parser = assert(M.get_parser(buf, lang))
M.highlighter.new(parser)
end
--- Stops treesitter highlighting for a buffer
---
---@param bufnr (integer|nil) Buffer to stop highlighting (default: current buffer)
function M.stop(bufnr)
bufnr = vim._resolve_bufnr(bufnr)
---@param buf (integer|nil) Buffer to stop highlighting (default: current buffer)
function M.stop(buf)
buf = vim._resolve_bufnr(buf)
if M.highlighter.active[bufnr] then
M.highlighter.active[bufnr]:destroy()
if M.highlighter.active[buf] then
M.highlighter.active[buf]:destroy()
end
end

View File

@@ -26,12 +26,12 @@ local FoldInfo = {}
FoldInfo.__index = FoldInfo
---@private
---@param bufnr integer
function FoldInfo.new(bufnr)
---@param buf integer
function FoldInfo.new(buf)
return setmetatable({
levels0 = {},
levels = {},
parser = ts.get_parser(bufnr, nil),
parser = ts.get_parser(buf, nil),
}, FoldInfo)
end

View File

@@ -69,24 +69,20 @@ end
--- Create a new treesitter view.
---
---@param bufnr integer Source buffer number
---@param buf integer Source buffer number
---@param lang string|nil Language of source buffer
---
---@return vim.treesitter.dev.TSTreeView|nil
---@return string|nil Error message, if any
---
---@package
function TSTreeView:new(bufnr, lang)
bufnr = bufnr or 0
lang = lang or vim.treesitter.language.get_lang(vim.bo[bufnr].filetype)
local parser = vim.treesitter.get_parser(bufnr, lang)
function TSTreeView:new(buf, lang)
buf = buf or 0
lang = lang or vim.treesitter.language.get_lang(vim.bo[buf].filetype)
local parser = vim.treesitter.get_parser(buf, lang)
if not parser then
return nil,
string.format(
'Failed to create TSTreeView for buffer %s: no parser for lang "%s"',
bufnr,
lang
)
string.format('Failed to create TSTreeView for buffer %s: no parser for lang "%s"', buf, lang)
end
-- For each child tree (injected language), find the root of the tree and locate the node within
@@ -232,10 +228,10 @@ end
---
--- Calling this function computes the text that is displayed for each node.
---
---@param bufnr integer Buffer number to write into.
---@param buf integer Buffer number to write into.
---@package
function TSTreeView:draw(bufnr)
vim.bo[bufnr].modifiable = true
function TSTreeView:draw(buf)
vim.bo[buf].modifiable = true
local lines = {} ---@type string[]
local lang_hl_marks = {} ---@type table[]
@@ -284,18 +280,18 @@ function TSTreeView:draw(bufnr)
lines[i] = line
end
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
api.nvim_buf_set_lines(buf, 0, -1, false, lines)
api.nvim_buf_clear_namespace(bufnr, decor_ns, 0, -1)
api.nvim_buf_clear_namespace(buf, decor_ns, 0, -1)
for i, m in ipairs(lang_hl_marks) do
api.nvim_buf_set_extmark(bufnr, decor_ns, i - 1, m.col, {
api.nvim_buf_set_extmark(buf, decor_ns, i - 1, m.col, {
hl_group = 'Title',
end_col = m.end_col,
})
end
vim.bo[bufnr].modifiable = false
vim.bo[buf].modifiable = false
end
--- Get node {i} from this View.

View File

@@ -1253,7 +1253,7 @@ function LanguageTree:_edit(
end
end
---@param bufnr integer
---@param buf integer
---@param changed_tick integer
---@param start_row integer
---@param start_col integer
@@ -1265,7 +1265,7 @@ end
---@param new_col integer
---@param new_byte integer
function LanguageTree:_on_bytes(
bufnr,
buf,
changed_tick,
start_row,
start_col,
@@ -1282,7 +1282,7 @@ function LanguageTree:_on_bytes(
self:_log(
'on_bytes',
bufnr,
buf,
changed_tick,
start_row,
start_col,
@@ -1310,7 +1310,7 @@ function LanguageTree:_on_bytes(
self:_do_callback(
'bytes',
bufnr,
buf,
changed_tick,
start_row,
start_col,

View File

@@ -77,10 +77,10 @@ function M.uri_from_fname(path)
end
---Gets a URI from a bufnr.
---@param bufnr integer
---@param buf integer
---@return string URI
function M.uri_from_bufnr(bufnr)
local fname = vim.api.nvim_buf_get_name(bufnr)
function M.uri_from_bufnr(buf)
local fname = vim.api.nvim_buf_get_name(buf)
local volume_path = fname:match('^([a-zA-Z]:).*')
local is_windows = volume_path ~= nil
local scheme ---@type string?