chore: auto format code

This commit is contained in:
əlemi 2024-10-01 16:11:36 +02:00
parent d7736c0add
commit 3f5f72fbfb
Signed by: alemi
GPG key ID: A4895B84D311642C
6 changed files with 58 additions and 64 deletions

View file

@ -2,11 +2,10 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as codemp from 'codemp'; import * as codemp from 'codemp';
import * as mapping from "../mapping"; import * as mapping from "../mapping";
import {client} from "./client" import { workspace } from "./workspaces";
import {workspace} from "./workspaces";
import { LOGGER, provider } from '../extension'; import { LOGGER, provider } from '../extension';
let locks : Map<string, boolean> = new Map(); let locks: Map<string, boolean> = new Map();
let autoResync = vscode.workspace.getConfiguration('codemp').get<string>("autoResync"); let autoResync = vscode.workspace.getConfiguration('codemp').get<string>("autoResync");
@ -15,7 +14,7 @@ export async function apply_changes_to_buffer(path: string, controller: codemp.B
if (!controller) controller = workspace.buffer_by_name(path); if (!controller) controller = workspace.buffer_by_name(path);
if (!controller) return; if (!controller) return;
let editor = mapping.bufferMapper.visible_by_buffer(path); let editor = mapping.bufferMapper.visible_by_buffer(path);
if (editor === undefined) return; if (editor === undefined) return;
if (locks.get(path) && !force) return; if (locks.get(path) && !force) return;
locks.set(path, true); locks.set(path, true);
@ -36,7 +35,7 @@ export async function apply_changes_to_buffer(path: string, controller: codemp.B
if (event.hash !== undefined) { if (event.hash !== undefined) {
if (codemp.hash(editor.document.getText()) !== event.hash) if (codemp.hash(editor.document.getText()) !== event.hash)
if(autoResync) await resync(path,workspace,editor); if (autoResync) await resync(path, workspace, editor);
else vscode.window.showErrorMessage("Client out of sync"); else vscode.window.showErrorMessage("Client out of sync");
} }
} }
@ -47,7 +46,7 @@ export async function attach(selected: vscode.TreeItem | undefined) {
if (workspace === null) return vscode.window.showWarningMessage("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') {
buffer_name = selected.label; buffer_name = selected.label;
} else { } else {
buffer_name = selected.label.label; // TODO ughh what is this api? buffer_name = selected.label.label; // TODO ughh what is this api?
@ -78,9 +77,9 @@ export async function attach(selected: vscode.TreeItem | undefined) {
// TODO poll never unblocks // TODO poll never unblocks
let done = false; let done = false;
buffer.poll().then(() => done = true); buffer.poll().then(() => done = true);
for(let i=0; i< 20; i++){ for (let i = 0; i < 20; i++) {
if(done) break; if (done) break;
await new Promise(r => setTimeout(r,100)) await new Promise(r => setTimeout(r, 100))
} }
LOGGER.info(`attached to buffer ${buffer_name}`); LOGGER.info(`attached to buffer ${buffer_name}`);
@ -123,7 +122,7 @@ export async function share(selected: vscode.TreeItem | undefined) {
if (workspace === null) return vscode.window.showWarningMessage("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') {
buffer_name = selected.label; buffer_name = selected.label;
} else { } else {
buffer_name = selected.label.label; // TODO ughh what is this api? buffer_name = selected.label.label; // TODO ughh what is this api?
@ -155,9 +154,9 @@ export async function share(selected: vscode.TreeItem | undefined) {
// TODO poll never unblocks // TODO poll never unblocks
let done = false; let done = false;
buffer.poll().then(() => done = true); buffer.poll().then(() => done = true);
for(let i=0; i< 20; i++){ for (let i = 0; i < 20; i++) {
if(done) break; if (done) break;
await new Promise(r => setTimeout(r,100)) await new Promise(r => setTimeout(r, 100))
} }
LOGGER.info(`attached to buffer ${buffer_name}`); LOGGER.info(`attached to buffer ${buffer_name}`);
@ -197,7 +196,7 @@ export async function sync(selected: vscode.TreeItem | undefined) {
let editor; let editor;
let buffer_name; let buffer_name;
if (selected !== undefined && selected.label !== undefined) { if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') { if (typeof (selected.label) === 'string') {
buffer_name = selected.label; buffer_name = selected.label;
} else { } else {
buffer_name = selected.label.label; // TODO ughh what is this api? buffer_name = selected.label.label; // TODO ughh what is this api?
@ -210,10 +209,10 @@ export async function sync(selected: vscode.TreeItem | undefined) {
buffer_name = mapping.bufferMapper.by_editor(editor.document.uri); buffer_name = mapping.bufferMapper.by_editor(editor.document.uri);
if (buffer_name === undefined) throw "No such buffer managed by codemp" if (buffer_name === undefined) throw "No such buffer managed by codemp"
} }
resync(buffer_name,workspace,editor); resync(buffer_name, workspace, editor);
} }
export async function resync(buffer_name : string, workspace : codemp.Workspace, editor : vscode.TextEditor){ export async function resync(buffer_name: string, workspace: codemp.Workspace, editor: vscode.TextEditor) {
let controller = workspace.buffer_by_name(buffer_name); let controller = workspace.buffer_by_name(buffer_name);
if (controller === null) throw "No such buffer controller" if (controller === null) throw "No such buffer controller"

View file

@ -1,13 +1,10 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as codemp from 'codemp'; import * as codemp from 'codemp';
import * as mapping from "../mapping"; import * as mapping from "../mapping";
import {workspace,setWorkspace} from "./workspaces"; import { workspace, setWorkspace } from "./workspaces";
import { LOGGER, provider } from '../extension'; import { LOGGER, provider } from '../extension';
// TODO this "global state" should probably live elsewher but we need lo update it from these commands // TODO this "global state" should probably live elsewher but we need lo update it from these commands
export let client: codemp.Client | null = null; export let client: codemp.Client | null = null;
export let workspace_list: string[] = []; export let workspace_list: string[] = [];
@ -45,7 +42,7 @@ export async function join(selected: vscode.TreeItem | undefined) {
if (client === null) return vscode.window.showWarningMessage("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') {
workspace_id = selected.label; workspace_id = selected.label;
} else { } else {
workspace_id = selected.label.label; // TODO ughh what is this api? workspace_id = selected.label.label; // TODO ughh what is this api?
@ -54,14 +51,14 @@ export async function join(selected: vscode.TreeItem | undefined) {
workspace_id = await vscode.window.showInputBox({ prompt: "name of workspace to attach to" }); workspace_id = await vscode.window.showInputBox({ prompt: "name of workspace to attach to" });
} }
if (!workspace_id) return; // user cancelled with ESC if (!workspace_id) return; // user cancelled with ESC
if(vscode.workspace.workspaceFolders === undefined) { if (vscode.workspace.workspaceFolders === undefined) {
vscode.window.showErrorMessage("Open a Workspace folder first"); vscode.window.showErrorMessage("Open a Workspace folder first");
return; return;
} }
setWorkspace(await client.join_workspace(workspace_id)); setWorkspace(await client.join_workspace(workspace_id));
if(!workspace) return; if (!workspace) return;
let controller = workspace.cursor(); let controller = 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.try_recv();
if (event === null) break; if (event === null) break;
@ -152,7 +149,7 @@ export async function inviteToWorkspace() {
if (workspace_id === undefined) return; if (workspace_id === undefined) 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) return; if (user_id === undefined) 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);
} }

View file

@ -1,36 +1,37 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as codemp from 'codemp'; import * as codemp from 'codemp';
import * as mapping from "../mapping"; import * as mapping from "../mapping";
import {client} from "./client" import { client } from "./client"
import { LOGGER, provider } from '../extension'; import { LOGGER, provider } from '../extension';
export let workspace: codemp.Workspace | null = null; export let workspace: codemp.Workspace | null = null;
export function setWorkspace(ws : codemp.Workspace){ export function setWorkspace(ws: codemp.Workspace) {
workspace = ws; workspace = ws;
} }
export async function jump(selected: vscode.TreeItem | undefined){ export async function jump(selected: vscode.TreeItem | undefined) {
if (client === null) return vscode.window.showWarningMessage("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') {
user = selected.label; user = selected.label;
} else { } else {
user = selected.label.label; user = selected.label.label;
} }
} }
if (!user) user = await vscode.window.showInputBox({ prompt: "username"}); if (!user) user = await vscode.window.showInputBox({ prompt: "username" });
if (!user) return; // user cancelled with ESC if (!user) return; // user cancelled with ESC
let user_hl = mapping.colors_cache.get(user); let user_hl = mapping.colors_cache.get(user);
if (user_hl === undefined) return vscode.window.showWarningMessage("unknown position of such user"); if (user_hl === undefined) return vscode.window.showWarningMessage("unknown position of such user");
let uri = mapping.bufferMapper.uri_by_buffer(user_hl.buffer); let uri = mapping.bufferMapper.uri_by_buffer(user_hl.buffer);
if (uri === undefined) { if (uri === undefined) {
return vscode.window.showWarningMessage("user is on an untracked buffer: "+ user_hl.buffer);} return vscode.window.showWarningMessage("user is on an untracked buffer: " + user_hl.buffer);
}
let editor = await vscode.window.showTextDocument(uri, { preserveFocus: false }); let editor = await vscode.window.showTextDocument(uri, { preserveFocus: false });
let range_start: vscode.Position = new vscode.Position(user_hl.startRow, user_hl.startCol); let range_start: vscode.Position = new vscode.Position(user_hl.startRow, user_hl.startCol);
let range_end: vscode.Position = new vscode.Position(user_hl.endRow, user_hl.endCol); let range_end: vscode.Position = new vscode.Position(user_hl.endRow, user_hl.endCol);
@ -39,8 +40,6 @@ export async function jump(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) return vscode.window.showWarningMessage("Join a workspace first"); if (workspace === null) return vscode.window.showWarningMessage("Join a workspace first");

View file

@ -1,10 +1,10 @@
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, leaveWorkspace } 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'
import {attach,share,sync,apply_changes_to_buffer} from './commands/buffers' import { attach, share, sync, apply_changes_to_buffer } from './commands/buffers'
export let provider = new CodempTreeProvider(); export let provider = new CodempTreeProvider();
@ -18,11 +18,11 @@ export function activate(context: vscode.ExtensionContext) {
let sub = vscode.window.registerTreeDataProvider('codemp-tree-view', provider); let sub = vscode.window.registerTreeDataProvider('codemp-tree-view', provider);
context.subscriptions.push(sub); context.subscriptions.push(sub);
vscode.window.onDidChangeVisibleTextEditors(async (editors : readonly vscode.TextEditor[]) => { vscode.window.onDidChangeVisibleTextEditors(async (editors: readonly vscode.TextEditor[]) => {
if(workspace===null) return; if (workspace === null) return;
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===undefined) continue; if (path === undefined) continue;
await apply_changes_to_buffer(path, undefined, true); await apply_changes_to_buffer(path, undefined, true);
} }
}); });
@ -62,4 +62,3 @@ async function log_poller_task(logger: codemp.JsLogger) {
} }
} }

