Skip to content

Commit

Permalink
Fix deprecation warnings in nvim 0.10 (#170)
Browse files Browse the repository at this point in the history
* fix: vim.lsp.buf_get_clients is deprecated

* fix: vim.loop is deprecated

* fix: vim.api.nvim_buf_get_option is deprecated

* chore: formatting

* doc: add note to readme about backward compatibility
  • Loading branch information
aarondill committed May 23, 2024
1 parent a9baab6 commit ccca333
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ If you need to use Tabnine on Windows and Unix you can change the config as foll
```lua
-- Get platform dependant build script
local function tabnine_build_path()
if vim.loop.os_uname().sysname == "Windows_NT" then
-- Replace vim.uv with vim.loop if using NVIM 0.9.0 or below
if vim.uv.os_uname().sysname == "Windows_NT" then
return "pwsh.exe -file .\\dl_binaries.ps1"
else
return "./dl_binaries.sh"
Expand Down
2 changes: 1 addition & 1 deletion lua/tabnine/binary.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local uv = vim.loop
local uv = vim.uv or vim.loop
local fn = vim.fn
local json = vim.json
local consts = require("tabnine.consts")
Expand Down
2 changes: 1 addition & 1 deletion lua/tabnine/chat/binary.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local uv = vim.loop
local uv = vim.uv or vim.loop
local json = vim.json
local utils = require("tabnine.utils")
local ChatBinary = {}
Expand Down
4 changes: 2 additions & 2 deletions lua/tabnine/chat/codelens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local cancel_lsp_request = nil
local buf_supports_symbols = nil

function M.reload_buf_supports_symbols()
local clients = vim.lsp.buf_get_clients()
local clients = utils.buf_get_clients()

for _, client in ipairs(clients) do
if client.server_capabilities.documentSymbolProvider then
Expand All @@ -29,7 +29,7 @@ end
function M.should_display()
return config.get_config().codelens_enabled
and state.active
and #vim.lsp.buf_get_clients() > 0
and #utils.buf_get_clients() > 0
and not vim.tbl_contains(config.get_config().exclude_filetypes, vim.bo.filetype)
and buf_supports_symbols
end
Expand Down
4 changes: 2 additions & 2 deletions lua/tabnine/chat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ local function register_events(on_init)

chat_binary:register_event("get_basic_context", function(_, answer)
tabnine_binary:request({
FileMetadata = { path = api.nvim_buf_get_option(0, "filetype") },
FileMetadata = { path = vim.bo.filetype },
}, function(metadata)
answer({
fileUri = api.nvim_buf_get_name(0),
language = api.nvim_buf_get_option(0, "filetype"),
language = vim.bo.filetype,
metadata = metadata,
})
end)
Expand Down
2 changes: 1 addition & 1 deletion lua/tabnine/completion.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local M = {}
local api = vim.api
local fn = vim.fn
local uv = vim.loop
local uv = vim.uv or vim.loop
local config = require("tabnine.config")
local consts = require("tabnine.consts")
local state = require("tabnine.state")
Expand Down
2 changes: 1 addition & 1 deletion lua/tabnine/state.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local uv = vim.loop
local uv = vim.uv or vim.loop

return {
requests_counter = 0,
Expand Down
2 changes: 1 addition & 1 deletion lua/tabnine/status.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local uv = vim.loop
local uv = vim.uv or vim.loop
local fn = vim.fn
local utils = require("tabnine.utils")

Expand Down
9 changes: 9 additions & 0 deletions lua/tabnine/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,13 @@ function M.read_lines_start(stream, on_line, on_error)
end)
end

--- A wrapper around vim.lsp.get_clients which support nvim 0.10 and before
---@param bufnr integer?
---@return vim.lsp.Client[]
function M.buf_get_clients(bufnr)
bufnr = bufnr or 0
if vim.lsp.get_clients then return vim.lsp.get_clients({ bufnr = bufnr }) end
return vim.lsp.buf_get_clients(bufnr)
end

return M
4 changes: 2 additions & 2 deletions lua/tabnine/workspace.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local tabnine_binary = require("tabnine.binary")
local uv = vim.loop
local uv = vim.uv or vim.loop
local lsp = vim.lsp
local utils = require("tabnine.utils")

Expand All @@ -12,7 +12,7 @@ function M.setup()
0,
30000,
vim.schedule_wrap(function()
if #vim.lsp.buf_get_clients() > 0 then
if #utils.buf_get_clients() > 0 then
local root_paths = utils.set(lsp.buf.list_workspace_folders())
tabnine_binary:request({ Workspace = { root_paths = root_paths } }, function() end)
end
Expand Down

0 comments on commit ccca333

Please sign in to comment.