This commit is contained in:
Justin M. Keyes 2024-09-01 13:01:24 -07:00 committed by GitHub
parent 6913c5e1d9
commit 61e9137394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 91 additions and 83 deletions

View File

@ -4361,6 +4361,7 @@ maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
"lhsrawalt" The {lhs} of the mapping as raw bytes, alternate "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
form, only present when it differs from "lhsraw" form, only present when it differs from "lhsraw"
"rhs" The {rhs} of the mapping as typed. "rhs" The {rhs} of the mapping as typed.
"callback" Lua function, if RHS was defined as such.
"silent" 1 for a |:map-silent| mapping, else 0. "silent" 1 for a |:map-silent| mapping, else 0.
"noremap" 1 if the {rhs} of the mapping is not remappable. "noremap" 1 if the {rhs} of the mapping is not remappable.
"script" 1 if mapping was defined with <script>. "script" 1 if mapping was defined with <script>.

View File

@ -138,15 +138,15 @@ DOCUMENTATION *dev-doc*
- Write docstrings (as opposed to inline comments) with present tense ("Gets"), - Write docstrings (as opposed to inline comments) with present tense ("Gets"),
not imperative ("Get"). This tends to reduce ambiguity and improve clarity not imperative ("Get"). This tends to reduce ambiguity and improve clarity
by describing "What" instead of "How". > by describing "What" instead of "How". >
GOOD: ✅ OK:
/// Gets a highlight definition. /// Gets a highlight definition.
BAD: ❌ NO:
/// Get a highlight definition. /// Get a highlight definition.
- Avoid starting docstrings with "The" or "A" unless needed to avoid - Avoid starting docstrings with "The" or "A" unless needed to avoid
ambiguity. This is a visual aid and reduces noise. > ambiguity. This is a visual aid and reduces noise. >
GOOD: ✅ OK:
/// @param dirname Path fragment before `pend` /// @param dirname Path fragment before `pend`
BAD: ❌ NO:
/// @param dirname The path fragment before `pend` /// @param dirname The path fragment before `pend`
- Vim differences: - Vim differences:
- Do not prefix help tags with "nvim-". Use |vim_diff.txt| to catalog - Do not prefix help tags with "nvim-". Use |vim_diff.txt| to catalog
@ -329,13 +329,20 @@ Where possible, these patterns apply to _both_ Lua and the API:
- When accepting a buffer id, etc., 0 means "current buffer", nil means "all - When accepting a buffer id, etc., 0 means "current buffer", nil means "all
buffers". Likewise for window id, tabpage id, etc. buffers". Likewise for window id, tabpage id, etc.
- Examples: |vim.lsp.codelens.clear()| |vim.diagnostic.enable()| - Examples: |vim.lsp.codelens.clear()| |vim.diagnostic.enable()|
- Any function signature that accepts a callback function should define the - Any function signature that accepts a callback (example: |table.foreach()|)
callback as the LAST parameter, if possible. This improves readability of should place it as the LAST parameter (after opts), if possible (or ALWAYS
calls by placing the less "noisy" arguments near the start. > for "continuation callbacks"—functions called exactly once).
GOOD: - Improves readability by placing the less "noisy" arguments near the start.
filter(table, opts, function() … end) - Consistent with luv.
BAD: - Useful for future async lib which transforms functions of the form
filter(function() … end, table, opts) `function(<args>, cb(<ret)>))` => `function(<args>) -> <ret>`.
- Example: >lua
-- ✅ OK:
filter(…, opts, function() … end)
-- ❌ NO:
filter(function() … end, …, opts)
-- ❌ NO:
filter(…, function() … end, opts)
- "Enable" ("toggle") interface and behavior: - "Enable" ("toggle") interface and behavior:
- `enable(…, nil)` and `enable(…, {buf=nil})` are synonyms and control the - `enable(…, nil)` and `enable(…, {buf=nil})` are synonyms and control the
the "global" enablement of a feature. the "global" enablement of a feature.
@ -566,10 +573,10 @@ a good name: it's idiomatic and unambiguous. If the package is named "neovim",
it confuses users, and complicates documentation and discussions. it confuses users, and complicates documentation and discussions.
Examples of API-client package names: Examples of API-client package names:
- GOOD: nvim-racket - ✅ OK: nvim-racket
- GOOD: pynvim - ✅ OK: pynvim
- BAD: python-client - ❌ NO: python-client
- BAD: neovim_ - ❌ NO: neovim_
API client implementation guidelines ~ API client implementation guidelines ~

