mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-22 07:24:49 +01:00
feat: added auth and config for server username and password
This commit is contained in:
parent
496a97cb72
commit
ec2a2950ff
3 changed files with 76 additions and 27 deletions
36
package.json
36
package.json
|
@ -25,11 +25,19 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "codemp.join",
|
"command": "codemp.join",
|
||||||
"title": "Join a codemp Workspace"
|
"title": "Join a codemp Workspace if you are allowed"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "codemp.attach",
|
"command": "codemp.attach",
|
||||||
"title": "attach to a codemp buffer"
|
"title": "Attach to a codemp buffer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "codemp.createWorkspace",
|
||||||
|
"title": "Create a new Workspace if you are allowed"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "codemp.listWorkspaces",
|
||||||
|
"title": "List all Workspaces you can join"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "codemp.listBuffers",
|
"command": "codemp.listBuffers",
|
||||||
|
@ -56,6 +64,28 @@
|
||||||
"title": "Hello World (debug)"
|
"title": "Hello World (debug)"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
,"contributes": {
|
||||||
|
"configuration": {
|
||||||
|
"title": "TypeScript",
|
||||||
|
"properties": {
|
||||||
|
"typescript.server": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "http://codemp.dev:50053",
|
||||||
|
"description": "Server IP to use"
|
||||||
|
},
|
||||||
|
"typescript.username": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "test",
|
||||||
|
"description": "Username to use (the email you used during registration)"
|
||||||
|
},
|
||||||
|
"typescript.password": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "test",
|
||||||
|
"description": "Password to use"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"vscode:prepublish": "npm run compile",
|
"vscode:prepublish": "npm run compile",
|
||||||
|
@ -80,7 +110,7 @@
|
||||||
"typescript": "^5.1.6"
|
"typescript": "^5.1.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemp/codemp": "0.1.0-debug",
|
"@codemp/codemp": "0.1.0-auth",
|
||||||
"@vscode/vsce": "^2.32.0",
|
"@vscode/vsce": "^2.32.0",
|
||||||
"npx": "^10.2.2"
|
"npx": "^10.2.2"
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,13 @@ let username: string = "";
|
||||||
let mine : boolean;
|
let mine : boolean;
|
||||||
|
|
||||||
export async function connect() {
|
export async function connect() {
|
||||||
let username = await vscode.window.showInputBox({ prompt: "enter username" });
|
let config = vscode.workspace.getConfiguration('codemp-vscode');
|
||||||
if (username === null) throw "choose an username";
|
let server : string = config.get("server", "http://codemp.dev:50053");
|
||||||
client = await codemp.connect("http://codemp.alemi.dev:50053", username!, "lmaodefaultpassword");
|
let username : string = config.get("username")!;
|
||||||
|
let password : string = config.get("password")!;
|
||||||
|
console.log(server,username,password);
|
||||||
|
client = await codemp.connect(server, username, password);
|
||||||
|
console.log(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,9 +30,7 @@ export async function join() {
|
||||||
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) {
|
||||||
console.log("debug 12");
|
|
||||||
let event = await controller.try_recv();
|
let event = await controller.try_recv();
|
||||||
console.log("debug 13");
|
|
||||||
if (event === null) break;
|
if (event === null) break;
|
||||||
if (event.user === undefined) {
|
if (event.user === undefined) {
|
||||||
console.log("Skipping cursor without user not found", event)
|
console.log("Skipping cursor without user not found", event)
|
||||||
|
@ -64,10 +66,10 @@ export async function join() {
|
||||||
user: undefined,
|
user: undefined,
|
||||||
}
|
}
|
||||||
console.log("Sending Cursor");
|
console.log("Sending Cursor");
|
||||||
await controller.send(cursor);
|
//await controller.send(cursor);
|
||||||
console.log("Cursor sent");
|
console.log("Cursor sent");
|
||||||
});
|
});
|
||||||
vscode.window.showInformationMessage(`Connected to workspace @[${workspace}]`);
|
vscode.window.showInformationMessage("Connected to workspace");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,13 +125,11 @@ export async function attach() {
|
||||||
});
|
});
|
||||||
vscode.workspace.onDidChangeTextDocument(async (event: vscode.TextDocumentChangeEvent) => {
|
vscode.workspace.onDidChangeTextDocument(async (event: vscode.TextDocumentChangeEvent) => {
|
||||||
if(mine) { return }
|
if(mine) { return }
|
||||||
console.log("debug 6");
|
|
||||||
if (event.document.uri !== file_uri) return; // ?
|
if (event.document.uri !== file_uri) return; // ?
|
||||||
for (let change of event.contentChanges) {
|
for (let change of event.contentChanges) {
|
||||||
let tmp = CACHE.get(buffer_name, change.rangeOffset, change.text, change.rangeOffset + change.rangeLength)
|
let tmp = CACHE.get(buffer_name, change.rangeOffset, change.text, change.rangeOffset + change.rangeLength)
|
||||||
console.log("CACHE DUMPP", tmp);
|
console.log("CACHE DUMPP", tmp);
|
||||||
if (tmp) continue; // Remove TMP is for debug
|
if (tmp) continue; // Remove TMP is for debug
|
||||||
console.log("debug 7");
|
|
||||||
LOGGER.info(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
LOGGER.info(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
||||||
console.log("Sending buffer event");
|
console.log("Sending buffer event");
|
||||||
await buffer.send({
|
await buffer.send({
|
||||||
|
@ -137,19 +137,16 @@ export async function attach() {
|
||||||
end: change.rangeOffset + change.rangeLength,
|
end: change.rangeOffset + change.rangeLength,
|
||||||
content: change.text
|
content: change.text
|
||||||
});
|
});
|
||||||
console.log("debug 8");
|
|
||||||
console.log("Buffer event sent");
|
console.log("Buffer event sent");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
buffer.callback(async (controller: codemp.BufferController) => {
|
buffer.callback(async (controller: codemp.BufferController) => {
|
||||||
while (true) {
|
while (true) {
|
||||||
console.log("debug 9");
|
|
||||||
let event = await controller.try_recv();
|
let event = await controller.try_recv();
|
||||||
if (event === null) break;
|
if (event === null) break;
|
||||||
LOGGER.info(`buffer.callback(event: [${event.start}, ${event.content}, ${event.end}])`)
|
LOGGER.info(`buffer.callback(event: [${event.start}, ${event.content}, ${event.end}])`)
|
||||||
console.log(`console log buffer.callback(event: [${event.start}, ${event.content}, ${event.end}])`)
|
console.log(`console log buffer.callback(event: [${event.start}, ${event.content}, ${event.end}])`)
|
||||||
CACHE.put(buffer_name, event.start, event.content, event.end);
|
CACHE.put(buffer_name, event.start, event.content, event.end);
|
||||||
console.log("debug 10");
|
|
||||||
if (editor === undefined) { throw "Open an editor first" }
|
if (editor === undefined) { throw "Open an editor first" }
|
||||||
let range = new vscode.Range(
|
let range = new vscode.Range(
|
||||||
editor.document.positionAt(event.start),
|
editor.document.positionAt(event.start),
|
||||||
|
@ -168,12 +165,6 @@ export async function attach() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*export async function disconnectBuffer() { TODO i should just set buffer=null
|
|
||||||
let buffer : string = (await vscode.window.showInputBox({prompt: "buffer name for the file to disconnect from"}))!;
|
|
||||||
codemp.disconnectBuffer(buffer);
|
|
||||||
vscode.window.showInformationMessage(`Disconnected from codemp workspace buffer @[${buffer}]`);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
export async function sync() {
|
export async function sync() {
|
||||||
if (workspace === null) throw "join a workspace first";
|
if (workspace === null) throw "join a workspace first";
|
||||||
let editor = vscode.window.activeTextEditor;
|
let editor = vscode.window.activeTextEditor;
|
||||||
|
@ -200,17 +191,43 @@ export async function listBuffers() {
|
||||||
console.log(buffers); // improve UX
|
console.log(buffers); // improve UX
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function helloWorld() {
|
|
||||||
vscode.window.showInformationMessage("Hello World");
|
export async function createWorkspace(){
|
||||||
|
if(client===null){
|
||||||
|
vscode.window.showInformationMessage("Connect first");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let workspace_id = await vscode.window.showInputBox({ prompt: "Enter name for workspace" });
|
||||||
|
if(workspace_id===undefined){
|
||||||
|
vscode.window.showInformationMessage("You didn't enter a name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await client.create_workspace(workspace_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method is called when your extension is deactivated
|
export async function listWorkspaces(){
|
||||||
export function deactivate() {
|
if(client===null){
|
||||||
//Maybe i should disconnect from every workspace and buffer ??? // TODO
|
vscode.window.showInformationMessage("Connect first");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let result = await client.list_workspaces(true,true);
|
||||||
|
console.log(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export async function helloWorld() {
|
||||||
|
vscode.window.showInformationMessage("Hello World");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function printOpCache() {
|
export function printOpCache() {
|
||||||
console.log("CACHE\n");
|
console.log("CACHE\n");
|
||||||
console.log(CACHE.toString());
|
console.log(CACHE.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method is called when your extension is deactivated
|
||||||
|
export function deactivate() {
|
||||||
|
//Maybe i should disconnect from every workspace and buffer ??? // TODO
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@ import * as vscode from 'vscode';
|
||||||
import * as codemp from '@codemp/codemp'; // TODO why won't it work with a custom name???
|
import * as codemp from '@codemp/codemp'; // TODO why won't it work with a custom name???
|
||||||
import * as codemplogic from './codemp';
|
import * as codemplogic from './codemp';
|
||||||
|
|
||||||
export let LOGGER = vscode.window.createOutputChannel("codemp", {log: true});
|
export let LOGGER = vscode.window.createOutputChannel("codemp", { log: true });
|
||||||
|
|
||||||
// extension is activated the very first time the command is executed
|
// extension is activated the very first time the command is executed
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
|
@ -18,6 +18,8 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
vscode.commands.registerCommand('codemp.connect', codemplogic.connect),
|
vscode.commands.registerCommand('codemp.connect', codemplogic.connect),
|
||||||
vscode.commands.registerCommand('codemp.join', codemplogic.join),
|
vscode.commands.registerCommand('codemp.join', codemplogic.join),
|
||||||
vscode.commands.registerCommand('codemp.attach', codemplogic.attach),
|
vscode.commands.registerCommand('codemp.attach', codemplogic.attach),
|
||||||
|
vscode.commands.registerCommand('codemp.createWorkspace', codemplogic.createWorkspace),
|
||||||
|
vscode.commands.registerCommand('codemp.listWorkspaces', codemplogic.listWorkspaces),
|
||||||
vscode.commands.registerCommand('codemp.createBuffer', codemplogic.createBuffer),
|
vscode.commands.registerCommand('codemp.createBuffer', codemplogic.createBuffer),
|
||||||
vscode.commands.registerCommand('codemp.listBuffers', codemplogic.listBuffers),
|
vscode.commands.registerCommand('codemp.listBuffers', codemplogic.listBuffers),
|
||||||
// vscode.commands.registerCommand('codemp.disconnectBuffer', codemplogic.disconnectBuffer),
|
// vscode.commands.registerCommand('codemp.disconnectBuffer', codemplogic.disconnectBuffer),
|
||||||
|
|
Loading…
Reference in a new issue