fix(deprecation): remove use of deprecated API functions (#59)

Removes usage of several deprecated API functions, and changes all uses
of `vim.loop` to `vim.uv`.

Now that 0.10 is released, several functions used here have been
deprecated and show warnings when they're first called.

I've updated:
- `lsp.get_active_clients()` -> `lsp.get_clients()`
- `api.nvim_buf_set_option` -> `api.nvim_set_option_value` with
buf-local scope
- `api.nvim_win_set_option` -> `api.nvim_set_option_value` with
window-local scope
- `vim.tbl_flatten` -> `vim.iter(t):flatten():totable()`
- `vim.loop.*` -> `vim.uv.*`
- `vim.islist or vim.tbl_islist` -> `vim.islist`

---------

Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
Will Hopkins 2024-07-06 14:58:43 -07:00 committed by GitHub
parent 043361fabe
commit 983a93b2b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 30 additions and 22 deletions

View File

@ -98,7 +98,7 @@ function M.get_type(prop)
if vim.tbl_isempty(types) then if vim.tbl_isempty(types) then
types = { "any" } types = { "any" }
end end
return table.concat(vim.tbl_flatten(types), "|") return vim.iter(types):flatten():join("|")
end end
function M.process_object(name, prop) function M.process_object(name, prop)

View File

@ -117,7 +117,7 @@ function M.translate(props, nls_url)
desc = nls[desc:gsub("%%", "")] or desc desc = nls[desc:gsub("%%", "")] or desc
if type(desc) == "table" then if type(desc) == "table" then
local lines = vim.tbl_values(desc) local lines = vim.tbl_values(desc)
lines = vim.tbl_flatten(lines) lines = vim.iter(lines):flatten():totable()
table.sort(lines) table.sort(lines)
desc = table.concat(lines, "\n\n") desc = table.concat(lines, "\n\n")
end end
@ -182,7 +182,7 @@ end
function M.clean() function M.clean()
---@diagnostic disable-next-line: param-type-mismatch ---@diagnostic disable-next-line: param-type-mismatch
for _, f in pairs(vim.fn.expand("schemas/*.json", false, true)) do for _, f in pairs(vim.fn.expand("schemas/*.json", false, true)) do
vim.loop.fs_unlink(f) vim.uv.fs_unlink(f)
end end
end end

View File

@ -65,7 +65,10 @@ function M.setup()
pattern = Util.file_patterns({ autocmd = true }), pattern = Util.file_patterns({ autocmd = true }),
group = group, group = group,
callback = function(event) callback = function(event)
vim.api.nvim_buf_set_option(event.buf, "filetype", "jsonc") vim.api.nvim_set_option_value("filetype", "jsonc", {
buf = event.buf,
scope = "local",
})
end, end,
}) })
else else

View File

@ -67,7 +67,7 @@ end
function M.on_update(fname) function M.on_update(fname)
local is_global = Util.is_global(fname) local is_global = Util.is_global(fname)
local clients = vim.lsp.get_active_clients() local clients = vim.lsp.get_clients()
for _, client in ipairs(clients) do for _, client in ipairs(clients) do
local settings_root = require("neoconf.workspace").find_root({ file = client.config.root_dir }) local settings_root = require("neoconf.workspace").find_root({ file = client.config.root_dir })

View File

