mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 07:24:52 +01:00
chore: new api
This commit is contained in:
parent
b8c05f431f
commit
bbc86f3ac4
5 changed files with 27 additions and 17 deletions
|
@ -25,7 +25,7 @@ local function attach(name, buffer, content, nowait)
|
||||||
|
|
||||||
vim.api.nvim_set_option_value('fileformat', 'unix', { buf = buffer })
|
vim.api.nvim_set_option_value('fileformat', 'unix', { buf = buffer })
|
||||||
vim.api.nvim_buf_set_name(buffer, name)
|
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
|
if not nowait then
|
||||||
local promise = controller:poll()
|
local promise = controller:poll()
|
||||||
|
@ -84,7 +84,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({
|
||||||
|
start = start_offset, finish = end_offset, content = change_content
|
||||||
|
}):await()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -94,9 +96,9 @@ local function attach(name, buffer, content, nowait)
|
||||||
if event == nil then break end
|
if event == nil then break end
|
||||||
ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer)
|
ticks[buffer] = vim.api.nvim_buf_get_changedtick(buffer)
|
||||||
if CODEMP.config.debug then
|
if CODEMP.config.debug then
|
||||||
print(" ~~ applying change ~~ " .. event.first .. ".." .. event.last .. "::[" .. event.content .. "]")
|
print(" ~~ applying change ~~ " .. event.start .. ".." .. event.finish .. "::[" .. event.content .. "]")
|
||||||
end
|
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 event.hash ~= nil then
|
||||||
if utils.hash(utils.buffer.get_content(buffer)) ~= event.hash then
|
if utils.hash(utils.buffer.get_content(buffer)) ~= event.hash then
|
||||||
-- OUT OF SYNC!
|
-- OUT OF SYNC!
|
||||||
|
@ -112,7 +114,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({
|
||||||
|
start = 0, finish = #remote_content, content = content
|
||||||
|
}) -- no need to await
|
||||||
else
|
else
|
||||||
local current_content = utils.buffer.get_content(buffer)
|
local current_content = utils.buffer.get_content(buffer)
|
||||||
if current_content ~= remote_content then
|
if current_content ~= remote_content then
|
||||||
|
@ -137,7 +141,7 @@ local function detach(name)
|
||||||
local buffer = buffer_id_map[name]
|
local buffer = buffer_id_map[name]
|
||||||
id_buffer_map[buffer] = nil
|
id_buffer_map[buffer] = nil
|
||||||
buffer_id_map[name] = nil
|
buffer_id_map[name] = nil
|
||||||
session.workspace:detach_buffer(name)
|
session.workspace:detach(name)
|
||||||
vim.api.nvim_buf_delete(buffer, {})
|
vim.api.nvim_buf_delete(buffer, {})
|
||||||
|
|
||||||
print(" -- detached from buffer " .. name)
|
print(" -- detached from buffer " .. name)
|
||||||
|
@ -176,7 +180,7 @@ local function create(buffer)
|
||||||
if session.workspace == nil then
|
if session.workspace == nil then
|
||||||
error("join a workspace first")
|
error("join a workspace first")
|
||||||
end
|
end
|
||||||
session.workspace:create_buffer(buffer):await()
|
session.workspace:create(buffer):await()
|
||||||
print(" ++ created buffer " .. buffer)
|
print(" ++ created buffer " .. buffer)
|
||||||
require('codemp.window').update()
|
require('codemp.window').update()
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
local native = require("codemp.loader").load()
|
|
||||||
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 = CODEMP.native.connect(CODEMP.config):await()
|
||||||
require('codemp.window').update()
|
require('codemp.window').update()
|
||||||
vim.schedule(function () workspace.list() end)
|
vim.schedule(function () workspace.list() end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,7 +102,7 @@ local joined_actions = {
|
||||||
|
|
||||||
delete = function(path)
|
delete = function(path)
|
||||||
if path == nil then error("missing buffer name") end
|
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)
|
print(" xx deleted buffer " .. path)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ M.delete = function(state, path, extra)
|
||||||
vim.ui.input({ prompt = "delete buffer '" .. selected.name .. "'?" }, function (input)
|
vim.ui.input({ prompt = "delete buffer '" .. selected.name .. "'?" }, function (input)
|
||||||
if input == nil then return end
|
if input == nil then return end
|
||||||
if not vim.startswith("y", string.lower(input)) 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)
|
print("deleted buffer " .. selected.name)
|
||||||
manager.refresh("codemp")
|
manager.refresh("codemp")
|
||||||
end)
|
end)
|
||||||
|
@ -126,7 +126,7 @@ M.add = function(state, path, extra)
|
||||||
if vim.startswith(selected.name, "#") then
|
if vim.startswith(selected.name, "#") then
|
||||||
vim.ui.input({ prompt = "new buffer path" }, function(input)
|
vim.ui.input({ prompt = "new buffer path" }, function(input)
|
||||||
if input == nil or input == "" then return end
|
if input == nil or input == "" then return end
|
||||||
session.workspace:create_buffer(input):await()
|
session.workspace:create(input):await()
|
||||||
manager.refresh("codemp")
|
manager.refresh("codemp")
|
||||||
end)
|
end)
|
||||||
elseif selected.name == "workspaces" then
|
elseif selected.name == "workspaces" then
|
||||||
|
|
|
@ -33,7 +33,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 = cur[1],
|
||||||
|
finish = cur[2],
|
||||||
|
}) -- no need to await here
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue