mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-12-23 05:54:51 +01:00
chore: compliance to api changes
This commit is contained in:
parent
8586c07fe1
commit
011bbf808f
6 changed files with 59 additions and 60 deletions
|
@ -256,6 +256,6 @@
|
|||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"codemp": "^0.7.3"
|
||||
"codemp": "^0.8.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,22 +18,22 @@ export async function apply_changes_to_buffer(path: string, controller: codemp.B
|
|||
while (true) {
|
||||
if (workspaceState.workspace === null) {
|
||||
LOGGER.info(`left workspace, unregistering buffer controller '${path}' callback`);
|
||||
controller.clear_callback();
|
||||
controller.clearCallback();
|
||||
return;
|
||||
}
|
||||
let event = await controller.try_recv();
|
||||
let event = await controller.tryRecv();
|
||||
if (event === null) break;
|
||||
// LOGGER.info(`buffer.callback(event: [${event.start}, ${event.content}, ${event.end}])`)
|
||||
|
||||
let range = new vscode.Range(
|
||||
editor.document.positionAt(event.start),
|
||||
editor.document.positionAt(event.end)
|
||||
editor.document.positionAt(event.change.startIdx),
|
||||
editor.document.positionAt(event.change.endIdx)
|
||||
)
|
||||
|
||||
locks.set(path, event.content);
|
||||
locks.set(path, event.change.content);
|
||||
if (!await editor.edit(editBuilder => {
|
||||
editBuilder
|
||||
.replace(range, event.content)
|
||||
.replace(range, event.change.content)
|
||||
})) {
|
||||
vscode.window.showWarningMessage("Couldn't apply changes");
|
||||
await resync(path, workspaceState.workspace, editor, 100);
|
||||
|
@ -46,12 +46,12 @@ export async function apply_changes_to_buffer(path: string, controller: codemp.B
|
|||
vscode.window.showWarningMessage("Out of Sync, resynching...");
|
||||
await resync(path, workspaceState.workspace, editor, 20);
|
||||
} else {
|
||||
controller.clear_callback();
|
||||
controller.clearCallback();
|
||||
const selection = await vscode.window.showWarningMessage('Out of Sync', 'Resync');
|
||||
if (selection !== undefined && workspaceState.workspace) {
|
||||
await resync(path, workspaceState.workspace, editor, 20);
|
||||
controller.callback(async (controller: codemp.BufferController) =>
|
||||
await apply_changes_to_buffer(controller.get_path(), controller)
|
||||
await apply_changes_to_buffer(controller.path(), controller)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ export async function attach_to_remote_buffer(buffer_name: string, set_content?:
|
|||
let doc = await vscode.workspace.openTextDocument(path);
|
||||
let editor = await vscode.window.showTextDocument(doc, { preserveFocus: false })
|
||||
await editor.edit((editor) => editor.setEndOfLine(vscode.EndOfLine.LF)); // set LF for EOL sequence
|
||||
let buffer: codemp.BufferController = await workspaceState.workspace.attach(buffer_name);
|
||||
let buffer: codemp.BufferController = await workspaceState.workspace.attachBuffer(buffer_name);
|
||||
|
||||
// wait for server changes
|
||||
// TODO poll never unblocks, so this dirty fix is necessary
|
||||
|
@ -107,7 +107,7 @@ export async function attach_to_remote_buffer(buffer_name: string, set_content?:
|
|||
if (set_content) {
|
||||
// make remote document match local content
|
||||
let doc_len = remoteContent.length;
|
||||
await buffer.send({ start: 0, end: doc_len, content: localContent });
|
||||
await buffer.send({ startIdx: 0, endIdx: doc_len, content: localContent });
|
||||
} else {
|
||||
// make local document match remote content
|
||||
let doc_len = localContent.length;
|
||||
|
@ -131,18 +131,18 @@ export async function attach_to_remote_buffer(buffer_name: string, set_content?:
|
|||
if (skip_this !== undefined && change.text == skip_this) continue;
|
||||
// LOGGER.info(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
||||
await buffer.send({
|
||||
start: change.rangeOffset,
|
||||
end: change.rangeOffset + change.rangeLength,
|
||||
startIdx: change.rangeOffset,
|
||||
endIdx: change.rangeOffset + change.rangeLength,
|
||||
content: change.text
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
buffer.callback(async (controller: codemp.BufferController) =>
|
||||
await apply_changes_to_buffer(controller.get_path(), controller)
|
||||
await apply_changes_to_buffer(controller.path(), controller)
|
||||
);
|
||||
|
||||
mapping.bufferMapper.register(buffer.get_path(), file_uri, disposable);
|
||||
mapping.bufferMapper.register(buffer.path(), file_uri, disposable);
|
||||
|
||||
provider.refresh();
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ export async function attach(selected: vscode.TreeItem | undefined) {
|
|||
buffer_name = selected.label.label; // TODO ughh what is this api?
|
||||
}
|
||||
} else {
|
||||
buffer_name = await vscode.window.showQuickPick(workspaceState.workspace.filetree(null, false), { placeHolder: "buffer to attach to:" }, undefined);
|
||||
buffer_name = await vscode.window.showQuickPick(workspaceState.workspace.searchBuffers(), { placeHolder: "buffer to attach to:" }, undefined);
|
||||
}
|
||||
if (!buffer_name) return;
|
||||
await attach_to_remote_buffer(buffer_name);
|
||||
|
@ -173,12 +173,12 @@ export async function detach(selected: vscode.TreeItem | undefined) {
|
|||
buffer_name = selected.label.label; // TODO ughh what is this api?
|
||||
}
|
||||
} else {
|
||||
buffer_name = await vscode.window.showQuickPick(workspaceState.workspace.buffer_list(), { placeHolder: "buffer to detach from:" }, undefined);
|
||||
buffer_name = await vscode.window.showQuickPick(workspaceState.workspace.activeBuffers(), { placeHolder: "buffer to detach from:" }, undefined);
|
||||
}
|
||||
if (!buffer_name) return;
|
||||
let controller = workspaceState.workspace.buffer_by_name(buffer_name);
|
||||
if (controller) controller.clear_callback();
|
||||
workspaceState.workspace.detach(buffer_name);
|
||||
let controller = workspaceState.workspace.getBuffer(buffer_name);
|
||||
if (controller) controller.clearCallback();
|
||||
workspaceState.workspace.detachBuffer(buffer_name);
|
||||
mapping.bufferMapper.remove(buffer_name);
|
||||
vscode.window.showInformationMessage(`Detached from buffer ${buffer_name}`)
|
||||
provider.refresh();
|
||||
|
@ -198,7 +198,7 @@ export async function share() {
|
|||
let workspacePath: string = vscode.workspace.workspaceFolders[0].uri.toString();
|
||||
buffer_name = buffer_name.replace(workspacePath, "").substring(1); //vscode.workspace.asRelativePath doesn't work properly with other extensions like ssh, substring(1) to remove "/"
|
||||
console.log("After: " + buffer_name);
|
||||
await workspaceState.workspace.create(buffer_name);
|
||||
await workspaceState.workspace.createBuffer(buffer_name);
|
||||
await attach_to_remote_buffer(buffer_name, true);
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ export async function sync(selected: vscode.TreeItem | undefined) {
|
|||
|
||||
export async function resync(buffer_name: string, workspace: codemp.Workspace, editor: vscode.TextEditor, tries?: number) {
|
||||
LOGGER.info(`resynching buffer ${buffer_name}`);
|
||||
let controller = workspace.buffer_by_name(buffer_name);
|
||||
let controller = workspace.getBuffer(buffer_name);
|
||||
if (controller === null) throw "No such buffer controller"
|
||||
|
||||
let content = await controller.content();
|
||||
|
|
|
@ -56,13 +56,13 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
|||
let ws = await vscode.window.showWorkspaceFolderPick({ placeHolder: "directory to open workspace into:" });
|
||||
if (ws === undefined) return vscode.window.showErrorMessage("Open a Workspace folder first");
|
||||
}
|
||||
workspaceState.workspace = await client.join_workspace(workspace_id);
|
||||
workspaceState.workspace = await client.attachWorkspace(workspace_id);
|
||||
let controller = workspaceState.workspace.cursor();
|
||||
controller.callback(async function (controller: codemp.CursorController) {
|
||||
while (true) {
|
||||
let event = await controller.try_recv();
|
||||
let event = await controller.tryRecv();
|
||||
if (workspaceState.workspace === null) {
|
||||
controller.clear_callback();
|
||||
controller.clearCallback();
|
||||
LOGGER.info("left workspace, stopping cursor controller");
|
||||
return;
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
|||
provider.refresh();
|
||||
}
|
||||
|
||||
let editor = mapping.bufferMapper.visible_by_buffer(event.buffer);
|
||||
let refresh = event.buffer != mapp.buffer;
|
||||
let editor = mapping.bufferMapper.visible_by_buffer(event.sel.buffer);
|
||||
let refresh = event.sel.buffer != mapp.buffer;
|
||||
mapp.update(event, editor);
|
||||
if (workspaceState.follow === event.user) executeJump(event.user);
|
||||
if (refresh) provider.refresh();
|
||||
|
@ -113,35 +113,34 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
|||
endRow: selection.active.line,
|
||||
endCol: selection.active.character,
|
||||
buffer: buffer,
|
||||
user: undefined,
|
||||
});
|
||||
once = true;
|
||||
}
|
||||
});
|
||||
|
||||
// TODO waiting for https://github.com/hexedtech/codemp/pull/19 to reach npm
|
||||
let event_handler = async () => {
|
||||
try {
|
||||
while (true) {
|
||||
if (workspaceState.workspace === null) break;
|
||||
let event = await workspaceState.workspace.event();
|
||||
if (event.type == "leave") {
|
||||
mapping.colors_cache.get(event.value)?.clear()
|
||||
mapping.colors_cache.delete(event.value);
|
||||
}
|
||||
if (event.type == "join") {
|
||||
mapping.colors_cache.set(event.value, new mapping.UserDecoration(event.value));
|
||||
}
|
||||
provider.refresh();
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(`stopping event handler for workspace: ${e}`);
|
||||
|
||||
workspaceState.workspace.callback(async function (controller: codemp.Workspace) {
|
||||
while(true){
|
||||
if (workspaceState.workspace === null) {
|
||||
controller.clearCallback();
|
||||
LOGGER.info("left workspace, stopping receiving events");
|
||||
return;
|
||||
}
|
||||
};
|
||||
event_handler();
|
||||
let event = await workspaceState.workspace.tryRecv();
|
||||
if (event === null) break;
|
||||
if (event.type == "leave") {
|
||||
mapping.colors_cache.get(event.value)?.clear()
|
||||
mapping.colors_cache.delete(event.value);
|
||||
}
|
||||
if (event.type == "join") {
|
||||
mapping.colors_cache.set(event.value, new mapping.UserDecoration(event.value));
|
||||
}
|
||||
provider.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
for (let user of workspaceState.workspace.user_list()) {
|
||||
mapping.colors_cache.set(user, new mapping.UserDecoration(user));
|
||||
for (let user of workspaceState.workspace.userList()) {
|
||||
mapping.colors_cache.set(user.name, new mapping.UserDecoration(user.name));
|
||||
}
|
||||
|
||||
vscode.window.showInformationMessage("Connected to workspace");
|
||||
|
@ -151,7 +150,7 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
|||
|
||||
export async function listWorkspaces() {
|
||||
if (client === null) return vscode.window.showWarningMessage("Connect first");
|
||||
workspace_list = await client.list_workspaces(true, true);
|
||||
workspace_list = await client.fetchJoinedWorkspaces();
|
||||
provider.refresh();
|
||||
}
|
||||
|
||||
|
@ -161,7 +160,7 @@ export async function createWorkspace() {
|
|||
if (client === null) return vscode.window.showWarningMessage("Connect first");
|
||||
let workspace_id = await vscode.window.showInputBox({ prompt: "Enter name for workspace" });
|
||||
if (workspace_id === undefined) return;
|
||||
await client.create_workspace(workspace_id);
|
||||
await client.createWorkspace(workspace_id);
|
||||
vscode.window.showInformationMessage("Created new workspace " + workspace_id);
|
||||
listWorkspaces();
|
||||
}
|
||||
|
@ -172,15 +171,15 @@ export async function inviteToWorkspace() {
|
|||
if (workspace_id === undefined) return;
|
||||
let user_id = await vscode.window.showInputBox({ prompt: "Name of user to invite" });
|
||||
if (user_id === undefined) return;
|
||||
await client.invite_to_workspace(workspace_id, user_id);
|
||||
await client.inviteToWorkspace(workspace_id, user_id);
|
||||
vscode.window.showInformationMessage("Invited " + user_id + " into workspace " + workspace_id);
|
||||
}
|
||||
|
||||
export async function leave() {
|
||||
if (!client) throw "can't leave while disconnected";
|
||||
if (!workspaceState.workspace) throw "can't leave while not in a workspace";
|
||||
workspaceState.workspace.cursor().clear_callback()
|
||||
client.leave_workspace(workspaceState.workspace.id());
|
||||
workspaceState.workspace.cursor().clearCallback()
|
||||
client.leaveWorkspace(workspaceState.workspace.id());
|
||||
if (cursor_disposable !== null) cursor_disposable.dispose();
|
||||
let workspace_id = workspaceState.workspace.id();
|
||||
workspaceState.workspace = null;
|
||||
|
|
|
@ -53,14 +53,14 @@ export async function executeJump(user: string) {
|
|||
export async function createBuffer() {
|
||||
let bufferName: any = (await vscode.window.showInputBox({ prompt: "path of the buffer to create" }));
|
||||
if (workspaceState.workspace === null) return vscode.window.showWarningMessage("Join a workspace first");
|
||||
await workspaceState.workspace.create(bufferName);
|
||||
await workspaceState.workspace.createBuffer(bufferName);
|
||||
vscode.window.showInformationMessage(`new buffer created :${bufferName}`);
|
||||
provider.refresh();
|
||||
}
|
||||
|
||||
export async function listBuffers() {
|
||||
if (workspaceState.workspace === null) return vscode.window.showWarningMessage("Join a workspace first");
|
||||
let buffers = workspaceState.workspace.filetree(undefined, false);
|
||||
let buffers = workspaceState.workspace.searchBuffers();
|
||||
vscode.window.showInformationMessage(buffers.join("\n"));
|
||||
provider.refresh();
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ export async function listBuffers() {
|
|||
export async function deleteBuffer() {
|
||||
let bufferName: any = (await vscode.window.showInputBox({ prompt: "path of the buffer to delete" }));
|
||||
if (workspaceState.workspace === null) return vscode.window.showWarningMessage("Join a workspace first");
|
||||
await workspaceState.workspace.delete(bufferName);
|
||||
await workspaceState.workspace.deleteBuffer(bufferName);
|
||||
vscode.window.showInformationMessage(`Deleted buffer :${bufferName}`);
|
||||
provider.refresh();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
for (let editor of editors) {
|
||||
let path = mapping.bufferMapper.by_editor(editor.document.uri);
|
||||
if (!path) continue;
|
||||
let controller = workspaceState.workspace.buffer_by_name(path);
|
||||
let controller = workspaceState.workspace.getBuffer(path);
|
||||
if (!controller) continue;
|
||||
await apply_changes_to_buffer(path, controller, true);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
|
||||
export async function deactivate() {
|
||||
if (client && workspaceState.workspace) {
|
||||
await client.leave_workspace(workspaceState.workspace.id());
|
||||
await client.leaveWorkspace(workspaceState.workspace.id());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
|
|||
case Type.Workspace:
|
||||
if (workspaceState.workspace === null) return [];
|
||||
else if (element.label == workspaceState.workspace.id()) {
|
||||
return workspaceState.workspace.filetree(undefined, false).map((x) =>
|
||||
return workspaceState.workspace.searchBuffers().map((x) =>
|
||||
new CodempTreeItem(x, Type.Buffer, { active: bufferMapper.bufferToEditorMapping.has(x) })
|
||||
);
|
||||
} else return [];
|
||||
|
|
Loading…
Reference in a new issue