@ -1,7 +1,7 @@
local Config = require("neoconf.config") local Config = require("neoconf.config")
local M = {} local M = {}
local uv = vim.uv or vim.loop
M.islist = vim.islist or vim.tbl_islist M.islist = vim.islist or vim.tbl_islist
function M.merge(...) function M.merge(...)
@ -151,7 +151,7 @@ end
function M.fqn(fname) function M.fqn(fname)
fname = vim.fn.fnamemodify(fname, ":p") fname = vim.fn.fnamemodify(fname, ":p")
return vim.loop.fs_realpath(fname) or fname return uv.fs_realpath(fname) or fname
end end
---@param root_dir string ---@param root_dir string
@ -187,7 +187,7 @@ function M.try(fn, msg)
end end
function M.config_path() function M.config_path()
return vim.loop.fs_realpath(vim.fn.stdpath("config")) return uv.fs_realpath(vim.fn.stdpath("config"))
end end
function M.is_nvim_config(path) function M.is_nvim_config(path)
@ -263,12 +263,12 @@ function M.json_format(obj)
end end
function M.mtime(fname) function M.mtime(fname)
local stat = vim.loop.fs_stat(fname) local stat = uv.fs_stat(fname)
return (stat and stat.type) and stat.mtime.sec or 0 return (stat and stat.type) and stat.mtime.sec or 0
end end
function M.exists(fname) function M.exists(fname)
local stat = vim.loop.fs_stat(fname) local stat = uv.fs_stat(fname)
return (stat and stat.type) or false return (stat and stat.type) or false
end end
@ -276,10 +276,13 @@ function M.notify(msg, level)
vim.notify(msg, level, { vim.notify(msg, level, {
title = "settings.nvim", title = "settings.nvim",
on_open = function(win) on_open = function(win)
vim.api.nvim_win_set_option(win, "conceallevel", 3) vim.api.nvim_set_option_value("conceallevel", 3, {
win = win,
scope = "local",
})
local buf = vim.api.nvim_win_get_buf(win) local buf = vim.api.nvim_win_get_buf(win)
vim.api.nvim_buf_set_option(buf, "filetype", "markdown") vim.api.nvim_set_option_value("filetype", "markdown", { buf = buf, scope = "local" })
vim.api.nvim_win_set_option(win, "spell", false) vim.api.nvim_set_option_value("spell", false, { buf = buf, scope = "local" })
end, end,
}) })
end end

View File

@ -28,14 +28,16 @@ function M.show(str)
local win = vim.api.nvim_open_win(buf, true, opts) local win = vim.api.nvim_open_win(buf, true, opts)
vim.api.nvim_buf_set_option(buf, "filetype", "markdown") local buf_scope = { buf = buf, scope = "local" }
vim.api.nvim_buf_set_option(buf, "modifiable", false) vim.api.nvim_set_option_value("filetype", "markdown", buf_scope)
vim.api.nvim_buf_set_option(buf, "buftype", "nofile") vim.api.nvim_set_option_value("buftype", "nofile", buf_scope)
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe") vim.api.nvim_set_option_value("bufhidden", "wipe", buf_scope)
vim.api.nvim_set_option_value("modifiable", false, buf_scope)
vim.api.nvim_win_set_option(win, "conceallevel", 3) local win_scope = { win = win, scope = "local" }
vim.api.nvim_win_set_option(win, "spell", false) vim.api.nvim_set_option_value("conceallevel", 3, win_scope)
vim.api.nvim_win_set_option(win, "wrap", true) vim.api.nvim_set_option_value("spell", false, win_scope)
vim.api.nvim_set_option_value("wrap", true, win_scope)
local function close() local function close()
if vim.api.nvim_buf_is_valid(buf) then if vim.api.nvim_buf_is_valid(buf) then
@ -59,7 +61,7 @@ function M.show_lsp_settings()
local content = { local content = {
"# Lsp Settings\n", "# Lsp Settings\n",
} }
local clients = vim.lsp.get_active_clients({ bufnr = vim.api.nvim_get_current_buf() }) local clients = vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() })
for _, client in ipairs(clients) do for _, client in ipairs(clients) do
table.insert(content, "## " .. client.name .. "\n") table.insert(content, "## " .. client.name .. "\n")

View File

@ -20,7 +20,7 @@ function M.find_root(opts)
-- fallback to lsp root_dir detection if in options -- fallback to lsp root_dir detection if in options
if not root_dir and opts.lsp then if not root_dir and opts.lsp then
for _, client in ipairs(vim.lsp.get_active_clients({ bufnr = buf })) do for _, client in ipairs(vim.lsp.get_clients({ bufnr = buf })) do
root_dir = client.config.root_dir root_dir = client.config.root_dir
break break
end end