Skip to content

Commit

Permalink
fix: deprecated warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
notomo committed May 20, 2024
1 parent c43d958 commit 82cd463
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lua/typescript-tools/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ end
---@param callback fun(params: table, result: table)|nil
function M.request_diagnostics(callback)
local text_document = vim.lsp.util.make_text_document_params()
local client = vim.lsp.get_active_clients {
local client = utils.get_clients {
name = plugin_config.plugin_name,
bufnr = vim.uri_to_bufnr(text_document.uri),
}
Expand Down Expand Up @@ -212,7 +212,7 @@ end
---
---@param codes integer[]
function M.filter_diagnostics(codes)
vim.tbl_add_reverse_lookup(codes)
utils.add_reverse_lookup(codes)
return function(err, res, ctx, config)
local filtered = {}
for _, diag in ipairs(res.diagnostics) do
Expand Down
3 changes: 2 additions & 1 deletion lua/typescript-tools/protocol/module_mapper.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local c = require "typescript-tools.protocol.constants"
local utils = require "typescript-tools.utils"

local remapped_methods = {
[c.LspMethods.CompletionResolve] = "text_document.completion.resolve",
Expand All @@ -18,7 +19,7 @@ local remapped_methods = {
}

local noop_methods = { c.LspMethods.DidSave }
vim.tbl_add_reverse_lookup(noop_methods)
utils.add_reverse_lookup(noop_methods)

local M = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local stylecheck_diagnostics = {
-- not all code paths return a value
7030,
}
vim.tbl_add_reverse_lookup(stylecheck_diagnostics)
utils.add_reverse_lookup(stylecheck_diagnostics)

--- @param diagnostic table
--- @return DiagnosticSeverity
Expand Down Expand Up @@ -83,7 +83,7 @@ end

--- @return string[]
local function get_attached_buffers()
local client = vim.lsp.get_active_clients({ name = plugin_config.plugin_name })[1]
local client = utils.get_clients({ name = plugin_config.plugin_name })[1]

if client then
local attached_bufs = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ local utils = require "typescript-tools.protocol.utils"

local M = {}

local islist = vim.islist or vim.tbl_islist

---@type TsserverProtocolHandler
function M.handler(request, response, params)
local text_document = params.textDocument
Expand All @@ -18,7 +20,7 @@ function M.handler(request, response, params)
-- tsserver protocol reference:
-- https://github.com/microsoft/TypeScript/blob/503604c884bd0557c851b11b699ef98cdb65b93b/lib/protocol.d.ts#L2584
local body = coroutine.yield()
body = vim.tbl_islist(body) and body or { body }
body = islist(body) and body or { body }

response(vim.tbl_map(function(it)
return utils.convert_tsserver_call_hierarchy_item_to_lsp(it)
Expand Down
17 changes: 15 additions & 2 deletions lua/typescript-tools/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ function M.is_nightly()
return type(v) ~= "boolean" and v ~= nil or v
end

function M.get_clients(filter)
local get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients
return get_clients(filter)
end

---@param bufnr integer
---@return lsp.Client|nil
function M.get_typescript_client(bufnr)
local get_clients = M.is_nightly() and vim.lsp.get_clients or vim.lsp.get_active_clients
local clients = get_clients {
local clients = M.get_clients {
name = plugin_config.plugin_name,
bufnr = bufnr,
}
Expand Down Expand Up @@ -104,4 +108,13 @@ function M.list_contains(list, value)
return false
end

--- @param tbl table
function M.add_reverse_lookup(tbl)
local keys = vim.tbl_keys(tbl)
for _, k in ipairs(keys) do
local v = tbl[k]
tbl[v] = k
end
end

return M
2 changes: 1 addition & 1 deletion tests/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ end
---@param capability string
---@return boolean
function M.supports_capability(capability)
return not not vim.lsp.get_active_clients({
return not not vim.lsp.get_clients({
name = require("typescript-tools.config").plugin_name,
})[1].server_capabilities[capability]
end
Expand Down

0 comments on commit 82cd463

Please sign in to comment.