feat: new serde deserializing api

This commit is contained in:
əlemi 2024-09-14 00:02:40 +02:00
parent 8a12b109ff
commit f274457f37
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 21 additions and 9 deletions

View file

@ -74,7 +74,9 @@ local function attach(name, buffer, content, nowait)
if CODEMP.config.debug then if CODEMP.config.debug then
print(string.format("sending: %s..%s '%s'", start_offset, start_offset + old_end_byte_len, change_content)) print(string.format("sending: %s..%s '%s'", start_offset, start_offset + old_end_byte_len, change_content))
end end
controller:send(start_offset, end_offset, change_content):await() controller:send({
first = start_offset, last = end_offset, content = change_content
}):await()
end, end,
}) })
@ -102,7 +104,9 @@ local function attach(name, buffer, content, nowait)
local remote_content = controller:content():await() local remote_content = controller:content():await()
if content ~= nil then if content ~= nil then
-- TODO this may happen too soon!! -- 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 else
ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer) ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer)
utils.buffer.set_content(buffer, remote_content) utils.buffer.set_content(buffer, remote_content)

View file

@ -3,11 +3,14 @@ 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")
local function connect(host, username, password) local function connect()
if host == nil then host = 'http://code.mp:50053' end if CODEMP.config.username == nil then
if username == nil then username = vim.g.codemp_username or vim.fn.input("username > ", "") end CODEMP.config.username = vim.g.codemp_username or vim.fn.input("username > ", "")
if password == nil then password = vim.g.codemp_password or vim.fn.input("password > ", "") end end
session.client = native.connect(host, username, password):await() 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() window.update()
vim.schedule(function () workspace.list() end) vim.schedule(function () workspace.list() end)
end end

View file

@ -102,7 +102,8 @@ local function open_buffer_under_cursor()
if buffers.map_rev[path] ~= nil then if buffers.map_rev[path] ~= nil then
vim.api.nvim_set_current_buf(buffers.map_rev[path]) vim.api.nvim_set_current_buf(buffers.map_rev[path])
else else
buffers.attach(path) local buf = vim.api.nvim_get_current_buf()
buffers.attach(path, buf)
update_window() update_window()
end end
end end

View file

@ -34,7 +34,11 @@ local function register_cursor_callback(ws)
local cur = utils.cursor.position() local cur = utils.cursor.position()
local buf = vim.api.nvim_get_current_buf() local buf = vim.api.nvim_get_current_buf()
if buffers.map[buf] ~= nil then 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
end end
}) })