View File

@ -7,10 +7,10 @@
Type |gO| to see the table of contents. Type |gO| to see the table of contents.
============================================================================== ==============================================================================
Checkhealth *health* Checkhealth *vim.health* *health*
health.vim is a minimal framework to help users troubleshoot configuration and vim.health is a minimal framework to help users troubleshoot configuration and
any other environment conditions that a plugin might care about. Nvim ships any other environment conditions that a plugin might care about. Nvim ships
with healthchecks for configuration, performance, python support, ruby with healthchecks for configuration, performance, python support, ruby
support, clipboard support, and more. support, clipboard support, and more.
@ -49,7 +49,7 @@ Commands *health-commands*
:checkhealth vim* :checkhealth vim*
< <
Create a healthcheck *health-dev* *vim.health* Create a healthcheck *health-dev*
Healthchecks are functions that check the user environment, configuration, or Healthchecks are functions that check the user environment, configuration, or
any other prerequisites that a plugin cares about. Nvim ships with any other prerequisites that a plugin cares about. Nvim ships with

View File

@ -1639,8 +1639,7 @@ Lua module: vim.lsp.completion *lsp-completion*
Fields: ~ Fields: ~
• {autotrigger}? (`boolean`) Whether to trigger completion • {autotrigger}? (`boolean`) Whether to trigger completion
automatically. Default: false automatically. Default: false
• {convert}? (`fun(item: lsp.CompletionItem): table`) An optional • {convert}? (`fun(item: lsp.CompletionItem): table`) Transforms an
function used to customize the transformation of an
LSP CompletionItem to |complete-items|. LSP CompletionItem to |complete-items|.

View File

@ -352,16 +352,14 @@ Example: >vim
< <
*lua-table-ambiguous* *lua-table-ambiguous*
Lua tables are used as both dictionaries and lists, so it is impossible to Lua tables are used as both dictionaries and lists, so it is impossible to
determine whether empty table is meant to be empty list or empty dictionary. decide whether empty table is a list or a dict. Also Lua does not have integer
Additionally Lua does not have integer numbers. To distinguish between these numbers. To disambiguate these cases, we define:
cases there is the following agreement:
*lua-list* *lua-list*
0. Empty table is empty list. 0. Empty table is a list. Use |vim.empty_dict()| to represent empty dict.
1. Table with N consecutive integer indices starting from 1 and ending with 1. Table with N consecutive (no `nil` values, aka "holes") integer keys 1…N is
N is considered a list. See also |list-iterator|. a list. See also |list-iterator|.
*lua-dict* *lua-dict*
2. Table with string keys, none of which contains NUL byte, is considered to 2. Table with string keys, none of which contains NUL byte, is a dict.
be a dictionary.
3. Table with string keys, at least one of which contains NUL byte, is also 3. Table with string keys, at least one of which contains NUL byte, is also
considered to be a dictionary, but this time it is converted to considered to be a dictionary, but this time it is converted to
a |msgpack-special-map|. a |msgpack-special-map|.
@ -3839,8 +3837,10 @@ argument into an *Iter* object with methods (such as |Iter:filter()| and
chained to create iterator "pipelines": the output of each pipeline stage is chained to create iterator "pipelines": the output of each pipeline stage is
input to the next stage. The first stage depends on the type passed to input to the next stage. The first stage depends on the type passed to
`vim.iter()`: `vim.iter()`:
• List tables (arrays, |lua-list|) yield only the value of each element. • Lists or arrays (|lua-list|) yield only the value of each element.
• Holes (nil values) are allowed. • Holes (nil values) are allowed (but discarded).
• Use pairs() to treat array/list tables as dicts (preserve holes and
non-contiguous integer keys): `vim.iter(pairs(…))`.
• Use |Iter:enumerate()| to also pass the index to the next stage. • Use |Iter:enumerate()| to also pass the index to the next stage.
• Or initialize with ipairs(): `vim.iter(ipairs(…))`. • Or initialize with ipairs(): `vim.iter(ipairs(…))`.
• Non-list tables (|lua-dict|) yield both the key and value of each element. • Non-list tables (|lua-dict|) yield both the key and value of each element.

View File

@ -65,9 +65,8 @@ EVENTS
LSP LSP
• Add convert field in |vim.lsp.completion.BufferOpts| of • |vim.lsp.completion.enable()| gained the `convert` callback which enables
|vim.lsp.completion.enable()| an optional function used to customize the customizing the transformation of an LSP CompletionItem to |complete-items|.
transformation of an Lsp CompletionItem to |complete-items|.
• |vim.lsp.diagnostic.from()| can be used to convert a list of • |vim.lsp.diagnostic.from()| can be used to convert a list of
|vim.Diagnostic| objects into their LSP diagnostic representation. |vim.Diagnostic| objects into their LSP diagnostic representation.

View File

@ -248,8 +248,8 @@ For Windows WSL, try this g:clipboard definition:
\ '*': 'clip.exe', \ '*': 'clip.exe',
\ }, \ },
\ 'paste': { \ 'paste': {
\ '+': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', \ '+': 'powershell.exe -NoLogo -NoProfile -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
\ '*': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', \ '*': 'powershell.exe -NoLogo -NoProfile -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
\ }, \ },
\ 'cache_enabled': 0, \ 'cache_enabled': 0,
\ } \ }

