Skip to content

Commit

Permalink
feat: Check capabilities before sending request to otter buffer (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbuhr authored Aug 25, 2024
1 parent 3b4fa74 commit 18fcdbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 0 additions & 2 deletions lua/otter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ M.activate = function(languages, completion, diagnostics, tsquery)
local client_id = args.data.client_id
local method = args.data.method
local params = args.data.params
vim.print(bufnr .. "[" .. client_id .. "]" .. ": " .. method)
vim.print(params)
end,
})

Expand Down
19 changes: 16 additions & 3 deletions lua/otter/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ local fn = require("otter.tools.functions")

local capabilities = vim.lsp.protocol.make_client_capabilities()



local otterls = {}

--- @param main_nr integer main buffer
Expand Down Expand Up @@ -72,6 +70,7 @@ otterls.start = function(main_nr, completion)
version = "2.0.0",
},
}

-- default handler for initialize
handler(nil, initializeResult)
return
Expand Down Expand Up @@ -114,6 +113,20 @@ otterls.start = function(main_nr, completion)
local otter_nr = keeper.rafts[main_nr].buffers[lang]
local otter_uri = vim.uri_from_bufnr(otter_nr)

-- get clients attached to otter buffer
local otterclients = vim.lsp.get_clients({ bufnr = otter_nr })
-- collect capabilities
local supports_method = false
for _, client in pairs(otterclients) do
if client.supports_method(method) then
supports_method = true
end
end
if not supports_method then
-- no server attached to the otter buffer supports this method
return
end

-- update the otter buffer of that language
local success = keeper.sync_raft(main_nr, lang)
if not success then
Expand Down Expand Up @@ -143,7 +156,7 @@ otterls.start = function(main_nr, completion)
-- send the request to the otter buffer
-- modification of the response is done by our handler
-- and then passed on to the default handler or user-defined handler
vim.lsp.buf_request(otter_nr, method, params, function (err, result, context, config)
vim.lsp.buf_request(otter_nr, method, params, function(err, result, context, config)
if handlers[method] ~= nil then
err, result, context, config = handlers[method](err, result, context, config)
end
Expand Down

0 comments on commit 18fcdbb

Please sign in to comment.