View file

@ -38,10 +38,10 @@ export class UserDecoration {
decoration: vscode.TextEditorDecorationType | null; decoration: vscode.TextEditorDecorationType | null;
color: string; color: string;
buffer: string; buffer: string;
startRow : number startRow: number
startCol : number; startCol: number;
endRow : number; endRow: number;
endCol : number; endCol: number;
public constructor(name: string) { public constructor(name: string) {
let hash = codemp.hash(name); let hash = codemp.hash(name);
@ -67,7 +67,7 @@ export class UserDecoration {
borderStyle: 'solid', borderStyle: 'solid',
borderColor: this.color, borderColor: this.color,
backgroundColor: this.color + '44', // add alpha backgroundColor: this.color + '44', // add alpha
after: {contentText: event.user, margin: "1px", color: colors[2], }, after: { contentText: event.user, margin: "1px", color: colors[2], },
border: "1px", border: "1px",
//isWholeLine: true //isWholeLine: true
overviewRulerLane: vscode.OverviewRulerLane.Right, overviewRulerLane: vscode.OverviewRulerLane.Right,
@ -82,7 +82,7 @@ export class UserDecoration {
if (editor !== undefined) { if (editor !== undefined) {
editor.setDecorations( editor.setDecorations(
this.decoration, this.decoration,
[{ range: decorationRange, hoverMessage: new vscode.MarkdownString(`### \`${event.user}\`'s cursor`)}] [{ range: decorationRange, hoverMessage: new vscode.MarkdownString(`### \`${event.user}\`'s cursor`) }]
); );
} }
} }

View file

@ -1,11 +1,11 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { client, workspace_list } from './commands/client'; import { client, workspace_list } from './commands/client';
import { workspace} from './commands/workspaces'; import { workspace } from './commands/workspaces';
import { bufferMapper, colors_cache } from './mapping'; import { bufferMapper, colors_cache } from './mapping';
export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeItem> { export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeItem> {
constructor() {} constructor() { }
private _emitter: vscode.EventEmitter<CodempTreeItem | undefined | null | void> = new vscode.EventEmitter<CodempTreeItem | undefined | null | void>(); private _emitter: vscode.EventEmitter<CodempTreeItem | undefined | null | void> = new vscode.EventEmitter<CodempTreeItem | undefined | null | void>();
readonly onDidChangeTreeData: vscode.Event<CodempTreeItem | undefined | null | void> = this._emitter.event; readonly onDidChangeTreeData: vscode.Event<CodempTreeItem | undefined | null | void> = this._emitter.event;
@ -29,9 +29,9 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
); );
} else return []; } else return [];
case Type.UserList: case Type.UserList: // asdasd
let out = []; let out = [];
for (let x of colors_cache){ for (let x of colors_cache) {
out.push(new CodempTreeItem(x[0], Type.User, { description: x[1].buffer })); out.push(new CodempTreeItem(x[0], Type.User, { description: x[1].buffer }));
}; };
return out; return out;
@ -48,7 +48,7 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
return []; // empty screen with [connect] button return []; // empty screen with [connect] button
} }
let items = workspace_list.map((x) => let items = workspace_list.map((x) =>
new CodempTreeItem(x, Type.Workspace, { expandable: true, active: workspace === null}) new CodempTreeItem(x, Type.Workspace, { expandable: true, active: workspace === null })
); );
if (workspace !== null) { if (workspace !== null) {
items.push(new CodempTreeItem("", Type.Placeholder, {})); items.push(new CodempTreeItem("", Type.Placeholder, {}));
@ -64,7 +64,7 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
class CodempTreeItem extends vscode.TreeItem { class CodempTreeItem extends vscode.TreeItem {
type: Type; type: Type;
constructor(label: string | vscode.TreeItemLabel, type: Type, opts: { description?: string, expandable?: boolean, active?: boolean }){ constructor(label: string | vscode.TreeItemLabel, type: Type, opts: { description?: string, expandable?: boolean, active?: boolean }) {
let state = opts.expandable ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None; let state = opts.expandable ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None;
super(label, state); super(label, state);
this.type = type; this.type = type;
@ -73,8 +73,8 @@ class CodempTreeItem extends vscode.TreeItem {
if (opts.active) this.contextValue += "_active"; if (opts.active) this.contextValue += "_active";
if (type === Type.Workspace) this.iconPath = new vscode.ThemeIcon(opts.active ? "timeline-pin" : "extensions-remote"); if (type === Type.Workspace) this.iconPath = new vscode.ThemeIcon(opts.active ? "timeline-pin" : "extensions-remote");
else if (type === Type.Buffer) this.iconPath = new vscode.ThemeIcon(opts.active ? "debug-restart-frame" : "debug-console-clear-all"); else if (type === Type.Buffer) this.iconPath = new vscode.ThemeIcon(opts.active ? "debug-restart-frame" : "debug-console-clear-all");
else if (type === Type.UserList ) this.iconPath = new vscode.ThemeIcon("accounts-view-bar-icon"); else if (type === Type.UserList) this.iconPath = new vscode.ThemeIcon("accounts-view-bar-icon");
else if (type === Type.User ) this.iconPath = new vscode.ThemeIcon("debug-breakpoint-data-unverified"); else if (type === Type.User) this.iconPath = new vscode.ThemeIcon("debug-breakpoint-data-unverified");
} }
} }