Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp,ui: do not attach lsp clients #4

Merged
merged 1 commit into from
Nov 18, 2021
Merged
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
13 changes: 13 additions & 0 deletions lua/calltree/lsp/util.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local M = {}

M.multi_client_request = function(clients, method, params, handler, bufnr)
for _, client in ipairs(clients) do
if not client.supports_method(method) then
goto continue
end
client.request(method, params, handler, bufnr)
::continue::
end
end

return M
30 changes: 12 additions & 18 deletions lua/calltree/ui.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local tree = require('calltree.tree')
local ct = require('calltree')
local lsp_util = require('calltree.lsp.util')

local M = {}

Expand Down Expand Up @@ -65,13 +66,6 @@ local function _setup_buffer()
vim.api.nvim_buf_set_keymap(M.buffer_handle, "n", "i", ":CTHover<CR>", opts)
vim.api.nvim_buf_set_keymap(M.buffer_handle, "n", "s", ":CTSwitch<CR>", opts)
vim.api.nvim_buf_set_keymap(M.buffer_handle, "n", "?", ":lua require('calltree.ui').help(true)<CR>", opts)

-- attach lsp's
if M.active_lsp_clients ~= nil then
for id, _ in ipairs(M.active_lsp_clients) do
vim.lsp.buf_attach_client(M.buffer_handle, id)
end
end
end

-- idempotent creation of the help buffer.
Expand Down Expand Up @@ -193,7 +187,7 @@ M.encode_node_to_line = function(node)
glyph = M.glyphs["collapsed"]
end

kind = vim.lsp.protocol.SymbolKind[node.kind]
local kind = vim.lsp.protocol.SymbolKind[node.kind]

-- add spacing up to node's depth
for _=1, node.depth do
Expand Down Expand Up @@ -303,11 +297,12 @@ M.expand = function()
node.expanded = true
end

vim.lsp.buf_request(
M.buffer_handle,
lsp_util.multi_client_request(
M.active_lsp_clients,
direction_map[M.direction].method,
{item = node.call_hierarchy_obj},
M.ch_expand_handler(node, linenr, M.direction)
M.ch_expand_handler(node, linenr, M.direction),
M.buffer_handle
)
end

Expand Down Expand Up @@ -335,19 +330,18 @@ M.switch_direction = function()
return
end

local name = vim.api.nvim_buf_get_name(M.buffer_handle)

if M.direction == "from" then
M.direction = "to"
else
M.direction = "from"
end

vim.lsp.buf_request(
M.buffer_handle,
lsp_util.multi_client_request(
M.active_lsp_clients,
direction_map[M.direction].method,
{item = node.call_hierarchy_obj},
M.ch_switch_handler(M.direction)
M.ch_switch_handler(M.direction),
M.buffer_handle
)
end

Expand Down Expand Up @@ -415,13 +409,13 @@ M.jump = function()

if ct.config.jump_mode == "neighbor" then
local cur_win = vim.api.nvim_get_current_win()
if config.layout == "left" then
if ct.config.layout == "left" then
vim.cmd('wincmd l')
else
vim.cmd('wincmd h')
end
if cur_win == vim.api.nvim_get_current_win() then
if config.layout == "left" then
if ct.config.layout == "left" then
vim.cmd("botright vsplit")
else
vim.cmd("topleft vsplit")
Expand Down