fix: dont require window until its used

so that config can be properly loaded first
This commit is contained in:
əlemi 2024-09-14 14:24:48 +02:00
parent 8a12b109ff
commit 335ea236c4
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 14 additions and 12 deletions

View file

@ -21,8 +21,13 @@ local function attach(name, buffer, content, nowait)
vim.api.nvim_set_option_value('fileformat', 'unix', { buf = buffer }) vim.api.nvim_set_option_value('fileformat', 'unix', { buf = buffer })
vim.api.nvim_buf_set_name(buffer, name) vim.api.nvim_buf_set_name(buffer, name)
local controller = session.workspace:attach_buffer(name):await() local controller = session.workspace:attach_buffer(name):await()
if not nowait then if not nowait then
controller:poll():await() -- wait for current state to get synched local promise = controller:poll()
for i=1, 20, 1 do
if promise.ready then break end
vim.uv.sleep(100)
end
end end
-- TODO map name to uuid -- TODO map name to uuid

View file

@ -1,5 +1,4 @@
local native = require("codemp.loader").load() local native = require("codemp.loader").load()
local window = require("codemp.window")
local session = require("codemp.session") local session = require("codemp.session")
local workspace = require("codemp.workspace") local workspace = require("codemp.workspace")
@ -8,7 +7,7 @@ local function connect(host, username, password)
if username == nil then username = vim.g.codemp_username or vim.fn.input("username > ", "") end if username == nil then username = vim.g.codemp_username or vim.fn.input("username > ", "") end
if password == nil then password = vim.g.codemp_password or vim.fn.input("password > ", "") end if password == nil then password = vim.g.codemp_password or vim.fn.input("password > ", "") end
session.client = native.connect(host, username, password):await() session.client = native.connect(host, username, password):await()
window.update() require('codemp.window').update()
vim.schedule(function () workspace.list() end) vim.schedule(function () workspace.list() end)
end end

View file

@ -2,7 +2,6 @@ local session = require('codemp.session')
local buffers = require('codemp.buffers') local buffers = require('codemp.buffers')
local workspace = require('codemp.workspace') local workspace = require('codemp.workspace')
local utils = require('codemp.utils') local utils = require('codemp.utils')
local window = require('codemp.window')
local client = require("codemp.client") local client = require("codemp.client")
local function filter(needle, haystack) local function filter(needle, haystack)
@ -18,7 +17,7 @@ end
-- always available -- always available
local base_actions = { local base_actions = {
toggle = function() toggle = function()
window.toggle() require('codemp.window').toggle()
end, end,
connect = function(host) connect = function(host)
@ -88,7 +87,7 @@ local joined_actions = {
if not bang then buffers.create(path) end if not bang then buffers.create(path) end
local content = utils.buffer.get_content(buf) local content = utils.buffer.get_content(buf)
buffers.attach(path, buf, content) buffers.attach(path, buf, content)
window.update() -- TODO would be nice to do automatically inside require('codemp.window').update() -- TODO would be nice to do automatically inside
else else
print(" !! empty path or open a file") print(" !! empty path or open a file")
end end
@ -123,7 +122,7 @@ local joined_actions = {
detach = function(path) detach = function(path)
if path == nil then error("missing buffer name") end if path == nil then error("missing buffer name") end
buffers.detach(path) buffers.detach(path)
window.update() -- TODO would be nice to do automatically inside require('codemp.window').update() -- TODO would be nice to do automatically inside
end, end,
leave = function(ws) leave = function(ws)

View file

@ -1,7 +1,6 @@
local utils = require('codemp.utils') local utils = require('codemp.utils')
local buffers = require('codemp.buffers') local buffers = require('codemp.buffers')
local session = require('codemp.session') local session = require('codemp.session')
local window = require('codemp.window')
local user_hl = {} local user_hl = {}
@ -22,7 +21,7 @@ local function fetch_workspaces_list()
}) })
end end
session.available = new_list session.available = new_list
window.update() require('codemp.window').update()
end end
---@param ws Workspace ---@param ws Workspace
@ -72,7 +71,7 @@ local function register_cursor_handler(ws)
) )
end end
if old_buffer ~= event.buffer then if old_buffer ~= event.buffer then
window.update() -- redraw user positions require('codemp.window').update() -- redraw user positions
end end
end end
end)) end))
@ -99,11 +98,11 @@ local function join(workspace)
-- end) -- end)
-- end -- end
-- end -- end
-- vim.schedule(function() window.update() end) -- vim.schedule(function() require('codemp.window').update() end)
-- end) -- end)
session.workspace = ws session.workspace = ws
window.update() require('codemp.window').update()
return ws return ws
end end