Skip to content

Commit 8fc9697

Browse files
Merge pull request #88 from gjsjohnmurray/fix-87
fix #87 implement optional sorting in getServerNames
2 parents 483cee0 + 20d8593 commit 8fc9697

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/api/getServerNames.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import * as vscode from 'vscode';
22
import { ServerName } from '../extension';
33
import { serverDetail } from './getServerSummary';
44

5-
export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[] {
5+
export function getServerNames(scope?: vscode.ConfigurationScope, sorted?: boolean): ServerName[] {
6+
const allNames: ServerName[] = [];
67
let names: ServerName[] = [];
7-
let defaultNames: ServerName[] = [];
8+
const embeddedNames: ServerName[] = [];
89
const servers = vscode.workspace.getConfiguration('intersystems', scope).get('servers');
910

1011
if (typeof servers === 'object' && servers) {
@@ -18,7 +19,7 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[]
1819
const inspectedDefault = vscode.workspace.getConfiguration('intersystems.servers', scope).inspect('/default');
1920
const myDefault: string = notSet(inspectedDefault) ? '' : servers['/default'] || '';
2021
if (myDefault.length > 0 && servers[myDefault]) {
21-
names.push({
22+
allNames.push({
2223
name: myDefault,
2324
description: `${servers[myDefault].description || ''} (default)`.trim(),
2425
detail: serverDetail(servers[myDefault])
@@ -32,7 +33,7 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[]
3233

3334
// Collect embedded (default~*) servers separately
3435
if (notSet(inspected)) {
35-
defaultNames.push({
36+
embeddedNames.push({
3637
name: key,
3738
description: servers[key].description || '',
3839
detail: serverDetail(servers[key])
@@ -48,9 +49,17 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[]
4849
}
4950
}
5051

52+
// If requested, sort what we found
53+
if (sorted) {
54+
names = names.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
55+
}
56+
57+
// Append them
58+
allNames.push(...names);
59+
5160
// Append the embedded servers unless suppressed
5261
if (!vscode.workspace.getConfiguration('intersystems.servers', scope).get('/hideEmbeddedEntries')) {
53-
names.push(...defaultNames);
62+
allNames.push(...embeddedNames);
5463
}
55-
return names;
64+
return allNames;
5665
}

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ export function activate(context: vscode.ExtensionContext) {
280280
async pickServer(scope?: vscode.ConfigurationScope, options: vscode.QuickPickOptions = {}): Promise<string | undefined> {
281281
return await pickServer(scope, options);
282282
},
283-
getServerNames(scope?: vscode.ConfigurationScope): ServerName[] {
284-
return getServerNames(scope);
283+
284+
getServerNames(scope?: vscode.ConfigurationScope, sorted?: boolean): ServerName[] {
285+
return getServerNames(scope, sorted);
285286
},
286287

287288
getServerSummary(name: string, scope?: vscode.ConfigurationScope): ServerName | undefined {

src/ui/serverManagerView.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ export class SMTreeItem extends vscode.TreeItem {
216216
function allServers(treeItem: SMTreeItem, params?: any): ServerTreeItem[] {
217217
const children: ServerTreeItem[] = [];
218218
const getAllServers = (sorted?: boolean): ServerTreeItem[] => {
219-
let serverNames = getServerNames();
220-
if (sorted) {
221-
serverNames = serverNames.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
222-
}
219+
let serverNames = getServerNames(undefined, sorted);
223220
return serverNames.map((serverName) => {
224221
return new ServerTreeItem({ label: serverName.name, id:serverName.name, parent: treeItem }, serverName);
225222
})

0 commit comments

Comments
 (0)