diff --git a/src/api/getServerNames.ts b/src/api/getServerNames.ts index e2d36cb..d1d39b6 100644 --- a/src/api/getServerNames.ts +++ b/src/api/getServerNames.ts @@ -2,9 +2,10 @@ import * as vscode from 'vscode'; import { ServerName } from '../extension'; import { serverDetail } from './getServerSummary'; -export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[] { +export function getServerNames(scope?: vscode.ConfigurationScope, sorted?: boolean): ServerName[] { + const allNames: ServerName[] = []; let names: ServerName[] = []; - let defaultNames: ServerName[] = []; + const embeddedNames: ServerName[] = []; const servers = vscode.workspace.getConfiguration('intersystems', scope).get('servers'); if (typeof servers === 'object' && servers) { @@ -18,7 +19,7 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[] const inspectedDefault = vscode.workspace.getConfiguration('intersystems.servers', scope).inspect('/default'); const myDefault: string = notSet(inspectedDefault) ? '' : servers['/default'] || ''; if (myDefault.length > 0 && servers[myDefault]) { - names.push({ + allNames.push({ name: myDefault, description: `${servers[myDefault].description || ''} (default)`.trim(), detail: serverDetail(servers[myDefault]) @@ -32,7 +33,7 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[] // Collect embedded (default~*) servers separately if (notSet(inspected)) { - defaultNames.push({ + embeddedNames.push({ name: key, description: servers[key].description || '', detail: serverDetail(servers[key]) @@ -48,9 +49,17 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[] } } + // If requested, sort what we found + if (sorted) { + names = names.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0); + } + + // Append them + allNames.push(...names); + // Append the embedded servers unless suppressed if (!vscode.workspace.getConfiguration('intersystems.servers', scope).get('/hideEmbeddedEntries')) { - names.push(...defaultNames); + allNames.push(...embeddedNames); } - return names; + return allNames; } diff --git a/src/extension.ts b/src/extension.ts index 19551c8..4239e75 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -280,8 +280,9 @@ export function activate(context: vscode.ExtensionContext) { async pickServer(scope?: vscode.ConfigurationScope, options: vscode.QuickPickOptions = {}): Promise { return await pickServer(scope, options); }, - getServerNames(scope?: vscode.ConfigurationScope): ServerName[] { - return getServerNames(scope); + + getServerNames(scope?: vscode.ConfigurationScope, sorted?: boolean): ServerName[] { + return getServerNames(scope, sorted); }, getServerSummary(name: string, scope?: vscode.ConfigurationScope): ServerName | undefined { diff --git a/src/ui/serverManagerView.ts b/src/ui/serverManagerView.ts index 943e2e5..704245e 100644 --- a/src/ui/serverManagerView.ts +++ b/src/ui/serverManagerView.ts @@ -216,10 +216,7 @@ export class SMTreeItem extends vscode.TreeItem { function allServers(treeItem: SMTreeItem, params?: any): ServerTreeItem[] { const children: ServerTreeItem[] = []; const getAllServers = (sorted?: boolean): ServerTreeItem[] => { - let serverNames = getServerNames(); - if (sorted) { - serverNames = serverNames.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0); - } + let serverNames = getServerNames(undefined, sorted); return serverNames.map((serverName) => { return new ServerTreeItem({ label: serverName.name, id:serverName.name, parent: treeItem }, serverName); })