aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/api.txt2
-rw-r--r--runtime/doc/builtin.txt4
-rw-r--r--runtime/doc/deprecated.txt1
-rw-r--r--runtime/doc/help.txt2
-rw-r--r--runtime/doc/lua-guide.txt8
-rw-r--r--runtime/doc/lua.txt37
-rw-r--r--runtime/doc/luaref.txt6
-rw-r--r--runtime/doc/luvref.txt6
-rw-r--r--runtime/doc/news.txt18
-rw-r--r--runtime/doc/provider.txt2
-rw-r--r--runtime/doc/repeat.txt5
-rw-r--r--runtime/lua/_vim9script.lua2
-rw-r--r--runtime/lua/man.lua8
-rw-r--r--runtime/lua/nvim/health.lua2
-rw-r--r--runtime/lua/provider/health.lua10
-rw-r--r--runtime/lua/vim/_editor.lua8
-rw-r--r--runtime/lua/vim/_watch.lua6
-rw-r--r--runtime/lua/vim/filetype/options.lua2
-rw-r--r--runtime/lua/vim/fs.lua20
-rw-r--r--runtime/lua/vim/iter.lua39
-rw-r--r--runtime/lua/vim/loader.lua4
-rw-r--r--runtime/lua/vim/lsp.lua6
-rw-r--r--runtime/lua/vim/lsp/health.lua2
-rw-r--r--runtime/lua/vim/lsp/log.lua4
-rw-r--r--runtime/lua/vim/lsp/protocol.lua7
-rw-r--r--runtime/lua/vim/lsp/rpc.lua4
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua2
-rw-r--r--runtime/lua/vim/lsp/util.lua2
-rw-r--r--runtime/lua/vim/secure.lua6
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua4
30 files changed, 139 insertions, 90 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index ed8858820e..83422c9501 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -3242,7 +3242,7 @@ nvim_create_autocmd({event}, {*opts}) *nvim_create_autocmd()*
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
pattern = {"*.c", "*.h"},
callback = function(ev)
- print(string.format('event fired: s', vim.inspect(ev)))
+ print(string.format('event fired: %s', vim.inspect(ev)))
end
})
<
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 7acc764644..27d52b7ac6 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -3927,8 +3927,8 @@ has({feature}) Returns 1 if {feature} is supported, 0 otherwise. The
{feature} argument is a feature name like "nvim-0.2.1" or
"win32", see below. See also |exists()|.
- To get the system name use |vim.loop|.os_uname() in Lua: >
- :lua print(vim.loop.os_uname().sysname)
+ To get the system name use |vim.uv|.os_uname() in Lua: >lua
+ print(vim.uv.os_uname().sysname)
< If the code has a syntax error then Vimscript may skip the
rest of the line. Put |:if| and |:endif| on separate lines to
diff --git a/runtime/doc/deprecated.txt b/runtime/doc/deprecated.txt
index 9d4a7324bf..6494c53059 100644
--- a/runtime/doc/deprecated.txt
+++ b/runtime/doc/deprecated.txt
@@ -144,6 +144,7 @@ TREESITTER FUNCTIONS
LUA
- vim.register_keystroke_callback() Use |vim.on_key()| instead.
- *vim.pretty_print()* Use |vim.print()| instead.
+- *vim.loop* Use |vim.uv| instead.
NORMAL COMMANDS
- *]f* *[f* Same as "gf".
diff --git a/runtime/doc/help.txt b/runtime/doc/help.txt
index a1550d5c8b..aefaa0b7df 100644
--- a/runtime/doc/help.txt
+++ b/runtime/doc/help.txt
@@ -105,7 +105,7 @@ API (EXTENSIBILITY/SCRIPTING/PLUGINS)
|lua-guide| Nvim Lua guide
|lua| Lua API
|luaref| Lua reference manual
-|luvref| Luv (|vim.loop|) reference manual
+|luvref| Luv (|vim.uv|) reference manual
|autocmd| Event handlers
|job-control| Spawn and control multiple processes
|channel| Nvim asynchronous IO
diff --git a/runtime/doc/lua-guide.txt b/runtime/doc/lua-guide.txt
index 94db6aac0a..22f51ce8c7 100644
--- a/runtime/doc/lua-guide.txt
+++ b/runtime/doc/lua-guide.txt
@@ -114,10 +114,10 @@ Let's assume you have the following directory structure:
|-- after/
|-- ftplugin/
|-- lua/
- | |-- myluamodule.lua
- | |-- other_modules/
- | |-- anothermodule.lua
- | |-- init.lua
+ | |-- myluamodule.lua
+ | |-- other_modules/
+ | |-- anothermodule.lua
+ | |-- init.lua
|-- plugin/
|-- syntax/
|-- init.vim
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index ad9cb69ae0..54527c5a50 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -449,29 +449,24 @@ Note that underscore-prefixed functions (e.g. "_os_proc_children") are
internal/private and must not be used by plugins.
------------------------------------------------------------------------------
-VIM.LOOP *lua-loop* *vim.loop*
+VIM.UV *lua-loop* *vim.uv*
-`vim.loop` exposes all features of the Nvim event-loop. This is a low-level
-API that provides functionality for networking, filesystem, and process
-management. Try this command to see available functions: >vim
-
- :lua print(vim.inspect(vim.loop))
-<
-Internally, `vim.loop` wraps the "luv" Lua bindings for the LibUV library;
-see |luv-intro| for a full reference manual.
+`vim.uv` exposes the "luv" Lua bindings for the libUV library that Nvim uses
+for networking, filesystem, and process management, see |luvref.txt|.
+In particular, it allows interacting with the main Nvim |luv-event-loop|.
*E5560* *lua-loop-callbacks*
It is an error to directly invoke `vim.api` functions (except |api-fast|) in
-`vim.loop` callbacks. For example, this is an error: >lua
+`vim.uv` callbacks. For example, this is an error: >lua
- local timer = vim.loop.new_timer()
+ local timer = vim.uv.new_timer()
timer:start(1000, 0, function()
vim.api.nvim_command('echomsg "test"')
end)
<
To avoid the error use |vim.schedule_wrap()| to defer the callback: >lua
- local timer = vim.loop.new_timer()
+ local timer = vim.uv.new_timer()
timer:start(1000, 0, vim.schedule_wrap(function()
vim.api.nvim_command('echomsg "test"')
end))
@@ -484,7 +479,7 @@ Example: repeating timer
2. Execute it with ":luafile %". >lua
-- Create a timer handle (implementation detail: uv_timer_t).
- local timer = vim.loop.new_timer()
+ local timer = vim.uv.new_timer()
local i = 0
-- Waits 1000ms, then repeats every 750ms until timer:close().
timer:start(1000, 750, function()
@@ -504,7 +499,7 @@ Example: File-change detection *watch-file*
5. Observe that the file reloads in Nvim (because on_change() calls
|:checktime|). >lua
- local w = vim.loop.new_fs_event()
+ local w = vim.uv.new_fs_event()
local function on_change(err, fname, status)
-- Do work...
vim.api.nvim_command('checktime')
@@ -528,11 +523,11 @@ Example: TCP echo-server *tcp-server*
4. Connect from any TCP client (e.g. "nc 0.0.0.0 36795"): >lua
local function create_server(host, port, on_connect)
- local server = vim.loop.new_tcp()
+ local server = vim.uv.new_tcp()
server:bind(host, port)
server:listen(128, function(err)
assert(not err, err) -- Check for errors.
- local sock = vim.loop.new_tcp()
+ local sock = vim.uv.new_tcp()
server:accept(sock) -- Accept client connection.
on_connect(sock) -- Start reading messages.
end)
@@ -553,14 +548,14 @@ Example: TCP echo-server *tcp-server*
Multithreading *lua-loop-threading*
Plugins can perform work in separate (os-level) threads using the threading
-APIs in luv, for instance `vim.loop.new_thread`. Note that every thread
+APIs in luv, for instance `vim.uv.new_thread`. Note that every thread
gets its own separate lua interpreter state, with no access to lua globals
in the main thread. Neither can the state of the editor (buffers, windows,
etc) be directly accessed from threads.
A subset of the `vim.*` API is available in threads. This includes:
-- `vim.loop` with a separate event loop per thread.
+- `vim.uv` with a separate event loop per thread.
- `vim.mpack` and `vim.json` (useful for serializing messages between threads)
- `require` in threads can use lua packages from the global |package.path|
- `print()` and `vim.inspect`
@@ -885,7 +880,7 @@ vim.defer_fn({fn}, {timeout}) *vim.defer_fn*
• {timeout} Time in ms to wait before calling {fn}
Returns: ~
- |vim.loop|.new_timer() object
+ |vim.uv|.new_timer() object
vim.wait({time} [, {callback}, {interval}, {fast_only}]) *vim.wait()*
Wait for {time} in milliseconds until {callback} returns `true`.
@@ -2531,7 +2526,7 @@ find({names}, {opts}) *vim.fs.find()*
-- location of Cargo.toml from the current buffer's path
local cargo = vim.fs.find('Cargo.toml', {
upward = true,
- stop = vim.loop.os_homedir(),
+ stop = vim.uv.os_homedir(),
path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)),
})
@@ -3035,7 +3030,7 @@ Iter:find({self}, {f}) *Iter:find()*
Iter:fold({self}, {init}, {f}) *Iter:fold()*
Fold an iterator or table into a single value.
- Examples: >
+ Examples: >lua
-- Create a new table with only even values
local t = { a = 1, b = 2, c = 3, d = 4 }
diff --git a/runtime/doc/luaref.txt b/runtime/doc/luaref.txt
index aafdd5c43e..a01196e538 100644
--- a/runtime/doc/luaref.txt
+++ b/runtime/doc/luaref.txt
@@ -4101,16 +4101,16 @@ string.gsub({s}, {pattern}, {repl} [, {n}]) *string.gsub()*
x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1")
--> x="world hello Lua from"
- x = string.gsub("home = `HOME, user = ` USER", "%$(%w+)", os.getenv)
+ x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv)
--> x="home = /home/roberto, user = roberto"
- x = string.gsub("4+5 = `return 4+5` ", "% `(.-)%` ", function (s)
+ x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s)
return loadstring(s)()
end)
--> x="4+5 = 9"
local t = {name="lua", version="5.1"}
- x = string.gsub(" `name%-` version.tar.gz", "%$(%w+)", t)
+ x = string.gsub("$name%-$version.tar.gz", "%$(%w+)", t)
--> x="lua-5.1.tar.gz"
<
diff --git a/runtime/doc/luvref.txt b/runtime/doc/luvref.txt
index 79dd1248aa..131e7889e4 100644
--- a/runtime/doc/luvref.txt
+++ b/runtime/doc/luvref.txt
@@ -5,8 +5,8 @@
*luvref*
This file documents the Lua bindings for the LibUV library which is used for
-Nvim's event-loop and is accessible from Lua via |vim.loop| (e.g., |uv.version()|
-is exposed as `vim.loop.version()`).
+Nvim's event-loop and is accessible from Lua via |vim.uv| (e.g., |uv.version()|
+is exposed as `vim.uv.version()`).
For information about this manual, see |luv-credits|.
@@ -29,7 +29,7 @@ TCP Echo Server Example ~
Here is a small example showing a TCP echo server:
>lua
- local uv = vim.loop
+ local uv = vim.uv
local server = uv.new_tcp()
server:bind("127.0.0.1", 1337)
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 72eb182fa5..d51227f0c0 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -39,7 +39,18 @@ ADDED FEATURES *news-added*
The following new APIs or features were added.
-• Dynamic registration of LSP capabilities. An implication of this change is that checking a client's `server_capabilities` is no longer a sufficient indicator to see if a server supports a feature. Instead use `client.supports_method(<method>)`. It considers both the dynamic capabilities and static `server_capabilities`.
+• Nvim's LSP client now advertises the general.positionEncodings client
+ capability to indicate to servers that it supports utf-8, utf-16, and utf-32
+ encodings. If the server responds with the positionEncoding capability in
+ its initialization response, Nvim automatically sets the client's
+ `offset_encoding` field.
+
+• Dynamic registration of LSP capabilities. An implication of this change is
+ that checking a client's `server_capabilities` is no longer a sufficient
+ indicator to see if a server supports a feature. Instead use
+ `client.supports_method(<method>)`. It considers both the dynamic
+ capabilities and static `server_capabilities`.
+
• |vim.iter()| provides a generic iterator interface for tables and Lua
iterators |luaref-in|.
@@ -86,6 +97,9 @@ The following changes to existing APIs or features add new behavior.
• |LspRequest| autocmd callbacks now contain additional information about the LSP
request status update that occurred.
+• `:source` without arguments treats a buffer with its 'filetype' set to "lua"
+ as Lua code regardless of its extension.
+
==============================================================================
REMOVED FEATURES *news-removed*
@@ -115,4 +129,6 @@ release.
- |nvim_win_get_option()| Use |nvim_get_option_value()| instead.
- |nvim_win_set_option()| Use |nvim_set_option_value()| instead.
+• `vim.loop` has been renamed to `vim.uv`.
+
vim:tw=78:ts=8:sw=2:et:ft=help:norl:
diff --git a/runtime/doc/provider.txt b/runtime/doc/provider.txt
index 117997cec2..a476a56877 100644
--- a/runtime/doc/provider.txt
+++ b/runtime/doc/provider.txt
@@ -189,8 +189,8 @@ registers. Nvim looks for these clipboard tools, in order of priority:
- pbcopy, pbpaste (macOS)
- wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
- waycopy, waypaste (if $WAYLAND_DISPLAY is set)
- - xclip (if $DISPLAY is set)
- xsel (if $DISPLAY is set)
+ - xclip (if $DISPLAY is set)
- lemonade (for SSH) https://github.com/pocke/lemonade
- doitclient (for SSH) https://www.chiark.greenend.org.uk/~sgtatham/doit/
- win32yank (Windows)
diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt
index b6cb126c3b..071b062957 100644
--- a/runtime/doc/repeat.txt
+++ b/runtime/doc/repeat.txt
@@ -183,7 +183,10 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
*:so* *:source* *load-vim-script*
:[range]so[urce] [file] Runs |Ex| commands or Lua code (".lua" files) from
- [file], or current buffer if no [file].
+ [file].
+ If no [file], the current buffer is used, and it is
+ treated as Lua code if its 'filetype' is "lua" or its
+ file name ends with ".lua".
Triggers the |SourcePre| autocommand.
*:source!*
:[range]so[urce]! {file}
diff --git a/runtime/lua/_vim9script.lua b/runtime/lua/_vim9script.lua
index b983878637..ca0e913d51 100644
--- a/runtime/lua/_vim9script.lua
+++ b/runtime/lua/_vim9script.lua
@@ -513,7 +513,7 @@ vim9['import'] = (function()
imported.absolute = setmetatable({}, {
__index = function(self, name)
- if vim.loop.fs_stat(name) then
+ if vim.uv.fs_stat(name) then
local result = loadfile(name)()
rawset(self, name, result)
diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua
index ac493bdc7f..09265b1999 100644
--- a/runtime/lua/man.lua
+++ b/runtime/lua/man.lua
@@ -21,13 +21,13 @@ end
local function system(cmd_, silent, env)
local stdout_data = {} ---@type string[]
local stderr_data = {} ---@type string[]
- local stdout = assert(vim.loop.new_pipe(false))
- local stderr = assert(vim.loop.new_pipe(false))
+ local stdout = assert(vim.uv.new_pipe(false))
+ local stderr = assert(vim.uv.new_pipe(false))
local done = false
local exit_code ---@type integer?
- -- We use the `env` command here rather than the env option to vim.loop.spawn since spawn will
+ -- We use the `env` command here rather than the env option to vim.uv.spawn since spawn will
-- completely overwrite the environment when we just want to modify the existing one.
--
-- Overwriting mainly causes problems NixOS which relies heavily on a non-standard environment.
@@ -39,7 +39,7 @@ local function system(cmd_, silent, env)
end
local handle
- handle = vim.loop.spawn(cmd[1], {
+ handle = vim.uv.spawn(cmd[1], {
args = vim.list_slice(cmd, 2),
stdio = { nil, stdout, stderr },
}, function(code)
diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua
index 19303d34f9..7ccb082a40 100644
--- a/runtime/lua/nvim/health.lua
+++ b/runtime/lua/nvim/health.lua
@@ -30,7 +30,7 @@ local function check_runtime()
local bad_files_msg = ''
for k, _ in pairs(bad_files) do
local path = ('%s/%s'):format(vim.env.VIMRUNTIME, k)
- if vim.loop.fs_stat(path) then
+ if vim.uv.fs_stat(path) then
bad_files[k] = true
bad_files_msg = ('%s%s\n'):format(bad_files_msg, path)
end
diff --git a/runtime/lua/provider/health.lua b/runtime/lua/provider/health.lua
index 3a60e38fe5..f2c19f53fb 100644
--- a/runtime/lua/provider/health.lua
+++ b/runtime/lua/provider/health.lua
@@ -5,7 +5,7 @@ local ok = vim.health.ok
local info = vim.health.info
local warn = vim.health.warn
local error = vim.health.error
-local iswin = vim.loop.os_uname().sysname == 'Windows_NT'
+local iswin = vim.uv.os_uname().sysname == 'Windows_NT'
local shell_error_code = 0
local function shell_error()
@@ -30,7 +30,7 @@ local function isdir(path)
if not path then
return false
end
- local stat = vim.loop.fs_stat(path)
+ local stat = vim.uv.fs_stat(path)
if not stat then
return false
end
@@ -41,7 +41,7 @@ local function isfile(path)
if not path then
return false
end
- local stat = vim.loop.fs_stat(path)
+ local stat = vim.uv.fs_stat(path)
if not stat then
return false
end
@@ -109,13 +109,13 @@ local function system(cmd, ...)
end
if not is_blank(stdin) then
- vim.cmd([[call jobsend(jobid, stdin)]])
+ vim.api.nvim_chan_send(jobid, stdin)
end
local res = vim.fn.jobwait({ jobid }, 30000)
if res[1] == -1 then
error('Command timed out: ' .. shellify(cmd))
- vim.cmd([[call jobstop(jobid)]])
+ vim.fn.jobstop(jobid)
elseif shell_error() and not ignore_error then
local emsg = 'Command error (job='
.. jobid
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
index b26def5958..7b946a55e4 100644
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -42,6 +42,10 @@ for k, v in pairs({
vim._submodules[k] = v
end
+-- Remove at Nvim 1.0
+---@deprecated
+vim.loop = vim.uv
+
-- There are things which have special rules in vim._init_packages
-- for legacy reasons (uri) or for performance (_inspector).
-- most new things should go into a submodule namespace ( vim.foobar.do_thing() )
@@ -159,7 +163,7 @@ do
--- - 3: ends the paste (exactly once)
---@returns boolean # false if client should cancel the paste.
function vim.paste(lines, phase)
- local now = vim.loop.now()
+ local now = vim.uv.now()
local is_first_chunk = phase < 2
local is_last_chunk = phase == -1 or phase == 3
if is_first_chunk then -- Reset flags.
@@ -483,7 +487,7 @@ end
---@return table timer luv timer object
function vim.defer_fn(fn, timeout)
vim.validate({ fn = { fn, 'c', true } })
- local timer = vim.loop.new_timer()
+ local timer = vim.uv.new_timer()
timer:start(
timeout,
0,
diff --git a/runtime/lua/vim/_watch.lua b/runtime/lua/vim/_watch.lua
index dbffd726a2..3bd8a56f6e 100644
--- a/runtime/lua/vim/_watch.lua
+++ b/runtime/lua/vim/_watch.lua
@@ -46,7 +46,7 @@ function M.watch(path, opts, callback)
path = vim.fs.normalize(path)
local uvflags = opts and opts.uvflags or {}
- local handle, new_err = vim.loop.new_fs_event()
+ local handle, new_err = vim.uv.new_fs_event()
assert(not new_err, new_err)
local _, start_err = handle:start(path, uvflags, function(err, filename, events)
assert(not err, err)
@@ -57,7 +57,7 @@ function M.watch(path, opts, callback)
end
local change_type = events.change and M.FileChangeType.Changed or 0
if events.rename then
- local _, staterr, staterrname = vim.loop.fs_stat(fullpath)
+ local _, staterr, staterrname = vim.uv.fs_stat(fullpath)
if staterrname == 'ENOENT' then
change_type = M.FileChangeType.Deleted
else
@@ -99,7 +99,7 @@ local function poll_internal(path, opts, callback, watches)
}
if not watches.handle then
- local poll, new_err = vim.loop.new_fs_poll()
+ local poll, new_err = vim.uv.new_fs_poll()
assert(not new_err, new_err)
watches.handle = poll
local _, start_err = poll:start(
diff --git a/runtime/lua/vim/filetype/options.lua b/runtime/lua/vim/filetype/options.lua
index a093c249f7..2a28b5a8e3 100644
--- a/runtime/lua/vim/filetype/options.lua
+++ b/runtime/lua/vim/filetype/options.lua
@@ -34,7 +34,7 @@ local ft_option_cache = {} ---@type table<string,table<string,any>>
--- @param path string
--- @return integer
local function hash(path)
- local mtime0 = vim.loop.fs_stat(path).mtime
+ local mtime0 = vim.uv.fs_stat(path).mtime
return mtime0.sec * 1000000000 + mtime0.nsec
end
diff --git a/runtime/lua/vim/fs.lua b/runtime/lua/vim/fs.lua
index 864ba495f1..5e63fb6237 100644
--- a/runtime/lua/vim/fs.lua
+++ b/runtime/lua/vim/fs.lua
@@ -1,6 +1,6 @@
local M = {}
-local iswin = vim.loop.os_uname().sysname == 'Windows_NT'
+local iswin = vim.uv.os_uname().sysname == 'Windows_NT'
--- Iterate over all the parents of the given file or directory.
---
@@ -106,12 +106,12 @@ function M.dir(path, opts)
})
if not opts.depth or opts.depth == 1 then
- local fs = vim.loop.fs_scandir(M.normalize(path))
+ local fs = vim.uv.fs_scandir(M.normalize(path))
return function()
if not fs then
return
end
- return vim.loop.fs_scandir_next(fs)
+ return vim.uv.fs_scandir_next(fs)
end
end
@@ -121,9 +121,9 @@ function M.dir(path, opts)
while #dirs > 0 do
local dir0, level = unpack(table.remove(dirs, 1))
local dir = level == 1 and dir0 or M.joinpath(path, dir0)
- local fs = vim.loop.fs_scandir(M.normalize(dir))
+ local fs = vim.uv.fs_scandir(M.normalize(dir))
while fs do
- local name, t = vim.loop.fs_scandir_next(fs)
+ local name, t = vim.uv.fs_scandir_next(fs)
if not name then
break
end
@@ -158,7 +158,7 @@ end
--- -- location of Cargo.toml from the current buffer's path
--- local cargo = vim.fs.find('Cargo.toml', {
--- upward = true,
---- stop = vim.loop.os_homedir(),
+--- stop = vim.uv.os_homedir(),
--- path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)),
--- })
---
@@ -212,7 +212,7 @@ function M.find(names, opts)
names = type(names) == 'string' and { names } or names
- local path = opts.path or vim.loop.cwd()
+ local path = opts.path or vim.uv.cwd()
local stop = opts.stop
local limit = opts.limit or 1
@@ -244,7 +244,7 @@ function M.find(names, opts)
local t = {}
for _, name in ipairs(names) do
local f = M.joinpath(p, name)
- local stat = vim.loop.fs_stat(f)
+ local stat = vim.uv.fs_stat(f)
if stat and (not opts.type or opts.type == stat.type) then
t[#t + 1] = f
end
@@ -337,7 +337,7 @@ function M.normalize(path, opts)
})
if path:sub(1, 1) == '~' then
- local home = vim.loop.os_homedir() or '~'
+ local home = vim.uv.os_homedir() or '~'
if home:sub(-1) == '\\' or home:sub(-1) == '/' then
home = home:sub(1, -2)
end
@@ -345,7 +345,7 @@ function M.normalize(path, opts)
end
if opts.expand_env == nil or opts.expand_env then
- path = path:gsub('%$([%w_]+)', vim.loop.os_getenv)
+ path = path:gsub('%$([%w_]+)', vim.uv.os_getenv)
end
path = path:gsub('\\', '/'):gsub('/+', '/')
diff --git a/runtime/lua/vim/iter.lua b/runtime/lua/vim/iter.lua
index bda3508262..0e98d0437e 100644
--- a/runtime/lua/vim/iter.lua
+++ b/runtime/lua/vim/iter.lua
@@ -51,6 +51,8 @@
--- In addition to the |vim.iter()| function, the |vim.iter| module provides
--- convenience functions like |vim.iter.filter()| and |vim.iter.totable()|.
+---@class IterMod
+---@operator call:Iter
local M = {}
---@class Iter
@@ -64,7 +66,7 @@ end
---@class ListIter : Iter
---@field _table table Underlying table data
---@field _head number Index to the front of a table iterator
----@field _tail number Index to the end of a table iterator
+---@field _tail number Index to the end of a table iterator (exclusive)
local ListIter = {}
ListIter.__index = setmetatable(ListIter, Iter)
ListIter.__call = function(self)
@@ -319,23 +321,39 @@ end
---@private
function ListIter.totable(self)
- if self._head == 1 and self._tail == #self._table + 1 and self.next == ListIter.next then
- -- Sanitize packed table values
- if getmetatable(self._table[1]) == packedmt then
- for i = 1, #self._table do
- self._table[i] = sanitize(self._table[i])
- end
+ if self.next ~= ListIter.next or self._head >= self._tail then
+ return Iter.totable(self)
+ end
+
+ local needs_sanitize = getmetatable(self._table[1]) == packedmt
+
+ -- Reindex and sanitize.
+ local len = self._tail - self._head
+
+ if needs_sanitize then
+ for i = 1, len do
+ self._table[i] = sanitize(self._table[self._head - 1 + i])
end
- return self._table
+ else
+ for i = 1, len do
+ self._table[i] = self._table[self._head - 1 + i]
+ end
+ end
+
+ for i = len + 1, table.maxn(self._table) do
+ self._table[i] = nil
end
- return Iter.totable(self)
+ self._head = 1
+ self._tail = len + 1
+
+ return self._table
end
--- Fold an iterator or table into a single value.
---
--- Examples:
---- <pre>
+--- <pre>lua
--- -- Create a new table with only even values
--- local t = { a = 1, b = 2, c = 3, d = 4 }
--- local it = vim.iter(t)
@@ -974,6 +992,7 @@ function M.map(f, src, ...)
return Iter.new(src, ...):map(f):totable()
end
+---@type IterMod
return setmetatable(M, {
__call = function(_, ...)
return Iter.new(...)
diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua
index 66627fe4e7..9024bdb231 100644
--- a/runtime/lua/vim/loader.lua
+++ b/runtime/lua/vim/loader.lua
@@ -1,4 +1,4 @@
-local uv = vim.loop
+local uv = vim.uv
--- @type (fun(modename: string): fun()|string)[]
local loaders = package.loaders
@@ -465,7 +465,7 @@ end
--- @private
function Loader.track(stat, f)
return function(...)
- local start = vim.loop.hrtime()
+ local start = vim.uv.hrtime()
local r = { f(...) }
Loader._stats[stat] = Loader._stats[stat] or { total = 0, time = 0 }
Loader._stats[stat].total = Loader._stats[stat].total + 1
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index d64ed0b5a3..5f7a95ae14 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -10,7 +10,7 @@ local semantic_tokens = require('vim.lsp.semantic_tokens')
local api = vim.api
local nvim_err_writeln, nvim_buf_get_lines, nvim_command, nvim_exec_autocmds =
api.nvim_err_writeln, api.nvim_buf_get_lines, api.nvim_command, api.nvim_exec_autocmds
-local uv = vim.loop
+local uv = vim.uv
local tbl_isempty, tbl_extend = vim.tbl_isempty, vim.tbl_extend
local validate = vim.validate
local if_nil = vim.F.if_nil
@@ -1344,6 +1344,10 @@ function lsp.start_client(config)
assert(result.capabilities, "initialize result doesn't contain capabilities")
client.server_capabilities = protocol.resolve_capabilities(client.server_capabilities)
+ if client.server_capabilities.positionEncoding then
+ client.offset_encoding = client.server_capabilities.positionEncoding
+ end
+
if next(config.settings) then
client.notify('workspace/didChangeConfiguration', { settings = config.settings })
end
diff --git a/runtime/lua/vim/lsp/health.lua b/runtime/lua/vim/lsp/health.lua
index 6ca468393e..8817bb71de 100644
--- a/runtime/lua/vim/lsp/health.lua
+++ b/runtime/lua/vim/lsp/health.lua
@@ -22,7 +22,7 @@ function M.check()
local log_path = vim.lsp.get_log_path()
report_info(string.format('Log path: %s', log_path))
- local log_file = vim.loop.fs_stat(log_path)
+ local log_file = vim.uv.fs_stat(log_path)
local log_size = log_file and log_file.size or 0
local report_fn = (log_size / 1000000 > 100 and report_warn or report_info)
diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua
index 3d5bc06c3f..07d0500797 100644
--- a/runtime/lua/vim/lsp/log.lua
+++ b/runtime/lua/vim/lsp/log.lua
@@ -31,7 +31,7 @@ do
end
end
- local path_sep = vim.loop.os_uname().version:match('Windows') and '\\' or '/'
+ local path_sep = vim.uv.os_uname().version:match('Windows') and '\\' or '/'
---@private
local function path_join(...)
return table.concat(vim.tbl_flatten({ ... }), path_sep)
@@ -68,7 +68,7 @@ do
return false
end
- local log_info = vim.loop.fs_stat(logfilename)
+ local log_info = vim.uv.fs_stat(logfilename)
if log_info and log_info.size > 1e9 then
local warn_msg = string.format(
'LSP client log is large (%d MB): %s',
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index a28ff407b7..7e49a572e7 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -634,6 +634,13 @@ export interface WorkspaceClientCapabilities {
--- capabilities.
function protocol.make_client_capabilities()
return {
+ general = {
+ positionEncodings = {
+ 'utf-8',
+ 'utf-16',
+ 'utf-32',
+ },
+ },
textDocument = {
semanticTokens = {
dynamicRegistration = false,
diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua
index af3190c9bd..5f48effebf 100644
--- a/runtime/lua/vim/lsp/rpc.lua
+++ b/runtime/lua/vim/lsp/rpc.lua
@@ -1,4 +1,4 @@
-local uv = vim.loop
+local uv = vim.uv
local log = require('vim.lsp.log')
local protocol = require('vim.lsp.protocol')
local validate, schedule, schedule_wrap = vim.validate, vim.schedule, vim.schedule_wrap
@@ -691,7 +691,7 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
})
---@private
- --- Callback for |vim.loop.spawn()| Closes all streams and runs the `on_exit` dispatcher.
+ --- Callback for |vim.uv.spawn()| Closes all streams and runs the `on_exit` dispatcher.
---@param code (integer) Exit code
---@param signal (integer) Signal that was used to terminate (if any)
local function onexit(code, signal)
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua
index 376cac19a7..191cc7b400 100644
--- a/runtime/lua/vim/lsp/semantic_tokens.lua
+++ b/runtime/lua/vim/lsp/semantic_tokens.lua
@@ -2,7 +2,7 @@ local api = vim.api
local bit = require('bit')
local handlers = require('vim.lsp.handlers')
local util = require('vim.lsp.util')
-local uv = vim.loop
+local uv = vim.uv
--- @class STTokenRange
--- @field line integer line number 0-based
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 9fffc845b1..53f8dba814 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -4,7 +4,7 @@ local validate = vim.validate
local api = vim.api
local list_extend = vim.list_extend
local highlight = require('vim.highlight')
-local uv = vim.loop
+local uv = vim.uv
local npcall = vim.F.npcall
local split = vim.split
diff --git a/runtime/lua/vim/secure.lua b/runtime/lua/vim/secure.lua
index 443b152273..1a04e11231 100644
--- a/runtime/lua/vim/secure.lua
+++ b/runtime/lua/vim/secure.lua
@@ -51,7 +51,7 @@ end
--- trusted, or nil otherwise.
function M.read(path)
vim.validate({ path = { path, 's' } })
- local fullpath = vim.loop.fs_realpath(vim.fs.normalize(path))
+ local fullpath = vim.uv.fs_realpath(vim.fs.normalize(path))
if not fullpath then
return nil
end
@@ -149,13 +149,13 @@ function M.trust(opts)
local fullpath
if path then
- fullpath = vim.loop.fs_realpath(vim.fs.normalize(path))
+ fullpath = vim.uv.fs_realpath(vim.fs.normalize(path))
elseif bufnr then
local bufname = vim.api.nvim_buf_get_name(bufnr)
if bufname == '' then
return false, 'buffer is not associated with a file'
end
- fullpath = vim.loop.fs_realpath(vim.fs.normalize(bufname))
+ fullpath = vim.uv.fs_realpath(vim.fs.normalize(bufname))
else
error('one of "path" or "bufnr" is required')
end
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index 244d88f3e0..cabfa8ccc0 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -170,11 +170,11 @@ end
---@param f fun(): R1, R2, R2
---@return integer, R1, R2, R3
local function tcall(f, ...)
- local start = vim.loop.hrtime()
+ local start = vim.uv.hrtime()
---@diagnostic disable-next-line
local r = { f(...) }
--- @type number
- local duration = (vim.loop.hrtime() - start) / 1000000
+ local duration = (vim.uv.hrtime() - start) / 1000000
return duration, unpack(r)
end