Skip to content

Commit 99c7390

Browse files
committed
Merge branch 'feat/server-url-quickpick' into dev
2 parents a1f5b71 + 66ee754 commit 99c7390

2 files changed

Lines changed: 102 additions & 23 deletions

File tree

extension/package.json

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@
8585
"title": "Artemis: Open Recordings Folder",
8686
"icon": "$(folder-opened)"
8787
},
88+
{
89+
"command": "artemis.setServerUrl",
90+
"title": "Artemis: Set Server URL",
91+
"icon": "$(server)"
92+
},
8893
{
8994
"command": "artemis.clearTrustedDomains",
9095
"title": "Artemis: Clear Trusted Domains"
@@ -105,6 +110,10 @@
105110
"command": "artemis.logout",
106111
"when": "!iris:managedEnvironment"
107112
},
113+
{
114+
"command": "artemis.setServerUrl",
115+
"when": "!iris:managedEnvironment"
116+
},
108117
{
109118
"command": "artemis.showJwtToken",
110119
"when": "config.artemis.developerMode"
@@ -151,29 +160,7 @@
151160
"artemis.serverUrl": {
152161
"type": "string",
153162
"default": "https://artemis.tum.de",
154-
"markdownDescription": "The URL of the Artemis server to connect to.\n\nFor a custom URL not listed here, [open settings.json](command:workbench.action.openSettingsJson) and edit `artemis.serverUrl` directly.",
155-
"enum": [
156-
"https://artemis.tum.de",
157-
"https://artemis-test1.artemis.cit.tum.de",
158-
"https://artemis-test2.artemis.cit.tum.de",
159-
"https://artemis-test3.artemis.cit.tum.de",
160-
"https://artemis-test4.artemis.cit.tum.de",
161-
"https://artemis-test5.artemis.cit.tum.de",
162-
"https://artemis-test6.artemis.cit.tum.de",
163-
"https://artemis-test9.artemis.cit.tum.de",
164-
"http://localhost:9000"
165-
],
166-
"enumItemLabels": [
167-
"Production (artemis.tum.de)",
168-
"Test Server 1 (artemis-test1.artemis.cit.tum.de)",
169-
"Test Server 2 (artemis-test2.artemis.cit.tum.de)",
170-
"Test Server 3 (artemis-test3.artemis.cit.tum.de)",
171-
"Test Server 4 (artemis-test4.artemis.cit.tum.de)",
172-
"Test Server 5 (artemis-test5.artemis.cit.tum.de)",
173-
"Test Server 6 (artemis-test6.artemis.cit.tum.de)",
174-
"Test Server 9 (artemis-test9.artemis.cit.tum.de)",
175-
"Local Development (localhost:9000)"
176-
]
163+
"markdownDescription": "The URL of the Artemis server to connect to.\n\nUse the command **[Artemis: Set Server URL](command:artemis.setServerUrl)** to pick from known servers or enter a custom URL."
177164
},
178165
"artemis.iris.sendUncommittedChanges": {
179166
"type": "boolean",

extension/src/extension/activation/extensionCommands.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,97 @@ function registerGoToSourceErrorCommand(): vscode.Disposable {
396396
);
397397
}
398398

399+
const KNOWN_SERVERS: ReadonlyArray<{ label: string; url: string }> = [
400+
{ label: 'Production (artemis.tum.de)', url: 'https://artemis.tum.de' },
401+
{ label: 'Test Server 1 (artemis-test1.artemis.cit.tum.de)', url: 'https://artemis-test1.artemis.cit.tum.de' },
402+
{ label: 'Test Server 2 (artemis-test2.artemis.cit.tum.de)', url: 'https://artemis-test2.artemis.cit.tum.de' },
403+
{ label: 'Test Server 3 (artemis-test3.artemis.cit.tum.de)', url: 'https://artemis-test3.artemis.cit.tum.de' },
404+
{ label: 'Test Server 4 (artemis-test4.artemis.cit.tum.de)', url: 'https://artemis-test4.artemis.cit.tum.de' },
405+
{ label: 'Test Server 5 (artemis-test5.artemis.cit.tum.de)', url: 'https://artemis-test5.artemis.cit.tum.de' },
406+
{ label: 'Test Server 6 (artemis-test6.artemis.cit.tum.de)', url: 'https://artemis-test6.artemis.cit.tum.de' },
407+
{ label: 'Test Server 9 (artemis-test9.artemis.cit.tum.de)', url: 'https://artemis-test9.artemis.cit.tum.de' },
408+
{ label: 'Local Development (localhost:9000)', url: 'http://localhost:9000' },
409+
];
410+
411+
function registerSetServerUrlCommand(): vscode.Disposable {
412+
return vscode.commands.registerCommand('artemis.setServerUrl', async () => {
413+
const config = vscode.workspace.getConfiguration(VSCODE_CONFIG.ARTEMIS_SECTION);
414+
const currentUrl = config.get<string>(VSCODE_CONFIG.SERVER_URL_KEY, '');
415+
const hasCustomCurrent = currentUrl.length > 0 && !KNOWN_SERVERS.some(s => s.url === currentUrl);
416+
417+
const items: vscode.QuickPickItem[] = [];
418+
419+
if (hasCustomCurrent) {
420+
let hostname = currentUrl;
421+
try {
422+
hostname = new URL(currentUrl).host || currentUrl;
423+
} catch {
424+
// Fall back to the raw value if it fails to parse.
425+
}
426+
items.push(
427+
{
428+
label: `Custom (${hostname})`,
429+
description: currentUrl,
430+
detail: '$(check) Currently selected',
431+
},
432+
{ label: '', kind: vscode.QuickPickItemKind.Separator },
433+
);
434+
}
435+
436+
items.push(...KNOWN_SERVERS.map(server => ({
437+
label: server.label,
438+
description: server.url,
439+
detail: server.url === currentUrl ? '$(check) Currently selected' : undefined,
440+
})));
441+
442+
items.push(
443+
{ label: '', kind: vscode.QuickPickItemKind.Separator },
444+
{ label: '$(edit) Enter custom URL...', description: 'Use your own Artemis server URL' },
445+
);
446+
447+
const selection = await vscode.window.showQuickPick(items, {
448+
title: 'Select Artemis Server',
449+
placeHolder: `Current: ${currentUrl || 'not set'}`,
450+
});
451+
452+
if (!selection) {
453+
return;
454+
}
455+
456+
let newUrl: string | undefined;
457+
458+
if (selection.label === '$(edit) Enter custom URL...') {
459+
newUrl = await vscode.window.showInputBox({
460+
title: 'Enter Custom Artemis Server URL',
461+
prompt: 'Full URL including protocol (e.g. https://artemis.example.com)',
462+
value: currentUrl,
463+
validateInput: (value) => {
464+
try {
465+
const url = new URL(value);
466+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
467+
return 'URL must start with http:// or https://';
468+
}
469+
return undefined;
470+
} catch {
471+
return 'Please enter a valid URL';
472+
}
473+
},
474+
});
475+
} else {
476+
newUrl = KNOWN_SERVERS.find(s => s.label === selection.label)?.url;
477+
}
478+
479+
if (newUrl) {
480+
newUrl = newUrl.replace(/\/+$/, '');
481+
}
482+
483+
if (newUrl && newUrl !== currentUrl) {
484+
await config.update(VSCODE_CONFIG.SERVER_URL_KEY, newUrl, vscode.ConfigurationTarget.Global);
485+
vscode.window.showInformationMessage(`Artemis server set to: ${newUrl}`);
486+
}
487+
});
488+
}
489+
399490
function registerClearTrustedDomainsCommand(context: vscode.ExtensionContext): vscode.Disposable {
400491
return vscode.commands.registerCommand('artemis.clearTrustedDomains', async () => {
401492
const result = await vscode.window.showWarningMessage(
@@ -497,6 +588,7 @@ export function registerAllCommands(deps: CommandDeps): vscode.Disposable {
497588
registerConnectWebSocketCommand(deps.authManager, deps.artemisWebsocketService),
498589
registerPlantUmlRenderCommand(deps.artemisApiService),
499590
registerGoToSourceErrorCommand(),
591+
registerSetServerUrlCommand(),
500592
registerClearTrustedDomainsCommand(deps.context),
501593
registerStruggleScoreCommand(deps.telemetryManager),
502594
registerReplaySessionCommand(deps.context.globalStorageUri),

0 commit comments

Comments
 (0)