mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-22 15:34:49 +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"
|
"typescript": "^5.1.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"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) {
|
while (true) {
|
||||||
if (workspaceState.workspace === null) {
|
if (workspaceState.workspace === null) {
|
||||||
LOGGER.info(`left workspace, unregistering buffer controller '${path}' callback`);
|
LOGGER.info(`left workspace, unregistering buffer controller '${path}' callback`);
|
||||||
controller.clear_callback();
|
controller.clearCallback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let event = await controller.try_recv();
|
let event = await controller.tryRecv();
|
||||||
if (event === null) break;
|
if (event === null) break;
|
||||||
// LOGGER.info(`buffer.callback(event: [${event.start}, ${event.content}, ${event.end}])`)
|
// LOGGER.info(`buffer.callback(event: [${event.start}, ${event.content}, ${event.end}])`)
|
||||||
|
|
||||||
let range = new vscode.Range(
|
let range = new vscode.Range(
|
||||||
editor.document.positionAt(event.start),
|
editor.document.positionAt(event.change.startIdx),
|
||||||
editor.document.positionAt(event.end)
|
editor.document.positionAt(event.change.endIdx)
|
||||||
)
|
)
|
||||||
|
|
||||||
locks.set(path, event.content);
|
locks.set(path, event.change.content);
|
||||||
if (!await editor.edit(editBuilder => {
|
if (!await editor.edit(editBuilder => {
|
||||||
editBuilder
|
editBuilder
|
||||||
.replace(range, event.content)
|
.replace(range, event.change.content)
|
||||||
})) {
|
})) {
|
||||||
vscode.window.showWarningMessage("Couldn't apply changes");
|
vscode.window.showWarningMessage("Couldn't apply changes");
|
||||||
await resync(path, workspaceState.workspace, editor, 100);
|
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...");
|
vscode.window.showWarningMessage("Out of Sync, resynching...");
|
||||||
await resync(path, workspaceState.workspace, editor, 20);
|
await resync(path, workspaceState.workspace, editor, 20);
|
||||||
} else {
|
} else {
|
||||||
controller.clear_callback();
|
controller.clearCallback();
|
||||||
const selection = await vscode.window.showWarningMessage('Out of Sync', 'Resync');
|
const selection = await vscode.window.showWarningMessage('Out of Sync', 'Resync');
|
||||||
if (selection !== undefined && workspaceState.workspace) {
|
if (selection !== undefined && workspaceState.workspace) {
|
||||||
await resync(path, workspaceState.workspace, editor, 20);
|
await resync(path, workspaceState.workspace, editor, 20);
|
||||||
controller.callback(async (controller: codemp.BufferController) =>
|
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 doc = await vscode.workspace.openTextDocument(path);
|
||||||
let editor = await vscode.window.showTextDocument(doc, { preserveFocus: false })
|
let editor = await vscode.window.showTextDocument(doc, { preserveFocus: false })
|
||||||
await editor.edit((editor) => editor.setEndOfLine(vscode.EndOfLine.LF)); // set LF for EOL sequence
|
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
|
// wait for server changes
|
||||||
// TODO poll never unblocks, so this dirty fix is necessary
|
// 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) {
|
if (set_content) {
|
||||||
// make remote document match local content
|
// make remote document match local content
|
||||||
let doc_len = remoteContent.length;
|
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 {
|
} else {
|
||||||
// make local document match remote content
|
// make local document match remote content
|
||||||
let doc_len = localContent.length;
|
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;
|
if (skip_this !== undefined && change.text == skip_this) continue;
|
||||||
// LOGGER.info(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
// LOGGER.info(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
||||||
await buffer.send({
|
await buffer.send({
|
||||||
start: change.rangeOffset,
|
startIdx: change.rangeOffset,
|
||||||
end: change.rangeOffset + change.rangeLength,
|
endIdx: change.rangeOffset + change.rangeLength,
|
||||||
content: change.text
|
content: change.text
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
buffer.callback(async (controller: codemp.BufferController) =>
|
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();
|
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?
|
buffer_name = selected.label.label; // TODO ughh what is this api?
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
if (!buffer_name) return;
|
||||||
await attach_to_remote_buffer(buffer_name);
|
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?
|
buffer_name = selected.label.label; // TODO ughh what is this api?
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
if (!buffer_name) return;
|
||||||
let controller = workspaceState.workspace.buffer_by_name(buffer_name);
|
let controller = workspaceState.workspace.getBuffer(buffer_name);
|
||||||
if (controller) controller.clear_callback();
|
if (controller) controller.clearCallback();
|
||||||
workspaceState.workspace.detach(buffer_name);
|
workspaceState.workspace.detachBuffer(buffer_name);
|
||||||
mapping.bufferMapper.remove(buffer_name);
|
mapping.bufferMapper.remove(buffer_name);
|
||||||
vscode.window.showInformationMessage(`Detached from buffer ${buffer_name}`)
|
vscode.window.showInformationMessage(`Detached from buffer ${buffer_name}`)
|
||||||
provider.refresh();
|
provider.refresh();
|
||||||
|
@ -198,7 +198,7 @@ export async function share() {
|
||||||
let workspacePath: string = vscode.workspace.workspaceFolders[0].uri.toString();
|
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 "/"
|
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);
|
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);
|
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) {
|
export async function resync(buffer_name: string, workspace: codemp.Workspace, editor: vscode.TextEditor, tries?: number) {
|
||||||
LOGGER.info(`resynching buffer ${buffer_name}`);
|
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"
|
if (controller === null) throw "No such buffer controller"
|
||||||
|
|
||||||
let content = await controller.content();
|
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:" });
|
let ws = await vscode.window.showWorkspaceFolderPick({ placeHolder: "directory to open workspace into:" });
|
||||||
if (ws === undefined) return vscode.window.showErrorMessage("Open a Workspace folder first");
|
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();
|
let controller = workspaceState.workspace.cursor();
|
||||||
controller.callback(async function (controller: codemp.CursorController) {
|
controller.callback(async function (controller: codemp.CursorController) {
|
||||||
while (true) {
|
while (true) {
|
||||||
let event = await controller.try_recv();
|
let event = await controller.tryRecv();
|
||||||
if (workspaceState.workspace === null) {
|
if (workspaceState.workspace === null) {
|
||||||
controller.clear_callback();
|
controller.clearCallback();
|
||||||
LOGGER.info("left workspace, stopping cursor controller");
|
LOGGER.info("left workspace, stopping cursor controller");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,8 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
||||||
provider.refresh();
|
provider.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
let editor = mapping.bufferMapper.visible_by_buffer(event.buffer);
|
let editor = mapping.bufferMapper.visible_by_buffer(event.sel.buffer);
|
||||||
let refresh = event.buffer != mapp.buffer;
|
let refresh = event.sel.buffer != mapp.buffer;
|
||||||
mapp.update(event, editor);
|
mapp.update(event, editor);
|
||||||
if (workspaceState.follow === event.user) executeJump(event.user);
|
if (workspaceState.follow === event.user) executeJump(event.user);
|
||||||
if (refresh) provider.refresh();
|
if (refresh) provider.refresh();
|
||||||
|
@ -113,18 +113,21 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
||||||
endRow: selection.active.line,
|
endRow: selection.active.line,
|
||||||
endCol: selection.active.character,
|
endCol: selection.active.character,
|
||||||
buffer: buffer,
|
buffer: buffer,
|
||||||
user: undefined,
|
|
||||||
});
|
});
|
||||||
once = true;
|
once = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO waiting for https://github.com/hexedtech/codemp/pull/19 to reach npm
|
|
||||||
let event_handler = async () => {
|
workspaceState.workspace.callback(async function (controller: codemp.Workspace) {
|
||||||
try {
|
while(true){
|
||||||
while (true) {
|
if (workspaceState.workspace === null) {
|
||||||
if (workspaceState.workspace === null) break;
|
controller.clearCallback();
|
||||||
let event = await workspaceState.workspace.event();
|
LOGGER.info("left workspace, stopping receiving events");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let event = await workspaceState.workspace.tryRecv();
|
||||||
|
if (event === null) break;
|
||||||
if (event.type == "leave") {
|
if (event.type == "leave") {
|
||||||
mapping.colors_cache.get(event.value)?.clear()
|
mapping.colors_cache.get(event.value)?.clear()
|
||||||
mapping.colors_cache.delete(event.value);
|
mapping.colors_cache.delete(event.value);
|
||||||
|
@ -134,14 +137,10 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
||||||
}
|
}
|
||||||
provider.refresh();
|
provider.refresh();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
});
|
||||||
console.log(`stopping event handler for workspace: ${e}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
event_handler();
|
|
||||||
|
|
||||||
for (let user of workspaceState.workspace.user_list()) {
|
for (let user of workspaceState.workspace.userList()) {
|
||||||
mapping.colors_cache.set(user, new mapping.UserDecoration(user));
|
mapping.colors_cache.set(user.name, new mapping.UserDecoration(user.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
vscode.window.showInformationMessage("Connected to workspace");
|
vscode.window.showInformationMessage("Connected to workspace");
|
||||||
|
@ -151,7 +150,7 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
||||||
|
|
||||||
export async function listWorkspaces() {
|
export async function listWorkspaces() {
|
||||||
if (client === null) return vscode.window.showWarningMessage("Connect first");
|
if (client === null) return vscode.window.showWarningMessage("Connect first");
|
||||||
workspace_list = await client.list_workspaces(true, true);
|
workspace_list = await client.fetchJoinedWorkspaces();
|
||||||
provider.refresh();
|
provider.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +160,7 @@ export async function createWorkspace() {
|
||||||
if (client === null) return vscode.window.showWarningMessage("Connect first");
|
if (client === null) return vscode.window.showWarningMessage("Connect first");
|
||||||
let workspace_id = await vscode.window.showInputBox({ prompt: "Enter name for workspace" });
|
let workspace_id = await vscode.window.showInputBox({ prompt: "Enter name for workspace" });
|
||||||
if (workspace_id === undefined) return;
|
if (workspace_id === undefined) return;
|
||||||
await client.create_workspace(workspace_id);
|
await client.createWorkspace(workspace_id);
|
||||||
vscode.window.showInformationMessage("Created new workspace " + workspace_id);
|
vscode.window.showInformationMessage("Created new workspace " + workspace_id);
|
||||||
listWorkspaces();
|
listWorkspaces();
|
||||||
}
|
}
|
||||||
|
@ -172,15 +171,15 @@ export async function inviteToWorkspace() {
|
||||||
if (workspace_id === undefined) return;
|
if (workspace_id === undefined) return;
|
||||||
let user_id = await vscode.window.showInputBox({ prompt: "Name of user to invite" });
|
let user_id = await vscode.window.showInputBox({ prompt: "Name of user to invite" });
|
||||||
if (user_id === undefined) return;
|
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);
|
vscode.window.showInformationMessage("Invited " + user_id + " into workspace " + workspace_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function leave() {
|
export async function leave() {
|
||||||
if (!client) throw "can't leave while disconnected";
|
if (!client) throw "can't leave while disconnected";
|
||||||
if (!workspaceState.workspace) throw "can't leave while not in a workspace";
|
if (!workspaceState.workspace) throw "can't leave while not in a workspace";
|
||||||
workspaceState.workspace.cursor().clear_callback()
|
workspaceState.workspace.cursor().clearCallback()
|
||||||
client.leave_workspace(workspaceState.workspace.id());
|
client.leaveWorkspace(workspaceState.workspace.id());
|
||||||
if (cursor_disposable !== null) cursor_disposable.dispose();
|
if (cursor_disposable !== null) cursor_disposable.dispose();
|
||||||
let workspace_id = workspaceState.workspace.id();
|
let workspace_id = workspaceState.workspace.id();
|
||||||
workspaceState.workspace = null;
|
workspaceState.workspace = null;
|
||||||
|
|
|
@ -53,14 +53,14 @@ export async function executeJump(user: string) {
|
||||||
export async function createBuffer() {
|
export async function createBuffer() {
|
||||||
let bufferName: any = (await vscode.window.showInputBox({ prompt: "path of the buffer to create" }));
|
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");
|
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}`);
|
vscode.window.showInformationMessage(`new buffer created :${bufferName}`);
|
||||||
provider.refresh();
|
provider.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listBuffers() {
|
export async function listBuffers() {
|
||||||
if (workspaceState.workspace === null) return vscode.window.showWarningMessage("Join a workspace first");
|
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"));
|
vscode.window.showInformationMessage(buffers.join("\n"));
|
||||||
provider.refresh();
|
provider.refresh();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ export async function listBuffers() {
|
||||||
export async function deleteBuffer() {
|
export async function deleteBuffer() {
|
||||||
let bufferName: any = (await vscode.window.showInputBox({ prompt: "path of the buffer to delete" }));
|
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");
|
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}`);
|
vscode.window.showInformationMessage(`Deleted buffer :${bufferName}`);
|
||||||
provider.refresh();
|
provider.refresh();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
for (let editor of editors) {
|
for (let editor of editors) {
|
||||||
let path = mapping.bufferMapper.by_editor(editor.document.uri);
|
let path = mapping.bufferMapper.by_editor(editor.document.uri);
|
||||||
if (!path) continue;
|
if (!path) continue;
|
||||||
let controller = workspaceState.workspace.buffer_by_name(path);
|
let controller = workspaceState.workspace.getBuffer(path);
|
||||||
if (!controller) continue;
|
if (!controller) continue;
|
||||||
await apply_changes_to_buffer(path, controller, true);
|
await apply_changes_to_buffer(path, controller, true);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
|
|
||||||
export async function deactivate() {
|
export async function deactivate() {
|
||||||
if (client && workspaceState.workspace) {
|
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:
|
case Type.Workspace:
|
||||||
if (workspaceState.workspace === null) return [];
|
if (workspaceState.workspace === null) return [];
|
||||||
else if (element.label == workspaceState.workspace.id()) {
|
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) })
|
new CodempTreeItem(x, Type.Buffer, { active: bufferMapper.bufferToEditorMapping.has(x) })
|
||||||
);
|
);
|
||||||
} else return [];
|
} else return [];
|
||||||
|
|
Loading…
Reference in a new issue