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 codemp from 'codemp';
import * as mapping from "../mapping";
import {client} from "./client"
import {workspace} from "./workspaces";
import { workspace } from "./workspaces";
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");
@ -36,7 +35,7 @@ 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);
if (autoResync) await resync(path, workspace, editor);
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");
let buffer_name: string | undefined;
if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') {
if (typeof (selected.label) === 'string') {
buffer_name = selected.label;
} else {
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
let done = false;
buffer.poll().then(() => done = true);
for(let i=0; i< 20; i++){
if(done) break;
await new Promise(r => setTimeout(r,100))
for (let i = 0; i < 20; i++) {
if (done) break;
await new Promise(r => setTimeout(r, 100))
}
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");
let buffer_name: string | undefined;
if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') {
if (typeof (selected.label) === 'string') {
buffer_name = selected.label;
} else {
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
let done = false;
buffer.poll().then(() => done = true);
for(let i=0; i< 20; i++){
if(done) break;
await new Promise(r => setTimeout(r,100))
for (let i = 0; i < 20; i++) {
if (done) break;
await new Promise(r => setTimeout(r, 100))
}
LOGGER.info(`attached to buffer ${buffer_name}`);
@ -197,7 +196,7 @@ export async function sync(selected: vscode.TreeItem | undefined) {
let editor;
let buffer_name;
if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') {
if (typeof (selected.label) === 'string') {
buffer_name = selected.label;
} else {
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);
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);
if (controller === null) throw "No such buffer controller"

View file

@ -1,13 +1,10 @@
import * as vscode from 'vscode';
import * as codemp from 'codemp';
import * as mapping from "../mapping";
import {workspace,setWorkspace} from "./workspaces";
import { workspace, setWorkspace } from "./workspaces";
import { LOGGER, provider } from '../extension';
// 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 workspace_list: string[] = [];
@ -45,7 +42,7 @@ export async function join(selected: vscode.TreeItem | undefined) {
if (client === null) return vscode.window.showWarningMessage("Connect first");
let workspace_id: string | undefined;
if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') {
if (typeof (selected.label) === 'string') {
workspace_id = selected.label;
} else {
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" });
}
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");
return;
}
setWorkspace(await client.join_workspace(workspace_id));
if(!workspace) return;
if (!workspace) return;
let controller = workspace.cursor();
controller.callback(async function (controller: codemp.CursorController) {
controller.callback(async function(controller: codemp.CursorController) {
while (true) {
let event = await controller.try_recv();
if (event === null) break;
@ -152,7 +149,7 @@ export async function inviteToWorkspace() {
if (workspace_id === undefined) return;
let user_id = await vscode.window.showInputBox({ prompt: "Enter name of the user you want to invite" });
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);
}

View file

@ -1,36 +1,37 @@
import * as vscode from 'vscode';
import * as codemp from 'codemp';
import * as mapping from "../mapping";
import {client} from "./client"
import { client } from "./client"
import { LOGGER, provider } from '../extension';
export let workspace: codemp.Workspace | null = null;
export function setWorkspace(ws : codemp.Workspace){
export function setWorkspace(ws: codemp.Workspace) {
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");
let user;
if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') {
if (typeof (selected.label) === 'string') {
user = selected.label;
} else {
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
let user_hl = mapping.colors_cache.get(user);
if (user_hl === undefined) return vscode.window.showWarningMessage("unknown position of such user");
let uri = mapping.bufferMapper.uri_by_buffer(user_hl.buffer);
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 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);
@ -39,8 +40,6 @@ export async function jump(selected: vscode.TreeItem | undefined){
}
export async function createBuffer() {
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");

View file

@ -1,10 +1,10 @@
import * as vscode from 'vscode';
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 * as mapping from './mapping';
import {workspace,jump,listBuffers,createBuffer} from './commands/workspaces'
import {attach,share,sync,apply_changes_to_buffer} from './commands/buffers'
import { workspace, jump, listBuffers, createBuffer } from './commands/workspaces'
import { attach, share, sync, apply_changes_to_buffer } from './commands/buffers'
export let provider = new CodempTreeProvider();
@ -18,11 +18,11 @@ export function activate(context: vscode.ExtensionContext) {
let sub = vscode.window.registerTreeDataProvider('codemp-tree-view', provider);
context.subscriptions.push(sub);
vscode.window.onDidChangeVisibleTextEditors(async (editors : readonly vscode.TextEditor[]) => {
if(workspace===null) return;
for(let editor of editors){
vscode.window.onDidChangeVisibleTextEditors(async (editors: readonly vscode.TextEditor[]) => {
if (workspace === null) return;
for (let editor of editors) {
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);
}
});
@ -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;
color: string;
buffer: string;
startRow : number
startCol : number;
endRow : number;
endCol : number;
startRow: number
startCol: number;
endRow: number;
endCol: number;
public constructor(name: string) {
let hash = codemp.hash(name);
@ -67,7 +67,7 @@ export class UserDecoration {
borderStyle: 'solid',
borderColor: this.color,
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",
//isWholeLine: true
overviewRulerLane: vscode.OverviewRulerLane.Right,
@ -82,7 +82,7 @@ export class UserDecoration {
if (editor !== undefined) {
editor.setDecorations(
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 { client, workspace_list } from './commands/client';
import { workspace} from './commands/workspaces';
import { workspace } from './commands/workspaces';
import { bufferMapper, colors_cache } from './mapping';
export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeItem> {
constructor() {}
constructor() { }
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;
@ -29,9 +29,9 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
);
} else return [];
case Type.UserList:
case Type.UserList: // asdasd
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 }));
};
return out;
@ -48,7 +48,7 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
return []; // empty screen with [connect] button
}
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) {
items.push(new CodempTreeItem("", Type.Placeholder, {}));
@ -64,7 +64,7 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
class CodempTreeItem extends vscode.TreeItem {
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;
super(label, state);
this.type = type;
@ -73,8 +73,8 @@ class CodempTreeItem extends vscode.TreeItem {
if (opts.active) this.contextValue += "_active";
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.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.UserList) this.iconPath = new vscode.ThemeIcon("accounts-view-bar-icon");
else if (type === Type.User) this.iconPath = new vscode.ThemeIcon("debug-breakpoint-data-unverified");
}
}