Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: luajit
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "luajit-2.1.0-beta3"
luaVersion: "luajit-2.1"

- name: luarocks
uses: leafo/gh-actions-luarocks@v4
Expand Down
4 changes: 2 additions & 2 deletions lua/lspsaga/callhierarchy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ end

function ch:call_hierarchy(item, client, timer_close, curlnum)
self.pending_request = true
client.request(self.method, { item = item }, function(_, res)
util.client_request(client, self.method, { item = item }, function(_, res)
self.pending_request = false
curlnum = curlnum or 0
local inlevel = curlnum == 0 and 2 or fn.indent(curlnum)
Expand Down Expand Up @@ -471,7 +471,7 @@ function ch:send_prepare_call()
self.list = slist.new()

local params = lsp.util.make_position_params(0, util.get_offset_encoding({ client = client }))
client.request(get_method(1), params, function(_, result, ctx)
util.client_request(client, get_method(1), params, function(_, result, ctx)
if api.nvim_get_current_buf() ~= ctx.bufnr then
return
end
Expand Down
8 changes: 4 additions & 4 deletions lua/lspsaga/codeaction/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ local function apply_action(action, client, enriched_ctx)
arguments = command.arguments,
workDoneToken = command.workDoneToken,
}
client.request('workspace/executeCommand', params, nil, enriched_ctx.bufnr)
util.client_request(client, 'workspace/executeCommand', params, nil, enriched_ctx.bufnr)
end
end
clean_ctx()
Expand All @@ -254,7 +254,7 @@ function act:support_resolve(client)
if vim.version().minor >= 10 then
local reg = client.dynamic_capabilities:get('textDocument/codeAction', { bufnr = ctx.bufnr })
return vim.tbl_get(reg or {}, 'registerOptions', 'resolveProvider')
or client.supports_method('codeAction/resolve')
or util.client_supports_method(client, 'codeAction/resolve')
end
return vim.tbl_get(client.server_capabilities, 'codeActionProvider', 'resolveProvider')
end
Expand All @@ -263,12 +263,12 @@ function act:get_resolve_action(client, action, bufnr)
if not self:support_resolve(client) then
return
end
return client.request_sync('codeAction/resolve', action, 1500, bufnr).result
return util.client_request_sync(client, 'codeAction/resolve', action, 1500, bufnr).result
end

function act:do_code_action(action, client, enriched_ctx)
if not action.edit and client and self:support_resolve(client) then
client.request('codeAction/resolve', action, function(err, resolved_action)
util.client_request(client, 'codeAction/resolve', action, function(err, resolved_action)
if err then
vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR)
return
Expand Down
2 changes: 1 addition & 1 deletion lua/lspsaga/codeaction/lightbulb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ local function lb_autocmd()
if not client then
return
end
if not client.supports_method('textDocument/codeAction') then
if not util.client_supports_method(client, 'textDocument/codeAction') then
return
end
if vim.tbl_contains(config.lightbulb.ignore.clients, client.name) then
Expand Down
3 changes: 2 additions & 1 deletion lua/lspsaga/implement/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local api, fn = vim.api, vim.fn
local uv = vim.version().minor >= 10 and vim.uv or vim.loop
local config = require('lspsaga').config.implement
local ui = require('lspsaga').config.ui
local util = require('lspsaga.util')
local ns = api.nvim_create_namespace('SagaImp')
local defined = false
local name = 'SagaImpIcon'
Expand Down Expand Up @@ -37,7 +38,7 @@ local function try_render(client_id, bufnr, pos, data)
return
end
---@diagnostic disable-next-line: invisible
client.request('textDocument/implementation', params, function(err, result)
util.client_request(client, 'textDocument/implementation', params, function(err, result)
if err or api.nvim_get_current_buf() ~= bufnr then
return
end
Expand Down
18 changes: 12 additions & 6 deletions lua/lspsaga/symbol/head.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local api, lsp = vim.api, vim.lsp
local config = require('lspsaga').config
---@diagnostic disable-next-line: deprecated
local uv = vim.version().minor >= 10 and vim.uv or vim.loop
local util = require('lspsaga.util')
local symbol = {}

local cache = {}
Expand Down Expand Up @@ -70,9 +71,11 @@ function symbol:buf_watcher(bufnr, group)
end

function symbol:do_request(buf, client_id)
local params = { textDocument = {
uri = vim.uri_from_bufnr(buf),
} }
local params = {
textDocument = {
uri = vim.uri_from_bufnr(buf),
},
}

local client = vim.lsp.get_client_by_id(client_id)
if not client then
Expand All @@ -86,7 +89,7 @@ function symbol:do_request(buf, client_id)
}
end

client.request('textDocument/documentSymbol', params, function(err, result, ctx)
util.client_request(client, 'textDocument/documentSymbol', params, function(err, result, ctx)
if not api.nvim_buf_is_loaded(ctx.bufnr) or not self[ctx.bufnr] then
return
end
Expand Down Expand Up @@ -170,7 +173,7 @@ function symbol:register_module()
end

local client = lsp.get_client_by_id(args.data.client_id)
if not client or not client.supports_method('textDocument/documentSymbol') then
if not client or not util.client_supports_method(client, 'textDocument/documentSymbol') then
return
end

Expand All @@ -183,7 +186,10 @@ function symbol:register_module()
end
self:buf_watcher(args.buf, group)

if config.implement.enable and client.supports_method('textDocument/implementation') then
if
config.implement.enable
and util.client_supports_method(client, 'textDocument/implementation')
then
require('lspsaga.implement').start()
end
end,
Expand Down
18 changes: 12 additions & 6 deletions lua/lspsaga/symbol/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local api, lsp = vim.api, vim.lsp
---@diagnostic disable-next-line: deprecated
local uv = vim.version().minor >= 10 and vim.uv or vim.loop
local config = require('lspsaga').config
local util = require('lspsaga.util')
local symbol = {}

local cache = {}
Expand Down Expand Up @@ -90,9 +91,11 @@ function symbol:do_request(buf, client_id)
return
end

local params = { textDocument = {
uri = vim.uri_from_bufnr(buf),
} }
local params = {
textDocument = {
uri = vim.uri_from_bufnr(buf),
},
}

local client = vim.lsp.get_client_by_id(client_id)
if not client then
Expand All @@ -106,7 +109,7 @@ function symbol:do_request(buf, client_id)

self[buf].pending_request = true

client.request('textDocument/documentSymbol', params, function(err, result, ctx)
util.client_request(client, 'textDocument/documentSymbol', params, function(err, result, ctx)
if not api.nvim_buf_is_loaded(ctx.bufnr) or not self[ctx.bufnr] then
return
end
Expand Down Expand Up @@ -190,7 +193,7 @@ function symbol:register_module()
end

local client = lsp.get_client_by_id(args.data.client_id)
if not client or not client.supports_method('textDocument/documentSymbol') then
if not client or not util.client_supports_method(client, 'textDocument/documentSymbol') then
return
end
self:do_request(args.buf, args.data.client_id)
Expand All @@ -199,7 +202,10 @@ function symbol:register_module()
require('lspsaga.symbol.winbar').init_winbar(args.buf)
end

if config.implement.enable and client.supports_method('textDocument/implementation') then
if
config.implement.enable
and util.client_supports_method(client, 'textDocument/implementation')
then
require('lspsaga.implement').start()
end
end,
Expand Down
4 changes: 2 additions & 2 deletions lua/lspsaga/typehierarchy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ end

function ch:type_hierarchy(item, client, timer_close, curlnum)
self.pending_request = true
client.request(self.method, { item = item }, function(_, res)
util.client_request(client, self.method, { item = item }, function(_, res)
self.pending_request = false
curlnum = curlnum or 0
local inlevel = curlnum == 0 and 2 or fn.indent(curlnum)
Expand Down Expand Up @@ -472,7 +472,7 @@ function ch:send_prepare_type()
self.list = slist.new()

local params = lsp.util.make_position_params()
client.request(get_method(1), params, function(_, result, ctx)
util.client_request(client, get_method(1), params, function(_, result, ctx)
if api.nvim_get_current_buf() ~= ctx.bufnr then
return
end
Expand Down
23 changes: 22 additions & 1 deletion lua/lspsaga/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,34 @@ local M = {}
M.iswin = uv.os_uname().sysname:match('Windows')
M.ismac = uv.os_uname().sysname == 'Darwin'
M.is_ten = vim.version().minor >= 10
M.is_eleven = vim.version().minor >= 11

M.path_sep = M.iswin and '\\' or '/'

function M.path_join(...)
return table.concat({ ... }, M.path_sep)
end

-- 0.11+ warns on dot calls; 0.10- breaks on colon calls.
local function client_method_wrapper(client, name, ...)
if M.is_eleven then
return client[name](client, ...)
end
return client[name](...)
end

function M.client_request(client, ...)
return client_method_wrapper(client, 'request', ...)
end

function M.client_request_sync(client, ...)
return client_method_wrapper(client, 'request_sync', ...)
end

function M.client_supports_method(client, ...)
return client_method_wrapper(client, 'supports_method', ...)
end

function M.path_itera(buf)
local parts = vim.split(api.nvim_buf_get_name(buf), M.path_sep, { trimempty = true })
local index = #parts + 1
Expand Down Expand Up @@ -66,7 +87,7 @@ function M.get_client_by_method(method)
local supports = {}

for _, client in ipairs(clients or {}) do
if client.supports_method(method) then
if M.client_supports_method(client, method) then
supports[#supports + 1] = client
end
end
Expand Down
Loading