From f274457f3765effaf79df79fc8832948229a277b Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 14 Sep 2024 00:02:40 +0200 Subject: [PATCH] feat: new serde deserializing api --- lua/codemp/buffers.lua | 8 ++++++-- lua/codemp/client.lua | 13 ++++++++----- lua/codemp/window.lua | 3 ++- lua/codemp/workspace.lua | 6 +++++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lua/codemp/buffers.lua b/lua/codemp/buffers.lua index 7fe3c59..2e0a6bf 100644 --- a/lua/codemp/buffers.lua +++ b/lua/codemp/buffers.lua @@ -74,7 +74,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({ + first = start_offset, last = end_offset, content = change_content + }):await() end, }) @@ -102,7 +104,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({ + first = 0, last = #remote_content, content = content + }) -- no need to await else ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer) utils.buffer.set_content(buffer, remote_content) diff --git a/lua/codemp/client.lua b/lua/codemp/client.lua index 37b4794..2e9b9e9 100644 --- a/lua/codemp/client.lua +++ b/lua/codemp/client.lua @@ -3,11 +3,14 @@ local window = require("codemp.window") 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 = native.connect(CODEMP.config):await() window.update() vim.schedule(function () workspace.list() end) end diff --git a/lua/codemp/window.lua b/lua/codemp/window.lua index c7095b0..dcf4179 100644 --- a/lua/codemp/window.lua +++ b/lua/codemp/window.lua @@ -102,7 +102,8 @@ local function open_buffer_under_cursor() if buffers.map_rev[path] ~= nil then vim.api.nvim_set_current_buf(buffers.map_rev[path]) else - buffers.attach(path) + local buf = vim.api.nvim_get_current_buf() + buffers.attach(path, buf) update_window() end end diff --git a/lua/codemp/workspace.lua b/lua/codemp/workspace.lua index 55ad885..9a79d53 100644 --- a/lua/codemp/workspace.lua +++ b/lua/codemp/workspace.lua @@ -34,7 +34,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 = { row = cur[1][1], col = cur[1][2] }, + finish = { row = cur[2][1], col = cur[2][2] }, + }) -- no need to await here end end })