diff --git a/lua/codemp/buffers.lua b/lua/codemp/buffers.lua index 7fe3c59..bc8f761 100644 --- a/lua/codemp/buffers.lua +++ b/lua/codemp/buffers.lua @@ -21,8 +21,13 @@ local function attach(name, buffer, content, nowait) vim.api.nvim_set_option_value('fileformat', 'unix', { buf = buffer }) vim.api.nvim_buf_set_name(buffer, name) local controller = session.workspace:attach_buffer(name):await() + 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 -- TODO map name to uuid diff --git a/lua/codemp/client.lua b/lua/codemp/client.lua index 37b4794..b7f4e78 100644 --- a/lua/codemp/client.lua +++ b/lua/codemp/client.lua @@ -1,5 +1,4 @@ local native = require("codemp.loader").load() -local window = require("codemp.window") local session = require("codemp.session") 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 password == nil then password = vim.g.codemp_password or vim.fn.input("password > ", "") end session.client = native.connect(host, username, password):await() - window.update() + require('codemp.window').update() vim.schedule(function () workspace.list() end) end diff --git a/lua/codemp/command.lua b/lua/codemp/command.lua index de1b208..66bd0a7 100644 --- a/lua/codemp/command.lua +++ b/lua/codemp/command.lua @@ -2,7 +2,6 @@ local session = require('codemp.session') local buffers = require('codemp.buffers') local workspace = require('codemp.workspace') local utils = require('codemp.utils') -local window = require('codemp.window') local client = require("codemp.client") local function filter(needle, haystack) @@ -18,7 +17,7 @@ end -- always available local base_actions = { toggle = function() - window.toggle() + require('codemp.window').toggle() end, connect = function(host) @@ -88,7 +87,7 @@ local joined_actions = { if not bang then buffers.create(path) end local content = utils.buffer.get_content(buf) 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 print(" !! empty path or open a file") end @@ -123,7 +122,7 @@ local joined_actions = { detach = function(path) if path == nil then error("missing buffer name") end 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, leave = function(ws) diff --git a/lua/codemp/workspace.lua b/lua/codemp/workspace.lua index 55ad885..ef87517 100644 --- a/lua/codemp/workspace.lua +++ b/lua/codemp/workspace.lua @@ -1,7 +1,6 @@ local utils = require('codemp.utils') local buffers = require('codemp.buffers') local session = require('codemp.session') -local window = require('codemp.window') local user_hl = {} @@ -22,7 +21,7 @@ local function fetch_workspaces_list() }) end session.available = new_list - window.update() + require('codemp.window').update() end ---@param ws Workspace @@ -72,7 +71,7 @@ local function register_cursor_handler(ws) ) end if old_buffer ~= event.buffer then - window.update() -- redraw user positions + require('codemp.window').update() -- redraw user positions end end end)) @@ -99,11 +98,11 @@ local function join(workspace) -- end) -- end -- end - -- vim.schedule(function() window.update() end) + -- vim.schedule(function() require('codemp.window').update() end) -- end) session.workspace = ws - window.update() + require('codemp.window').update() return ws end