Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbuhr committed Aug 10, 2024
1 parent dacd28b commit 7ced134
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
24 changes: 24 additions & 0 deletions lua/otter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ M.activate = function(languages, completion, diagnostics, tsquery)
keeper.rafts[main_nr].code_chunks = nil
keeper.rafts[main_nr].last_changetick = nil
keeper.rafts[main_nr].otterls = {}
keeper.rafts[main_nr].otterls.clients_by_otternr = {}

local all_code_chunks = keeper.extract_code_chunks(main_nr)
local found_languages = {}
Expand Down Expand Up @@ -136,6 +137,29 @@ M.activate = function(languages, completion, diagnostics, tsquery)
-- attached to their otter buffers
keeper.sync_raft(main_nr)

-- add autocommand for otter to track lsp clients attached
-- to the otter buffers before they are attached
-- to track server capabilities
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('OtterLSPAttach', { clear = true }),
callback = function(event)
local client = vim.lsp.get_client_by_id(event.data.client_id)

-- check if the event comes from an otter buffer
for _, lang in ipairs(keeper.rafts[main_nr].languages) do
local otter_nr = keeper.rafts[main_nr].buffers[lang]
if keeper.rafts[main_nr].otterls.clients_by_otternr[otter_nr] == nil then
keeper.rafts[main_nr].otterls.clients_by_otternr[otter_nr] = {}
end
if otter_nr == event.buf then
table.insert(keeper.rafts[main_nr].otterls.clients_by_otternr[otter_nr], client)
end
end
end,
})



-- manually attach language server that corresponds to the filetype
-- without setting the filetype
-- to prevent other plugins we don't need in the otter buffers
Expand Down
24 changes: 8 additions & 16 deletions lua/otter/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,11 @@ local capabilities = vim.lsp.protocol.make_client_capabilities()

local otterls = {}

otterls.clients = {}

otterls.check_capabilities = function(main_nr)
local otter_nrs = keeper.rafts[main_nr].buffers
local clients = vim.lsp.get_clients()
for _, client in ipairs(clients) do
otterls.clients[main_nr][client.id] = {}
otterls.clients[main_nr][client.id].capabilities = client.server_capabilities
end
vim.print(otterls.clients)
end

--- @param main_nr integer main buffer
--- @param completion boolean should completion be enabled?
--- @return integer? client_id
otterls.start = function(main_nr, completion)
local main_uri = vim.uri_from_bufnr(main_nr)
otterls.clients[main_nr] = {}
local client_id = vim.lsp.start({
name = "otter-ls" .. "[" .. main_nr .. "]",
capabilities = capabilities,
Expand Down Expand Up @@ -123,12 +110,17 @@ otterls.start = function(main_nr, completion)
return
end


local otter_nr = keeper.rafts[main_nr].buffers[lang]
local otter_uri = vim.uri_from_bufnr(otter_nr)

-- populate the capabilities of the clients
-- attached to the otter buffers
otterls.check_capabilities(main_nr)
local otterclients = keeper.rafts[main_nr].otterls.clients_by_otternr[otter_nr]
if otterclients == nil then
return
end
for _, client in pairs(otterclients) do
vim.print(client.server_capabilities)
end

-- update the otter buffer of that language
local success = keeper.sync_raft(main_nr, lang)
Expand Down

0 comments on commit 7ced134

Please sign in to comment.