feat: leave

Co-authored-by: alemi <me@alemi.dev>
This commit is contained in:
frelodev 2024-10-04 23:20:42 +02:00
parent 9c00cf9eeb
commit 4b98c836c6
3 changed files with 13 additions and 18 deletions

View file

@ -139,7 +139,7 @@
"icon": "$(extensions-view-icon)" "icon": "$(extensions-view-icon)"
}, },
{ {
"command": "codemp.leaveWorkspace", "command": "codemp.leave",
"title": "Leave Workspace", "title": "Leave Workspace",
"category": "codemp", "category": "codemp",
"icon": "$(arrow-down)" "icon": "$(arrow-down)"

View file

@ -144,15 +144,6 @@ export async function join(selected: vscode.TreeItem | undefined) {
provider.refresh(); provider.refresh();
} }
export async function leave() {
if (!client) throw "can't leave while disconnected";
if (!workspace) return vscode.window.showWarningMessage("Not in a workspace");
client.leave_workspace(workspace.id());
if (cursor_disposable !== null) cursor_disposable.dispose();
cursor_disposable = null;
setWorkspace(null);
}
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");
@ -181,15 +172,19 @@ export async function inviteToWorkspace() {
vscode.window.showInformationMessage("Invited " + user_id + " into workspace " + workspace_id); vscode.window.showInformationMessage("Invited " + user_id + " into workspace " + workspace_id);
} }
export async function leaveWorkspace() { export async function leave() {
if (client === null) return vscode.window.showWarningMessage("Connect first"); if (!client) throw "can't leave while disconnected";
let workspace_id = await vscode.window.showInputBox({ prompt: "Enter name for workspace you want to leave" }); if (!workspace) throw "can't leave while not in a workspace";
if (workspace_id === undefined) return; workspace.cursor().clear_callback()
await client.leave_workspace(workspace_id); client.leave_workspace(workspace.id());
vscode.window.showInformationMessage("Left workspace " + workspace_id); if (cursor_disposable !== null) cursor_disposable.dispose();
let workspace_id = workspace.id();
setWorkspace(null);
provider.refresh(); provider.refresh();
vscode.window.showInformationMessage("Left workspace " + workspace_id);
} }
export async function refresh() { export async function refresh() {
if (client === null) return vscode.window.showWarningMessage("Connect first"); if (client === null) return vscode.window.showWarningMessage("Connect first");
await client.refresh(); await client.refresh();

View file

@ -1,6 +1,6 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as codemp from 'codemp'; import * as codemp from 'codemp';
import { client, connect, join, refresh, createWorkspace, inviteToWorkspace, listWorkspaces, leaveWorkspace } from './commands/client'; import { client, connect, join, refresh, createWorkspace, inviteToWorkspace, listWorkspaces, leave } from './commands/client';
import { CodempTreeProvider } from './tree'; import { CodempTreeProvider } from './tree';
import * as mapping from './mapping'; import * as mapping from './mapping';
import { workspace, jump, listBuffers, createBuffer } from './commands/workspaces' import { workspace, jump, listBuffers, createBuffer } from './commands/workspaces'
@ -38,7 +38,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('codemp.createWorkspace', createWorkspace), vscode.commands.registerCommand('codemp.createWorkspace', createWorkspace),
vscode.commands.registerCommand('codemp.inviteWorkspace', inviteToWorkspace), vscode.commands.registerCommand('codemp.inviteWorkspace', inviteToWorkspace),
vscode.commands.registerCommand('codemp.listWorkspaces', listWorkspaces), vscode.commands.registerCommand('codemp.listWorkspaces', listWorkspaces),
vscode.commands.registerCommand('codemp.leaveWorkspace', leaveWorkspace), vscode.commands.registerCommand('codemp.leave', leave),
vscode.commands.registerCommand('codemp.createBuffer', createBuffer), vscode.commands.registerCommand('codemp.createBuffer', createBuffer),
vscode.commands.registerCommand('codemp.listBuffers', listBuffers), vscode.commands.registerCommand('codemp.listBuffers', listBuffers),
vscode.commands.registerCommand('codemp.detach', detach), vscode.commands.registerCommand('codemp.detach', detach),