fix: configuration proper scope, catch missing val

This commit is contained in:
əlemi 2024-09-06 16:04:24 +02:00
parent cc5bd6ea16
commit bce44730b9
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 32 additions and 25 deletions

View file

@ -62,28 +62,26 @@
"title": "Hello World (debug)" "title": "Hello World (debug)"
} }
], ],
"contributes": {
"configuration": { "configuration": {
"title": "codemp", "title": "codemp",
"properties": { "properties": {
"typescript.server": { "codemp.server": {
"type": "string", "type": "string",
"default": "http://codemp.dev:50053", "default": "http://codemp.dev:50053",
"description": "Server address to connect to" "description": "Server address to connect to"
}, },
"typescript.username": { "codemp.username": {
"type": "string", "type": "string",
"default": "mail@example.net", "default": "",
"description": "Username to use for login (the email you used during registration)" "description": "Username to use for login (the email you used during registration)"
}, },
"typescript.password": { "codemp.password": {
"type": "string", "type": "string",
"default": "dont-use-this-password", "default": "",
"description": "Password to use for login" "description": "Password to use for login"
} }
} }
} }
}
}, },
"scripts": { "scripts": {
"vscode:prepublish": "npm run compile", "vscode:prepublish": "npm run compile",
@ -102,6 +100,7 @@
"@typescript-eslint/eslint-plugin": "^6.4.1", "@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1", "@typescript-eslint/parser": "^6.4.1",
"@vscode/test-electron": "^2.3.4", "@vscode/test-electron": "^2.3.4",
"@vscode/vsce": "^3.1.0",
"eslint": "^8.47.0", "eslint": "^8.47.0",
"glob": "^10.3.3", "glob": "^10.3.3",
"mocha": "^10.2.0", "mocha": "^10.2.0",
@ -109,7 +108,6 @@
"typescript": "^5.1.6" "typescript": "^5.1.6"
}, },
"dependencies": { "dependencies": {
"codemp": "^0.0.5", "codemp": "^0.0.5"
"vsce": "^2.15.0"
} }
} }

View file

@ -10,10 +10,19 @@ let workspace: codemp.Workspace | null = null;
let mine : boolean; let mine : boolean;
export async function connect() { export async function connect() {
let config = vscode.workspace.getConfiguration('codemp-vscode'); let config = vscode.workspace.getConfiguration('codemp');
let server : string = config.get("server", "http://codemp.dev:50053"); let server = config.get<string>("server", "http://codemp.dev:50053");
let username : string = config.get("username")!;
let password : string = config.get("password")!; let username = config.get<string>("username");
if (!username) {
return vscode.window.showErrorMessage("missing username in settings: configure it first!");
}
let password = config.get<string>("password");
if (!password) {
return vscode.window.showErrorMessage("missing password in settings: configure it first!");
}
client = await codemp.connect(server, username, password); client = await codemp.connect(server, username, password);
} }