diff options
| author | srdusr <trevorgray@srdusr.com> | 2025-09-24 04:19:28 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2025-09-24 04:19:28 +0200 |
| commit | 7ed2303648bf83bb081d9bd863660ebf2344ce47 (patch) | |
| tree | 702f5f832796b572d0faee31c0eb15507e91f49a /lua/setup/compat.lua | |
| parent | 2a8020a2e9b7ef2ee77ddee14892127a4eb95187 (diff) | |
| download | dotfiles-7ed2303648bf83bb081d9bd863660ebf2344ce47.tar.gz dotfiles-7ed2303648bf83bb081d9bd863660ebf2344ce47.zip | |
Squashed 'common/config/nvim/' changes from 2a8020a..966d12a
966d12a Update/Overhaul
git-subtree-dir: common/config/nvim
git-subtree-split: 966d12ac730c83da90d60ab24eae539b2ea69441
Diffstat (limited to 'lua/setup/compat.lua')
| -rwxr-xr-x | lua/setup/compat.lua | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/lua/setup/compat.lua b/lua/setup/compat.lua new file mode 100755 index 0000000..ef90444 --- /dev/null +++ b/lua/setup/compat.lua @@ -0,0 +1,104 @@ +-- setup/compat.lua +-- Automatically patches deprecated APIs based on Neovim version + +-- Version check helper +local function has_version(major, minor, patch) + local v = vim.version() + patch = patch or 0 + return v.major > major + or (v.major == major and v.minor > minor) + or (v.major == major and v.minor == minor and v.patch >= patch) +end + +-- === GLOBAL PATCHES === -- + +-- Neovim 0.10+: vim.islist replaces deprecated vim.tbl_islist +if has_version(0, 10) then + if vim.tbl_islist == nil then + vim.tbl_islist = vim.islist + end +end + +-- Neovim 0.12+: vim.tbl_flatten removed → shim using vim.iter +if has_version(0, 12) then + vim.tbl_flatten = function(t) + return vim.iter(t):flatten():totable() + end +end + +-- === DEPRECATION SHIMS (0.13 / 1.0) === -- + +-- client.is_stopped → client:is_stopped() +if has_version(0, 13) then + local mt = getmetatable(vim.lsp._client or {}) + if mt and mt.__index and mt.__index.is_stopped then + mt.__index.is_stopped = function(client, ...) + return client:is_stopped(...) + end + end +end + +-- client.request → client:request() +if has_version(0, 13) then + local mt = getmetatable(vim.lsp._client or {}) + if mt and mt.__index and mt.__index.request then + mt.__index.request = function(client, ...) + return client:request(...) + end + end +end + +-- vim.validate{tbl} → vim.validate(tbl) +if has_version(1, 0) then + if type(vim.validate) == "function" then + local old_validate = vim.validate + vim.validate = function(arg) + -- Handle both forms for backward compatibility + if type(arg) == "table" then + return old_validate(arg) + else + return old_validate{ arg } + end + end + end +end + +-- Deprecated: vim.lsp.get_active_clients (moved in 0.11+) +if has_version(0, 11) then + if vim.lsp.get_active_clients == nil then + vim.lsp.get_active_clients = function(...) + return vim.lsp.get_clients(...) + end + end +end + +-- Deprecated: vim.diagnostic.setqflist / setloclist (moved in 0.11+) +if has_version(0, 11) then + if vim.diagnostic.setqflist == nil then + vim.diagnostic.setqflist = function(diags, opts) + return vim.diagnostic.toqflist(diags, opts) + end + end + if vim.diagnostic.setloclist == nil then + vim.diagnostic.setloclist = function(diags, opts) + return vim.diagnostic.toloclist(diags, opts) + end + end +end + +-- Deprecated: vim.lsp.buf.formatting/formatting_sync (removed in 0.8+) +if has_version(0, 8) then + if vim.lsp.buf.formatting == nil then + vim.lsp.buf.formatting = function(opts) + return vim.lsp.buf.format(opts) + end + end + if vim.lsp.buf.formatting_sync == nil then + vim.lsp.buf.formatting_sync = function(opts, timeout_ms) + return vim.lsp.buf.format(vim.tbl_extend("force", opts or {}, { timeout_ms = timeout_ms })) + end + end +end + +-- Return something to satisfy require() +return true |
