chore: refactor errors, remove unneeded redraws

This commit is contained in:
əlemi 2024-09-25 05:12:03 +02:00
parent 5ed0341ccc
commit 8755954b98
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -40,7 +40,7 @@ export async function connect() {
} }
export async function join(selected: vscode.TreeItem | undefined) { export async function join(selected: vscode.TreeItem | undefined) {
if (client === null) throw "connect first"; if (client === null) return vscode.window.showWarningMessage("Connect first");
let workspace_id: string | undefined; let workspace_id: string | undefined;
if (selected !== undefined && selected.label !== undefined) { if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') { if (typeof(selected.label) === 'string') {
@ -68,7 +68,7 @@ export async function join(selected: vscode.TreeItem | undefined) {
} }
let mapp = mapping.colors_cache.get(event.user); let mapp = mapping.colors_cache.get(event.user);
if (mapp === undefined) { // first time we see this user if (mapp === undefined) { // first time we see this user
mapp = new mapping.UserDecoration(event); mapp = new mapping.UserDecoration(event.user);
mapping.colors_cache.set(event.user, mapp); mapping.colors_cache.set(event.user, mapp);
provider.refresh(); provider.refresh();
} }
@ -102,7 +102,7 @@ export async function join(selected: vscode.TreeItem | undefined) {
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 (workspace === null) throw "join a workspace first" if (workspace === null) return vscode.window.showWarningMessage("Join a workspace first");
workspace.create(bufferName); workspace.create(bufferName);
vscode.window.showInformationMessage(`new buffer created :${bufferName}`); vscode.window.showInformationMessage(`new buffer created :${bufferName}`);
provider.refresh(); provider.refresh();
@ -141,7 +141,7 @@ export async function apply_changes_to_buffer(path: string, controller: codemp.B
} }
export async function share(selected: vscode.TreeItem | undefined) { export async function share(selected: vscode.TreeItem | undefined) {
if (workspace === null) throw "join a workspace first" if (workspace === null) return vscode.window.showWarningMessage("Join a workspace first");
let buffer_name: string | undefined; let buffer_name: string | undefined;
if (selected !== undefined && selected.label !== undefined) { if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') { if (typeof(selected.label) === 'string') {
@ -215,7 +215,7 @@ export async function share(selected: vscode.TreeItem | undefined) {
export async function attach(selected: vscode.TreeItem | undefined) { export async function attach(selected: vscode.TreeItem | undefined) {
if (workspace === null) throw "join a workspace first" if (workspace === null) return vscode.window.showWarningMessage("Join a workspace first");
let buffer_name: string | undefined; let buffer_name: string | undefined;
if (selected !== undefined && selected.label !== undefined) { if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') { if (typeof(selected.label) === 'string') {
@ -290,7 +290,7 @@ export async function attach(selected: vscode.TreeItem | undefined) {
} }
export async function sync(selected: vscode.TreeItem | undefined) { export async function sync(selected: vscode.TreeItem | undefined) {
if (workspace === null) throw "join a workspace first"; if (workspace === null) return vscode.window.showWarningMessage("Join a workspace first");
let editor; let editor;
let buffer_name; let buffer_name;
if (selected !== undefined && selected.label !== undefined) { if (selected !== undefined && selected.label !== undefined) {
@ -324,7 +324,7 @@ export async function sync(selected: vscode.TreeItem | undefined) {
} }
export async function listBuffers() { export async function listBuffers() {
if (workspace === null) throw "join a workspace first" if (workspace === null) return vscode.window.showWarningMessage("Join a workspace first");
let buffers = workspace.filetree(undefined, false); let buffers = workspace.filetree(undefined, false);
vscode.window.showInformationMessage(buffers.join("\n")); vscode.window.showInformationMessage(buffers.join("\n"));
provider.refresh(); provider.refresh();
@ -332,76 +332,47 @@ export async function listBuffers() {
export async function createWorkspace() { export async function createWorkspace() {
if(client===null){ if (client === null) return vscode.window.showWarningMessage("Connect first");
vscode.window.showWarningMessage("Connect first");
return;
}
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){ if (workspace_id === undefined) return;
vscode.window.showWarningMessage("You didn't enter a name");
return;
}
await client.create_workspace(workspace_id); await client.create_workspace(workspace_id);
vscode.window.showInformationMessage("Created new workspace " + workspace_id); vscode.window.showInformationMessage("Created new workspace " + workspace_id);
provider.refresh(); provider.refresh();
} }
export async function inviteToWorkspace() { export async function inviteToWorkspace() {
if(client===null){ if (client === null) return vscode.window.showWarningMessage("Connect first");
vscode.window.showWarningMessage("Connect first");
return;
}
let workspace_id = await vscode.window.showInputBox({ prompt: "Enter name of the workspace you want to invite the user into" }); let workspace_id = await vscode.window.showInputBox({ prompt: "Enter name of the workspace you want to invite the user into" });
if(workspace_id===undefined){ if (workspace_id === undefined) return;
vscode.window.showWarningMessage("You didn't enter a name");
return;
}
let user_id = await vscode.window.showInputBox({ prompt: "Enter name of the user you want to invite" }); let user_id = await vscode.window.showInputBox({ prompt: "Enter name of the user you want to invite" });
if(user_id===undefined){ if (user_id === undefined) return;
vscode.window.showWarningMessage("You didn't enter a name");
return;
}
await client.invite_to_workspace(workspace_id,user_id); await client.invite_to_workspace(workspace_id,user_id);
vscode.window.showInformationMessage("Invited " + user_id + "into workspace " + workspace_id); vscode.window.showInformationMessage("Invited " + user_id + "into workspace " + workspace_id);
provider.refresh();
} }
export async function listWorkspaces() { export async function listWorkspaces() {
if(client===null){ if (client === null) return vscode.window.showWarningMessage("Connect first");
vscode.window.showWarningMessage("Connect first");
return;
}
workspace_list = await client.list_workspaces(true, true); workspace_list = await client.list_workspaces(true, true);
provider.refresh(); provider.refresh();
} }
export async function leaveWorkspace() { export async function leaveWorkspace() {
if(client===null){ if (client === null) return vscode.window.showWarningMessage("Connect first");
vscode.window.showWarningMessage("Connect first");
return;
}
let workspace_id = await vscode.window.showInputBox({ prompt: "Enter name for workspace you want to leave" }); let workspace_id = await vscode.window.showInputBox({ prompt: "Enter name for workspace you want to leave" });
if(workspace_id===undefined){ if (workspace_id === undefined) return;
vscode.window.showWarningMessage("You didn't enter a name");
return;
}
await client.leave_workspace(workspace_id); await client.leave_workspace(workspace_id);
vscode.window.showInformationMessage("Left workspace " + workspace_id); vscode.window.showInformationMessage("Left workspace " + workspace_id);
provider.refresh(); provider.refresh();
} }
export async function refresh() { export async function refresh() {
if(client===null){ if (client === null) return vscode.window.showWarningMessage("Connect first");
vscode.window.showWarningMessage("Connect first");
return;
}
await client.refresh(); await client.refresh();
vscode.window.showInformationMessage("Refreshed Session token"); vscode.window.showInformationMessage("Refreshed Session token");
provider.refresh();
} }
export async function jump(selected: vscode.TreeItem | undefined){ export async function jump(selected: vscode.TreeItem | undefined){
if (client === null) throw "connect first"; if (client === null) return vscode.window.showWarningMessage("Connect first");
let user; let user;
if (selected !== undefined && selected.label !== undefined) { if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') { if (typeof(selected.label) === 'string') {