docs: manpage, keycodes, json

This commit is contained in:
Justin M. Keyes
2025-09-06 13:49:19 -04:00
parent 2f78ff816b
commit db67607201
8 changed files with 123 additions and 89 deletions

View File

@@ -10,7 +10,7 @@ vim.json = {}
--- This module provides encoding and decoding of Lua objects to and
--- from JSON-encoded strings. Supports |vim.NIL| and |vim.empty_dict()|.
--- Decodes (or "unpacks") the JSON-encoded {str} to a Lua object.
--- Decodes (or "unpacks") stringified JSON to a Lua object.
---
--- - Decodes JSON "null" as |vim.NIL| (controllable by {opts}, see below).
--- - Decodes empty object as |vim.empty_dict()|.
@@ -33,7 +33,23 @@ vim.json = {}
---@return any
function vim.json.decode(str, opts) end
--- Encodes (or "packs") Lua object {obj} as JSON in a Lua string.
--- Encodes (or "packs") a Lua object to stringified JSON.
---
--- Example: use the `indent` flag to implement a basic 'formatexpr' for JSON, so you can use |gq|
--- with a motion to format JSON in a buffer. (The motion must operate on a valid JSON object.)
---
--- ```lua
--- function _G.fmt_json()
--- local indent = vim.bo.expandtab and (' '):rep(vim.o.shiftwidth) or '\t'
--- local lines = vim.api.nvim_buf_get_lines(0, vim.v.lnum - 1, vim.v.lnum + vim.v.count - 1, true)
--- local o = vim.json.decode(table.concat(lines, '\n'))
--- local stringified = vim.json.encode(o, { indent = indent })
--- lines = vim.split(stringified, '\n')
--- vim.api.nvim_buf_set_lines(0, vim.v.lnum - 1, vim.v.count, true, lines)
--- end
--- vim.o.formatexpr = 'v:lua.fmt_json()'
--- ```
---
---@param obj any
---@param opts? table<string,any> Options table with keys:
--- - escape_slash: (boolean) (default false) Escape slash

View File

@@ -50,7 +50,7 @@ lsp._resolve_to_request = {
---@param method (vim.lsp.protocol.Method.ClientToServer) name of the method
function lsp._unsupported_method(method)
local msg = string.format(
'method %s is not supported by any of the servers registered for the current buffer',
'vim.lsp: method %q is not supported by any server activated for this buffer',
method
)
log.warn(msg)

View File

@@ -244,20 +244,21 @@ function vim.tbl_values(t)
return values
end
--- Apply a function to all values of a table.
--- Applies function `fn` to all values of table `t`, in `pairs()` iteration order (which is not
--- guaranteed to be stable, even when the data doesn't change).
---
---@generic T
---@param func fun(value: T): any Function
---@param fn fun(value: T): any Function
---@param t table<any, T> Table
---@return table : Table of transformed values
function vim.tbl_map(func, t)
vim.validate('func', func, 'callable')
function vim.tbl_map(fn, t)
vim.validate('fn', fn, 'callable')
vim.validate('t', t, 'table')
--- @cast t table<any,any>
local rettab = {} --- @type table<any,any>
for k, v in pairs(t) do
rettab[k] = func(v)
rettab[k] = fn(v)
end
return rettab
end
@@ -265,17 +266,17 @@ end
--- Filter a table using a predicate function
---
---@generic T
---@param func fun(value: T): boolean (function) Function
---@param fn fun(value: T): boolean (function) Function
---@param t table<any, T> (table) Table
---@return T[] : Table of filtered values
function vim.tbl_filter(func, t)
vim.validate('func', func, 'callable')
function vim.tbl_filter(fn, t)
vim.validate('fn', fn, 'callable')
vim.validate('t', t, 'table')
--- @cast t table<any,any>
local rettab = {} --- @type table<any,any>
for _, entry in pairs(t) do
if func(entry) then
if fn(entry) then
rettab[#rettab + 1] = entry
end
end