View File

@ -1,17 +1,19 @@
-- Nvim-Lua stdlib: the `vim` module (:help lua-stdlib) -- Nvim-Lua stdlib: the `vim` module (:help lua-stdlib)
-- --
-- Lua code lives in one of three places: -- Lua code lives in one of four places:
-- 1. runtime/lua/vim/ (the runtime): For "nice to have" features, e.g. the -- 1. Plugins! Not everything needs to live on "vim.*". Plugins are the correct model for
-- `inspect` and `lpeg` modules. -- non-essential features which the user may want to disable or replace with a third-party
-- 2. runtime/lua/vim/shared.lua: pure Lua functions which always -- plugin. Examples: "editorconfig", "comment".
-- are available. Used in the test runner, as well as worker threads -- - "opt-out": runtime/plugin/*.lua
-- and processes launched from Nvim. -- - "opt-in": runtime/pack/dist/opt/
-- 3. runtime/lua/vim/_editor.lua: Code which directly interacts with -- 2. runtime/lua/vim/ (the runtime): Lazy-loaded modules. Examples: `inspect`, `lpeg`.
-- the Nvim editor state. Only available in the main thread. -- 3. runtime/lua/vim/shared.lua: pure Lua functions which always are available. Used in the test
-- runner, as well as worker threads and processes launched from Nvim.
-- 4. runtime/lua/vim/_editor.lua: Eager-loaded code which directly interacts with the Nvim
-- editor state. Only available in the main thread.
-- --
-- Guideline: "If in doubt, put it in the runtime". -- The top level "vim.*" namespace is for fundamental Lua and editor features. Use submodules for
-- -- everything else (but avoid excessive "nesting"), or plugins (see above).
-- Most functions should live directly in `vim.`, not in submodules.
-- --
-- Compatibility with Vim's `if_lua` is explicitly a non-goal. -- Compatibility with Vim's `if_lua` is explicitly a non-goal.
-- --
@ -19,9 +21,7 @@
-- - https://github.com/luafun/luafun -- - https://github.com/luafun/luafun
-- - https://github.com/rxi/lume -- - https://github.com/rxi/lume
-- - http://leafo.net/lapis/reference/utilities.html -- - http://leafo.net/lapis/reference/utilities.html
-- - https://github.com/torch/paths
-- - https://github.com/bakpakin/Fennel (pretty print, repl) -- - https://github.com/bakpakin/Fennel (pretty print, repl)
-- - https://github.com/howl-editor/howl/tree/master/lib/howl/util
-- These are for loading runtime modules lazily since they aren't available in -- These are for loading runtime modules lazily since they aren't available in
-- the nvim binary as specified in executor.c -- the nvim binary as specified in executor.c

View File

@ -5262,6 +5262,7 @@ function vim.fn.map(expr1, expr2) end
--- "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate --- "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
--- form, only present when it differs from "lhsraw" --- form, only present when it differs from "lhsraw"
--- "rhs" The {rhs} of the mapping as typed. --- "rhs" The {rhs} of the mapping as typed.
--- "callback" Lua function, if RHS was defined as such.
--- "silent" 1 for a |:map-silent| mapping, else 0. --- "silent" 1 for a |:map-silent| mapping, else 0.
--- "noremap" 1 if the {rhs} of the mapping is not remappable. --- "noremap" 1 if the {rhs} of the mapping is not remappable.
--- "script" 1 if mapping was defined with <script>. --- "script" 1 if mapping was defined with <script>.

View File

@ -1,6 +1,6 @@
--- @brief --- @brief
---<pre>help ---<pre>help
--- health.vim is a minimal framework to help users troubleshoot configuration and --- vim.health is a minimal framework to help users troubleshoot configuration and
--- any other environment conditions that a plugin might care about. Nvim ships --- any other environment conditions that a plugin might care about. Nvim ships
--- with healthchecks for configuration, performance, python support, ruby --- with healthchecks for configuration, performance, python support, ruby
--- support, clipboard support, and more. --- support, clipboard support, and more.
@ -39,7 +39,7 @@
--- :checkhealth vim* --- :checkhealth vim*
--- < --- <
--- ---
--- Create a healthcheck *health-dev* *vim.health* --- Create a healthcheck *health-dev*
--- ---
--- Healthchecks are functions that check the user environment, configuration, or --- Healthchecks are functions that check the user environment, configuration, or
--- any other prerequisites that a plugin cares about. Nvim ships with --- any other prerequisites that a plugin cares about. Nvim ships with

View File

@ -6,8 +6,10 @@
--- of each pipeline stage is input to the next stage. The first stage depends on the type passed to --- of each pipeline stage is input to the next stage. The first stage depends on the type passed to
--- `vim.iter()`: --- `vim.iter()`:
--- ---
--- - List tables (arrays, |lua-list|) yield only the value of each element. --- - Lists or arrays (|lua-list|) yield only the value of each element.
--- - Holes (nil values) are allowed. --- - Holes (nil values) are allowed (but discarded).
--- - Use pairs() to treat array/list tables as dicts (preserve holes and non-contiguous integer
--- keys): `vim.iter(pairs(…))`.
--- - Use |Iter:enumerate()| to also pass the index to the next stage. --- - Use |Iter:enumerate()| to also pass the index to the next stage.
--- - Or initialize with ipairs(): `vim.iter(ipairs(…))`. --- - Or initialize with ipairs(): `vim.iter(ipairs(…))`.
--- - Non-list tables (|lua-dict|) yield both the key and value of each element. --- - Non-list tables (|lua-dict|) yield both the key and value of each element.
@ -1034,7 +1036,7 @@ function Iter.new(src, ...)
if type(k) ~= 'number' or k <= 0 or math.floor(k) ~= k then if type(k) ~= 'number' or k <= 0 or math.floor(k) ~= k then
return Iter.new(pairs(src)) return Iter.new(pairs(src))
end end
t[#t + 1] = v t[#t + 1] = v -- Coerce to list-like table.
end end
return ArrayIter.new(t) return ArrayIter.new(t)
end end

View File

@ -597,7 +597,7 @@ end
--- @class vim.lsp.completion.BufferOpts --- @class vim.lsp.completion.BufferOpts
--- @field autotrigger? boolean Whether to trigger completion automatically. Default: false --- @field autotrigger? boolean Whether to trigger completion automatically. Default: false
--- @field convert? fun(item: lsp.CompletionItem): table An optional function used to customize the transformation of an LSP CompletionItem to |complete-items|. --- @field convert? fun(item: lsp.CompletionItem): table Transforms an LSP CompletionItem to |complete-items|.
---@param client_id integer ---@param client_id integer
---@param bufnr integer ---@param bufnr integer

View File

@ -373,8 +373,8 @@ local config = {
section_fmt = function(_name) section_fmt = function(_name)
return 'Checkhealth' return 'Checkhealth'
end, end,
helptag_fmt = function(name) helptag_fmt = function()
return name:lower() return 'vim.health* *health' -- HACK
end, end,
}, },
} }

View File

@ -6442,6 +6442,7 @@ M.funcs = {
"lhsrawalt" The {lhs} of the mapping as raw bytes, alternate "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
form, only present when it differs from "lhsraw" form, only present when it differs from "lhsraw"
"rhs" The {rhs} of the mapping as typed. "rhs" The {rhs} of the mapping as typed.
"callback" Lua function, if RHS was defined as such.
"silent" 1 for a |:map-silent| mapping, else 0. "silent" 1 for a |:map-silent| mapping, else 0.
"noremap" 1 if the {rhs} of the mapping is not remappable. "noremap" 1 if the {rhs} of the mapping is not remappable.
"script" 1 if mapping was defined with <script>. "script" 1 if mapping was defined with <script>.

View File

@ -1434,9 +1434,9 @@ scripterror:
// On Windows expand "~\" or "~/" prefix in file names to profile directory. // On Windows expand "~\" or "~/" prefix in file names to profile directory.
#ifdef MSWIN #ifdef MSWIN
if (*p == '~' && (p[1] == '\\' || p[1] == '/')) { if (*p == '~' && (p[1] == '\\' || p[1] == '/')) {
size_t size = strlen(os_get_homedir()) + strlen(p); size_t size = strlen(os_homedir()) + strlen(p);
char *tilde_expanded = xmalloc(size); char *tilde_expanded = xmalloc(size);
snprintf(tilde_expanded, size, "%s%s", os_get_homedir(), p + 1); snprintf(tilde_expanded, size, "%s%s", os_homedir(), p + 1);
xfree(p); xfree(p);
p = tilde_expanded; p = tilde_expanded;
} }

View File

@ -395,7 +395,21 @@ void os_get_hostname(char *hostname, size_t size)
#endif #endif
} }
/// To get the "real" home directory: /// The "real" home directory as determined by `init_homedir`.
static char *homedir = NULL;
static char *os_uv_homedir(void);
/// Gets the "real", resolved user home directory as determined by `init_homedir`.
const char *os_homedir(void)
{
if (!homedir) {
emsg("os_homedir failed: homedir not initialized");
return NULL;
}
return homedir;
}
/// Sets `homedir` to the "real", resolved user home directory, as follows:
/// 1. get value of $HOME /// 1. get value of $HOME
/// 2. if $HOME is not set, try the following /// 2. if $HOME is not set, try the following
/// For Windows: /// For Windows:
@ -409,20 +423,6 @@ void os_get_hostname(char *hostname, size_t size)
/// This also works with mounts and links. /// This also works with mounts and links.
/// Don't do this for Windows, it will change the "current dir" for a drive. /// Don't do this for Windows, it will change the "current dir" for a drive.
/// 3. fall back to current working directory as a last resort /// 3. fall back to current working directory as a last resort
static char *homedir = NULL;
static char *os_uv_homedir(void);
/// Public accessor for the cached "real", resolved user home directory. See
/// comment on `homedir`.
const char *os_get_homedir(void)
{
if (!homedir) {
emsg("os_get_homedir failed: homedir not initialized");
return NULL;
}
return homedir;
}
void init_homedir(void) void init_homedir(void)
{ {
// In case we are called a second time. // In case we are called a second time.

View File

@ -514,7 +514,7 @@ static void process_ctrl_c(void)
size_t available = input_available(); size_t available = input_available();
ssize_t i; ssize_t i;
for (i = (ssize_t)available - 1; i >= 0; i--) { for (i = (ssize_t)available - 1; i >= 0; i--) { // Reverse-search input for Ctrl_C.
uint8_t c = (uint8_t)input_read_pos[i]; uint8_t c = (uint8_t)input_read_pos[i];
if (c == Ctrl_C if (c == Ctrl_C
|| (c == 'C' && i >= 3 || (c == 'C' && i >= 3

View File

@ -145,10 +145,9 @@ describe('lua stdlib', function()
-- "0.10" or "0.10-dev+xxx" -- "0.10" or "0.10-dev+xxx"
local curstr = ('%s.%s%s'):format(curver.major, curver.minor, prerel or '') local curstr = ('%s.%s%s'):format(curver.major, curver.minor, prerel or '')
eq( eq(
dedent( ([[foo.bar() is deprecated. Run ":checkhealth vim.deprecated" for more information]]):format(
[[ curstr
foo.bar() is deprecated. Run ":checkhealth vim.deprecated" for more information]] ),
):format(curstr),
exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', curstr) exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', curstr)
) )
-- Same message as above; skipped this time. -- Same message as above; skipped this time.
@ -178,8 +177,7 @@ describe('lua stdlib', function()
it('plugin=nil, to be deleted in the next major version (1.0)', function() it('plugin=nil, to be deleted in the next major version (1.0)', function()
eq( eq(
dedent [[ [[foo.baz() is deprecated. Run ":checkhealth vim.deprecated" for more information]],
foo.baz() is deprecated. Run ":checkhealth vim.deprecated" for more information]],
exec_lua [[ return vim.deprecate('foo.baz()', nil, '1.0') ]] exec_lua [[ return vim.deprecate('foo.baz()', nil, '1.0') ]]
) )
end) end)

View File

@ -724,7 +724,7 @@ describe('vim.lsp.completion: protocol', function()
end) end)
end) end)
it('custom word/abbar format', function() it('enable(…,{convert=fn}) custom word/abbr format', function()
create_server({ create_server({
isIncomplete = false, isIncomplete = false,
items = { items = {