diff options
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/doc/api.txt | 18 | ||||
| -rw-r--r-- | runtime/doc/deprecated.txt | 114 | ||||
| -rw-r--r-- | runtime/doc/lua.txt | 9 | ||||
| -rw-r--r-- | runtime/doc/news.txt | 7 | ||||
| -rw-r--r-- | runtime/lua/provider/ruby/health.lua | 3 | ||||
| -rw-r--r-- | runtime/lua/vim/iter.lua | 121 |
6 files changed, 132 insertions, 140 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 13884e865d..2aa147770d 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -1461,24 +1461,6 @@ nvim_strwidth({text}) *nvim_strwidth()* Return: ~ Number of cells -nvim_subscribe({event}) *nvim_subscribe()* - Subscribes to event broadcasts. - - Attributes: ~ - |RPC| only - - Parameters: ~ - • {event} Event type string - -nvim_unsubscribe({event}) *nvim_unsubscribe()* - Unsubscribes to event broadcasts. - - Attributes: ~ - |RPC| only - - Parameters: ~ - • {event} Event type string - nvim__complete_set({index}, {opts}) *nvim__complete_set()* EXPERIMENTAL: this API may change in the future. diff --git a/runtime/doc/deprecated.txt b/runtime/doc/deprecated.txt index 3fc2d872f6..646ba72bd8 100644 --- a/runtime/doc/deprecated.txt +++ b/runtime/doc/deprecated.txt @@ -12,76 +12,82 @@ They should not be used in new scripts, and old scripts should be updated. ============================================================================== Deprecated features -DEPRECATED IN 0.11 *deprecated-0.11* +------------------------------------------------------------------------------ +DEPRECATED IN 0.11 *deprecated-0.11* + +API +- nvim_subscribe() Plugins must maintain their own "multicast" channels list. +- nvim_unsubscribe() Plugins must maintain their own "multicast" channels list. -• N/A -DEPRECATED IN 0.10 *deprecated-0.10* +------------------------------------------------------------------------------ +DEPRECATED IN 0.10 *deprecated-0.10* +API +• *nvim_buf_get_option()* Use |nvim_get_option_value()| instead. +• *nvim_buf_set_option()* Use |nvim_set_option_value()| instead. +• *nvim_call_atomic()* Use |nvim_exec_lua()| instead. +• *nvim_get_option()* Use |nvim_get_option_value()| instead. +• *nvim_set_option()* Use |nvim_set_option_value()| instead. +• *nvim_win_get_option()* Use |nvim_get_option_value()| instead. +• *nvim_win_set_option()* Use |nvim_set_option_value()| instead. + +CHECKHEALTH +• *health#report_error* *vim.health.report_error()* Use |vim.health.error()| instead. +• *health#report_info* *vim.health.report_info()* Use |vim.health.info()| instead. +• *health#report_ok* *vim.health.report_ok()* Use |vim.health.ok()| instead. +• *health#report_start* *vim.health.report_start()* Use |vim.health.start()| instead. +• *health#report_warn* *vim.health.report_warn()* Use |vim.health.warn()| instead. + +DIAGNOSTICS • Configuring |diagnostic-signs| using |:sign-define| or |sign_define()|. Use the "signs" key of |vim.diagnostic.config()| instead. - -• Checkhealth functions: - - *health#report_error* *vim.health.report_error()* Use |vim.health.error()| instead. - - *health#report_info* *vim.health.report_info()* Use |vim.health.info()| instead. - - *health#report_ok* *vim.health.report_ok()* Use |vim.health.ok()| instead. - - *health#report_start* *vim.health.report_start()* Use |vim.health.start()| instead. - - *health#report_warn* *vim.health.report_warn()* Use |vim.health.warn()| instead. - -• |API| functions: - - *nvim_buf_get_option()* Use |nvim_get_option_value()| instead. - - *nvim_buf_set_option()* Use |nvim_set_option_value()| instead. - - *nvim_call_atomic()* Use |nvim_exec_lua()| instead. - - *nvim_get_option()* Use |nvim_get_option_value()| instead. - - *nvim_set_option()* Use |nvim_set_option_value()| instead. - - *nvim_win_get_option()* Use |nvim_get_option_value()| instead. - - *nvim_win_set_option()* Use |nvim_set_option_value()| instead. - • vim.diagnostic functions: - - *vim.diagnostic.disable()* Use |vim.diagnostic.enable()| - - *vim.diagnostic.is_disabled()* Use |vim.diagnostic.is_enabled()| - - Legacy signature: `vim.diagnostic.enable(buf:number, namespace:number)` - -• vim.lsp functions: - - *vim.lsp.util.get_progress_messages()* Use |vim.lsp.status()| instead. - - *vim.lsp.get_active_clients()* Use |vim.lsp.get_clients()| instead. - - *vim.lsp.for_each_buffer_client()* Use |vim.lsp.get_clients()| instead. - - *vim.lsp.util.trim_empty_lines()* Use |vim.split()| with `trimempty` instead. - - *vim.lsp.util.try_trim_markdown_code_blocks()* - - *vim.lsp.util.set_lines()* - - *vim.lsp.util.extract_completion_items()* - - *vim.lsp.util.parse_snippet()* - - *vim.lsp.util.text_document_completion_list_to_complete_items()* - - *vim.lsp.util.lookup_section()* Use |vim.tbl_get()| instead: > + • *vim.diagnostic.disable()* Use |vim.diagnostic.enable()| + • *vim.diagnostic.is_disabled()* Use |vim.diagnostic.is_enabled()| + • Legacy signature: `vim.diagnostic.enable(buf:number, namespace:number)` + +LSP +• *vim.lsp.util.get_progress_messages()* Use |vim.lsp.status()| instead. +• *vim.lsp.get_active_clients()* Use |vim.lsp.get_clients()| instead. +• *vim.lsp.for_each_buffer_client()* Use |vim.lsp.get_clients()| instead. +• *vim.lsp.util.trim_empty_lines()* Use |vim.split()| with `trimempty` instead. +• *vim.lsp.util.try_trim_markdown_code_blocks()* +• *vim.lsp.util.set_lines()* +• *vim.lsp.util.extract_completion_items()* +• *vim.lsp.util.parse_snippet()* +• *vim.lsp.util.text_document_completion_list_to_complete_items()* +• *vim.lsp.util.lookup_section()* Use |vim.tbl_get()| instead: > local keys = vim.split(section, '.', { plain = true }) local vim.tbl_get(table, unpack(keys)) +LUA • *vim.loop* Use |vim.uv| instead. +• *vim.tbl_add_reverse_lookup()* +• *vim.tbl_flatten()* Use |Iter:flatten()| instead. +• *vim.tbl_islist()* Use |vim.islist()| instead. -• vim.treesitter functions: - - *LanguageTree:for_each_child()* Use |LanguageTree:children()| (non-recursive) instead. - +OPTIONS • The "term_background" UI option |ui-ext-options| is deprecated and no longer populated. Background color detection is now performed in Lua by the Nvim core, not the TUI. -• Lua stdlib: - - *vim.tbl_add_reverse_lookup()* - - *vim.tbl_flatten()* Use |Iter:flatten()| instead. - - *vim.tbl_islist()* Use |vim.islist()| instead. - -DEPRECATED IN 0.9 *deprecated-0.9* +TREESITTER +• *LanguageTree:for_each_child()* Use |LanguageTree:children()| (non-recursive) instead. -• vim.treesitter functions - - *vim.treesitter.language.require_language()* Use |vim.treesitter.language.add()| instead. - - *vim.treesitter.get_node_at_pos()* Use |vim.treesitter.get_node()| instead. - - *vim.treesitter.get_node_at_cursor()* Use |vim.treesitter.get_node()| - and |TSNode:type()| instead. -• |API| functions: - - *nvim_get_hl_by_name()* Use |nvim_get_hl()| instead. - - *nvim_get_hl_by_id()* Use |nvim_get_hl()| instead. +------------------------------------------------------------------------------ +DEPRECATED IN 0.9 *deprecated-0.9* +API +- *nvim_get_hl_by_name()* Use |nvim_get_hl()| instead. +- *nvim_get_hl_by_id()* Use |nvim_get_hl()| instead. + +TREESITTER +- *vim.treesitter.language.require_language()* Use |vim.treesitter.language.add()| instead. +- *vim.treesitter.get_node_at_pos()* Use |vim.treesitter.get_node()| instead. +- *vim.treesitter.get_node_at_cursor()* Use |vim.treesitter.get_node()| + and |TSNode:type()| instead. • The following top level Treesitter functions have been moved: - *vim.treesitter.inspect_language()* -> |vim.treesitter.language.inspect()| - *vim.treesitter.get_query_files()* -> |vim.treesitter.query.get_files()| @@ -98,10 +104,12 @@ DEPRECATED IN 0.9 *deprecated-0.9* - *vim.treesitter.query.get_range()* -> |vim.treesitter.get_range()| - *vim.treesitter.query.get_node_text()* -> |vim.treesitter.get_node_text()| -• Lua stdlib: +LUA - *nvim_exec()* Use |nvim_exec2()| instead. - *vim.pretty_print()* Use |vim.print()| instead. + +------------------------------------------------------------------------------ DEPRECATED IN 0.8 OR EARLIER API diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 0be3c24b0a..fccda177d2 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -3830,6 +3830,7 @@ 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 `vim.iter()`: • List tables (arrays, |lua-list|) yield only the value of each element. + • Holes (nil values) are allowed. • Use |Iter:enumerate()| to also pass the index to the next stage. • Or initialize with ipairs(): `vim.iter(ipairs(…))`. • Non-list tables (|lua-dict|) yield both the key and value of each element. @@ -4287,9 +4288,9 @@ Iter:totable() *Iter:totable()* Collect the iterator into a table. The resulting table depends on the initial source in the iterator - pipeline. List-like tables and function iterators will be collected into a - list-like table. If multiple values are returned from the final stage in - the iterator pipeline, each value will be included in a table. + pipeline. Array-like tables and function iterators will be collected into + an array-like table. If multiple values are returned from the final stage + in the iterator pipeline, each value will be included in a table. Examples: >lua vim.iter(string.gmatch('100 20 50', '%d+')):map(tonumber):totable() @@ -4302,7 +4303,7 @@ Iter:totable() *Iter:totable()* -- { { 'a', 1 }, { 'c', 3 } } < - The generated table is a list-like table with consecutive, numeric + The generated table is an array-like table with consecutive, numeric indices. To create a map-like table with arbitrary keys, use |Iter:fold()|. diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index a1859d19cf..0730faa441 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -25,7 +25,12 @@ These changes may require adaptations in your config or plugins. API -• TODO +• `vim.rpcnotify(0)` and `rpcnotify(0)` broadcast to ALL channels. Previously + they would "multicast" only to subscribed channels (controlled by + `nvim_subscribe()`). Plugins and clients that want "multicast" behavior must + now maintain their own list of channels. + • In the future, |vim.rpcnotify()| may accept a list of channels, if there + is demand for this use-case. DEFAULTS diff --git a/runtime/lua/provider/ruby/health.lua b/runtime/lua/provider/ruby/health.lua index 4d859597a4..31c2fe3201 100644 --- a/runtime/lua/provider/ruby/health.lua +++ b/runtime/lua/provider/ruby/health.lua @@ -19,8 +19,7 @@ function M.check() end health.info('Ruby: ' .. health.system({ 'ruby', '-v' })) - local ruby_detect_table = vim.provider.ruby.detect() - local host = ruby_detect_table[1] + local host, _ = vim.provider.ruby.detect() if (not host) or host:find('^%s*$') then health.warn('`neovim-ruby-host` not found.', { 'Run `gem install neovim` to ensure the neovim RubyGem is installed.', diff --git a/runtime/lua/vim/iter.lua b/runtime/lua/vim/iter.lua index 06415773bc..1093759efe 100644 --- a/runtime/lua/vim/iter.lua +++ b/runtime/lua/vim/iter.lua @@ -7,6 +7,7 @@ --- `vim.iter()`: --- --- - List tables (arrays, |lua-list|) yield only the value of each element. +--- - Holes (nil values) are allowed. --- - Use |Iter:enumerate()| to also pass the index to the next stage. --- - Or initialize with ipairs(): `vim.iter(ipairs(…))`. --- - Non-list tables (|lua-dict|) yield both the key and value of each element. @@ -80,13 +81,13 @@ end --- Special case implementations for iterators on list tables. ---@nodoc ----@class ListIter : Iter +---@class ArrayIter : 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 (exclusive) -local ListIter = {} -ListIter.__index = setmetatable(ListIter, Iter) -ListIter.__call = function(self) +local ArrayIter = {} +ArrayIter.__index = setmetatable(ArrayIter, Iter) +ArrayIter.__call = function(self) return self:next() end @@ -110,36 +111,34 @@ end local function sanitize(t) if type(t) == 'table' and getmetatable(t) == packedmt then - -- Remove length tag + -- Remove length tag and metatable t.n = nil + setmetatable(t, nil) end return t end ---- Flattens a single list-like table. Errors if it attempts to flatten a +--- Flattens a single array-like table. Errors if it attempts to flatten a --- dict-like table ----@param v table table which should be flattened +---@param t table table which should be flattened ---@param max_depth number depth to which the table should be flattened ---@param depth number current iteration depth ---@param result table output table that contains flattened result ---@return table|nil flattened table if it can be flattened, otherwise nil -local function flatten(v, max_depth, depth, result) - if depth < max_depth and type(v) == 'table' then - local i = 0 - for _ in pairs(v) do - i = i + 1 - - if v[i] == nil then +local function flatten(t, max_depth, depth, result) + if depth < max_depth and type(t) == 'table' then + for k, v in pairs(t) do + if type(k) ~= 'number' or k <= 0 or math.floor(k) ~= k then -- short-circuit: this is not a list like table return nil end - if flatten(v[i], max_depth, depth + 1, result) == nil then + if flatten(v, max_depth, depth + 1, result) == nil then return nil end end - else - result[#result + 1] = v + elseif t ~= nil then + result[#result + 1] = t end return result @@ -198,7 +197,7 @@ function Iter:filter(f) end ---@private -function ListIter:filter(f) +function ArrayIter:filter(f) local inc = self._head < self._tail and 1 or -1 local n = self._head for i = self._head, self._tail - inc, inc do @@ -233,11 +232,11 @@ end ---@return Iter ---@diagnostic disable-next-line:unused-local function Iter:flatten(depth) -- luacheck: no unused args - error('flatten() requires a list-like table') + error('flatten() requires an array-like table') end ---@private -function ListIter:flatten(depth) +function ArrayIter:flatten(depth) depth = depth or 1 local inc = self._head < self._tail and 1 or -1 local target = {} @@ -247,7 +246,7 @@ function ListIter:flatten(depth) -- exit early if we try to flatten a dict-like table if flattened == nil then - error('flatten() requires a list-like table') + error('flatten() requires an array-like table') end for _, v in pairs(flattened) do @@ -327,7 +326,7 @@ function Iter:map(f) end ---@private -function ListIter:map(f) +function ArrayIter:map(f) local inc = self._head < self._tail and 1 or -1 local n = self._head for i = self._head, self._tail - inc, inc do @@ -360,7 +359,7 @@ function Iter:each(f) end ---@private -function ListIter:each(f) +function ArrayIter:each(f) local inc = self._head < self._tail and 1 or -1 for i = self._head, self._tail - inc, inc do f(unpack(self._table[i])) @@ -371,7 +370,7 @@ end --- Collect the iterator into a table. --- --- The resulting table depends on the initial source in the iterator pipeline. ---- List-like tables and function iterators will be collected into a list-like +--- Array-like tables and function iterators will be collected into an array-like --- table. If multiple values are returned from the final stage in the iterator --- pipeline, each value will be included in a table. --- @@ -388,7 +387,7 @@ end --- -- { { 'a', 1 }, { 'c', 3 } } --- ``` --- ---- The generated table is a list-like table with consecutive, numeric indices. +--- The generated table is an array-like table with consecutive, numeric indices. --- To create a map-like table with arbitrary keys, use |Iter:fold()|. --- --- @@ -408,12 +407,12 @@ function Iter:totable() end ---@private -function ListIter:totable() - if self.next ~= ListIter.next or self._head >= self._tail then +function ArrayIter:totable() + if self.next ~= ArrayIter.next or self._head >= self._tail then return Iter.totable(self) end - local needs_sanitize = getmetatable(self._table[1]) == packedmt + local needs_sanitize = getmetatable(self._table[self._head]) == packedmt -- Reindex and sanitize. local len = self._tail - self._head @@ -493,7 +492,7 @@ function Iter:fold(init, f) end ---@private -function ListIter:fold(init, f) +function ArrayIter:fold(init, f) local acc = init local inc = self._head < self._tail and 1 or -1 for i = self._head, self._tail - inc, inc do @@ -525,7 +524,7 @@ function Iter:next() end ---@private -function ListIter:next() +function ArrayIter:next() if self._head ~= self._tail then local v = self._table[self._head] local inc = self._head < self._tail and 1 or -1 @@ -548,11 +547,11 @@ end --- ---@return Iter function Iter:rev() - error('rev() requires a list-like table') + error('rev() requires an array-like table') end ---@private -function ListIter:rev() +function ArrayIter:rev() local inc = self._head < self._tail and 1 or -1 self._head, self._tail = self._tail - inc, self._head - inc return self @@ -576,11 +575,11 @@ end --- ---@return any function Iter:peek() - error('peek() requires a list-like table') + error('peek() requires an array-like table') end ---@private -function ListIter:peek() +function ArrayIter:peek() if self._head ~= self._tail then return self._table[self._head] end @@ -657,11 +656,11 @@ end ---@return any ---@diagnostic disable-next-line: unused-local function Iter:rfind(f) -- luacheck: no unused args - error('rfind() requires a list-like table') + error('rfind() requires an array-like table') end ---@private -function ListIter:rfind(f) +function ArrayIter:rfind(f) if type(f) ~= 'function' then local val = f f = function(v) @@ -709,10 +708,10 @@ function Iter:take(n) end ---@private -function ListIter:take(n) - local inc = self._head < self._tail and 1 or -1 +function ArrayIter:take(n) + local inc = self._head < self._tail and n or -n local cmp = self._head < self._tail and math.min or math.max - self._tail = cmp(self._tail, self._head + n * inc) + self._tail = cmp(self._tail, self._head + inc) return self end @@ -730,11 +729,11 @@ end --- ---@return any function Iter:pop() - error('pop() requires a list-like table') + error('pop() requires an array-like table') end --- @nodoc -function ListIter:pop() +function ArrayIter:pop() if self._head ~= self._tail then local inc = self._head < self._tail and 1 or -1 self._tail = self._tail - inc @@ -760,11 +759,11 @@ end --- ---@return any function Iter:rpeek() - error('rpeek() requires a list-like table') + error('rpeek() requires an array-like table') end ---@nodoc -function ListIter:rpeek() +function ArrayIter:rpeek() if self._head ~= self._tail then local inc = self._head < self._tail and 1 or -1 return self._table[self._tail - inc] @@ -793,7 +792,7 @@ function Iter:skip(n) end ---@private -function ListIter:skip(n) +function ArrayIter:skip(n) local inc = self._head < self._tail and n or -n self._head = self._head + inc if (inc > 0 and self._head > self._tail) or (inc < 0 and self._head < self._tail) then @@ -818,11 +817,11 @@ end ---@return Iter ---@diagnostic disable-next-line: unused-local function Iter:rskip(n) -- luacheck: no unused args - error('rskip() requires a list-like table') + error('rskip() requires an array-like table') end ---@private -function ListIter:rskip(n) +function ArrayIter:rskip(n) local inc = self._head < self._tail and n or -n self._tail = self._tail - inc if (inc > 0 and self._head > self._tail) or (inc < 0 and self._head < self._tail) then @@ -870,11 +869,11 @@ end ---@return Iter ---@diagnostic disable-next-line: unused-local function Iter:slice(first, last) -- luacheck: no unused args - error('slice() requires a list-like table') + error('slice() requires an array-like table') end ---@private -function ListIter:slice(first, last) +function ArrayIter:slice(first, last) return self:skip(math.max(0, first - 1)):rskip(math.max(0, self._tail - last - 1)) end @@ -955,7 +954,7 @@ function Iter:last() end ---@private -function ListIter:last() +function ArrayIter:last() local inc = self._head < self._tail and 1 or -1 local v = self._table[self._tail - inc] self._head = self._tail @@ -1000,7 +999,7 @@ function Iter:enumerate() end ---@private -function ListIter:enumerate() +function ArrayIter:enumerate() local inc = self._head < self._tail and 1 or -1 for i = self._head, self._tail - inc, inc do local v = self._table[i] @@ -1030,17 +1029,14 @@ function Iter.new(src, ...) local t = {} - -- O(n): scan the source table to decide if it is a list (consecutive integer indices 1…n). - local count = 0 - for _ in pairs(src) do - count = count + 1 - local v = src[count] - if v == nil then + -- O(n): scan the source table to decide if it is an array (only positive integer indices). + for k, v in pairs(src) do + if type(k) ~= 'number' or k <= 0 or math.floor(k) ~= k then return Iter.new(pairs(src)) end - t[count] = v + t[#t + 1] = v end - return ListIter.new(t) + return ArrayIter.new(t) end if type(src) == 'function' then @@ -1068,17 +1064,18 @@ function Iter.new(src, ...) return it end ---- Create a new ListIter +--- Create a new ArrayIter --- ----@param t table List-like table. Caller guarantees that this table is a valid list. +---@param t table Array-like table. Caller guarantees that this table is a valid array. Can have +--- holes (nil values). ---@return Iter ---@private -function ListIter.new(t) +function ArrayIter.new(t) local it = {} it._table = t it._head = 1 it._tail = #t + 1 - setmetatable(it, ListIter) + setmetatable(it, ArrayIter) return it end |