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
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)

View file

@ -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

View file

@ -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

View file

@ -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
})