mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-25 00:44:48 +01:00
feat: resync with action on warning
This commit is contained in:
parent
21b93f9d14
commit
4f16b46223
1 changed files with 15 additions and 8 deletions
|
@ -8,7 +8,6 @@ import { LOGGER, provider } from '../extension';
|
|||
let locks: Map<string, boolean> = new Map();
|
||||
let autoResync = vscode.workspace.getConfiguration('codemp').get<string>("autoResync");
|
||||
|
||||
|
||||
export async function apply_changes_to_buffer(path: string, controller: codemp.BufferController | undefined | null, force?: boolean) {
|
||||
if (workspace === null) throw "can't apply changes while not in a workspace";
|
||||
if (!controller) controller = workspace.buffer_by_name(path);
|
||||
|
@ -34,13 +33,20 @@ export async function apply_changes_to_buffer(path: string, controller: codemp.B
|
|||
});
|
||||
|
||||
if (event.hash !== undefined) {
|
||||
if (codemp.hash(editor.document.getText()) !== event.hash)
|
||||
if (autoResync) await resync(path, workspace, editor);
|
||||
else vscode.window.showErrorMessage("Client out of sync");
|
||||
if (codemp.hash(editor.document.getText()) !== event.hash) {
|
||||
if (autoResync) {
|
||||
vscode.window.showWarningMessage("Out of Sync, resynching...");
|
||||
await resync(path, workspace, editor);
|
||||
} else {
|
||||
controller.clear_callback();
|
||||
const selection = await vscode.window.showWarningMessage('Out of Sync', 'Resync');
|
||||
if (selection !== undefined && workspace) await resync(path, workspace, editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
locks.set(path, false);
|
||||
}
|
||||
}
|
||||
|
||||
export async function attach_to_remote_buffer(buffer_name: string, set_content?: boolean): Promise<codemp.BufferController | undefined> {
|
||||
if (workspace === null) {
|
||||
|
@ -177,7 +183,10 @@ export async function sync(selected: vscode.TreeItem | undefined) {
|
|||
buffer_name = mapping.bufferMapper.by_editor(editor.document.uri);
|
||||
if (buffer_name === undefined) throw "No such buffer managed by codemp"
|
||||
}
|
||||
|
||||
locks.set(buffer_name, true);
|
||||
resync(buffer_name, workspace, editor);
|
||||
locks.set(buffer_name, false);
|
||||
}
|
||||
|
||||
export async function resync(buffer_name: string, workspace: codemp.Workspace, editor: vscode.TextEditor) {
|
||||
|
@ -192,8 +201,6 @@ export async function resync(buffer_name: string, workspace: codemp.Workspace, e
|
|||
editor.document.positionAt(doc_len)
|
||||
);
|
||||
|
||||
locks.set(buffer_name, true);
|
||||
await editor.edit(editBuilder => editBuilder.replace(range, content));
|
||||
locks.set(buffer_name, false);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue