diff --git a/lua/codemp/buffers.lua b/lua/codemp/buffers.lua index 440452f..1fb4b65 100644 --- a/lua/codemp/buffers.lua +++ b/lua/codemp/buffers.lua @@ -25,7 +25,7 @@ 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() + local controller = session.workspace:attach(name):await() if not nowait then local promise = controller:poll() @@ -84,7 +84,9 @@ local function attach(name, buffer, content, nowait) if CODEMP.config.debug then print(string.format("sending: %s..%s '%s'", start_offset, start_offset + old_end_byte_len, change_content)) end - controller:send(start_offset, end_offset, change_content):await() + controller:send({ + start = start_offset, finish = end_offset, content = change_content + }):await() end, }) @@ -94,9 +96,9 @@ local function attach(name, buffer, content, nowait) if event == nil then break end ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer) if CODEMP.config.debug then - print(" ~~ applying change ~~ " .. event.first .. ".." .. event.last .. "::[" .. event.content .. "]") + print(" ~~ applying change ~~ " .. event.start .. ".." .. event.finish .. "::[" .. event.content .. "]") end - utils.buffer.set_content(buffer, event.content, event.first, event.last) + utils.buffer.set_content(buffer, event.content, event.start, event.finish) if event.hash ~= nil then if utils.hash(utils.buffer.get_content(buffer)) ~= event.hash then -- OUT OF SYNC! @@ -112,7 +114,9 @@ local function attach(name, buffer, content, nowait) local remote_content = controller:content():await() if content ~= nil then -- TODO this may happen too soon!! - local _ = controller:send(0, #remote_content, content) -- no need to await + local _ = controller:send({ + start = 0, finish = #remote_content, content = content + }) -- no need to await else local current_content = utils.buffer.get_content(buffer) if current_content ~= remote_content then @@ -137,7 +141,7 @@ local function detach(name) local buffer = buffer_id_map[name] id_buffer_map[buffer] = nil buffer_id_map[name] = nil - session.workspace:detach_buffer(name) + session.workspace:detach(name) vim.api.nvim_buf_delete(buffer, {}) print(" -- detached from buffer " .. name) @@ -176,7 +180,7 @@ local function create(buffer) if session.workspace == nil then error("join a workspace first") end - session.workspace:create_buffer(buffer):await() + session.workspace:create(buffer):await() print(" ++ created buffer " .. buffer) require('codemp.window').update() end diff --git a/lua/codemp/client.lua b/lua/codemp/client.lua index b7f4e78..f4555b7 100644 --- a/lua/codemp/client.lua +++ b/lua/codemp/client.lua @@ -1,12 +1,14 @@ -local native = require("codemp.loader").load() local session = require("codemp.session") local workspace = require("codemp.workspace") -local function connect(host, username, password) - if host == nil then host = 'http://code.mp:50053' 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 - session.client = native.connect(host, username, password):await() +local function connect() + if CODEMP.config.username == nil then + CODEMP.config.username = vim.g.codemp_username or vim.fn.input("username > ", "") + end + if CODEMP.config.password == nil then + CODEMP.config.password = vim.g.codemp_password or vim.fn.input("password > ", "") + end + session.client = CODEMP.native.connect(CODEMP.config):await() require('codemp.window').update() vim.schedule(function () workspace.list() end) end diff --git a/lua/codemp/command.lua b/lua/codemp/command.lua index c7dbb7d..74ecc6e 100644 --- a/lua/codemp/command.lua +++ b/lua/codemp/command.lua @@ -102,7 +102,7 @@ local joined_actions = { delete = function(path) if path == nil then error("missing buffer name") end - session.workspace:delete_buffer(path):await() + session.workspace:delete(path):await() print(" xx deleted buffer " .. path) end, diff --git a/lua/codemp/neo-tree/commands.lua b/lua/codemp/neo-tree/commands.lua index c0fb35d..f61531a 100644 --- a/lua/codemp/neo-tree/commands.lua +++ b/lua/codemp/neo-tree/commands.lua @@ -104,7 +104,7 @@ M.delete = function(state, path, extra) vim.ui.input({ prompt = "delete buffer '" .. selected.name .. "'?" }, function (input) if input == nil then return end if not vim.startswith("y", string.lower(input)) then return end - session.workspace:delete_buffer(selected.name):await() + session.workspace:delete(selected.name):await() print("deleted buffer " .. selected.name) manager.refresh("codemp") end) @@ -126,7 +126,7 @@ M.add = function(state, path, extra) if vim.startswith(selected.name, "#") then vim.ui.input({ prompt = "new buffer path" }, function(input) if input == nil or input == "" then return end - session.workspace:create_buffer(input):await() + session.workspace:create(input):await() manager.refresh("codemp") end) elseif selected.name == "workspaces" then diff --git a/lua/codemp/workspace.lua b/lua/codemp/workspace.lua index ef87517..b6a3913 100644 --- a/lua/codemp/workspace.lua +++ b/lua/codemp/workspace.lua @@ -33,7 +33,11 @@ local function register_cursor_callback(ws) local cur = utils.cursor.position() local buf = vim.api.nvim_get_current_buf() if buffers.map[buf] ~= nil then - local _ = controller:send(buffers.map[buf], cur[1][1], cur[1][2], cur[2][1], cur[2][2]) -- no need to await here + local _ = controller:send({ + buffer = buffers.map[buf], + start = cur[1], + finish = cur[2], + }) -- no need to await here end end })