Skip to content

Commit

Permalink
Merge pull request #208 from gjsjohnmurray/do-203
Browse files Browse the repository at this point in the history
Remove default servers and the /hideEmbedded switch
  • Loading branch information
gjsjohnmurray authored Aug 10, 2023
2 parents 20d3f62 + 1fc0d18 commit bff5b16
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 74 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ In this example two connections have been defined:
},
"description": "My local IRIS instance"
},
"/default": "my-local",
"/hideEmbeddedEntries": true
"/default": "my-local"
}
```

Expand All @@ -185,8 +184,6 @@ Notice how you can add a `description` property to each connection. This will be

Servers are displayed in the quickpick in the order they are defined in the JSON file. The exception is that if a server name is set as the value of the `/default` property (see example above) it will be shown first in the list.

A set of embedded servers with names beginning `default~` will appear at the end of the lists unless you add the property `"/hideEmbeddedEntries": true` to your `intersystems.server` object to hide them (see above).

---

## Technical Notes
Expand All @@ -197,12 +194,10 @@ These features use VS Code's extension-private global state storage. Data is not

### The 'All Servers' Folder

The `All Servers` tree respects the optional `/default` and `/hideEmbeddedEntries` settings in the `intersystems.servers` JSON.
The `All Servers` tree respects the optional `/default` setting in the `intersystems.servers` JSON.

If a server has been named in `/default` it is promoted to the top of the list, which is otherwise presented in alphabetical order.

Embedded entries (built-in default ones) are demoted to the end of the list, or omitted completely if `/hideEmbeddedEntries` is true.

---

## Information for VS Code Extension Developers - How To Leverage Server Manager
Expand Down
31 changes: 0 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,6 @@
"description": "InterSystems servers that other extensions connect to. Each property of this object names a server and holds nested properties specifying how to connect to it.",
"markdownDescription": "[InterSystems](https://www.intersystems.com) servers that other extensions connect to. Each property of this object names a server and holds nested properties specifying how to connect to it. Server names may only contain characters 'A' to 'Z', 'a' to 'z', digits, '-', '.', '_' and '~' characters.",
"scope": "resource",
"default": {
"default~iris": {
"webServer": {
"scheme": "http",
"host": "127.0.0.1",
"port": 52773
},
"description": "Connection to local InterSystems IRIS™ installed with default settings."
},
"default~cache": {
"webServer": {
"scheme": "http",
"host": "127.0.0.1",
"port": 57772
},
"description": "Connection to local InterSystems Caché installed with default settings."
},
"default~ensemble": {
"webServer": {
"scheme": "http",
"host": "127.0.0.1",
"port": 57772
},
"description": "Connection to local InterSystems Ensemble installed with default settings."
},
"/default": "default~iris"
},
"patternProperties": {
"^[a-z0-9-_~]+$": {
"type": "object",
Expand Down Expand Up @@ -237,10 +210,6 @@
"/default": {
"type": "string",
"description": "Name of the server to promote to the top of pick lists."
},
"/hideEmbeddedEntries": {
"type": "boolean",
"description": "Do not append the built-in 'default~*' server definitions to pick lists."
}
},
"additionalProperties": false
Expand Down
41 changes: 7 additions & 34 deletions src/api/getServerNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@ import { serverDetail } from "./getServerSummary";
export function getServerNames(scope?: vscode.ConfigurationScope, sorted?: boolean): IServerName[] {
const allNames: IServerName[] = [];
let names: IServerName[] = [];
const embeddedNames: IServerName[] = [];
const servers = vscode.workspace.getConfiguration("intersystems", scope).get("servers");

if (typeof servers === "object" && servers) {
// Helper function to return true iff inspected setting is not explicitly set at any level
const notSet = (inspected): boolean => {
return !inspected?.globalLanguageValue
&& !inspected?.globalValue
&& !inspected?.workspaceFolderLanguageValue
&& !inspected?.workspaceFolderValue
&& !inspected?.workspaceLanguageValue
&& !inspected?.workspaceValue;
};

// If a valid default has been explicitly nominated, add it first
const inspectedDefault = vscode.workspace.getConfiguration("intersystems.servers", scope).inspect("/default");
const myDefault: string = notSet(inspectedDefault) ? "" : servers["/default"] || "";
// If a valid default has been set, add it first
const myDefault: string = servers["/default"] || "";
if (myDefault.length > 0 && servers[myDefault]) {
allNames.push({
description: `${servers[myDefault].description || ""} (default)`.trim(),
Expand All @@ -33,22 +22,11 @@ export function getServerNames(scope?: vscode.ConfigurationScope, sorted?: boole
// Process the rest
for (const key in servers) {
if (!key.startsWith("/") && key !== myDefault) {
const inspected = vscode.workspace.getConfiguration("intersystems.servers", scope).inspect(key);

// Collect embedded (default~*) servers separately
if (notSet(inspected)) {
embeddedNames.push({
description: servers[key].description || "",
detail: serverDetail(servers[key]),
name: key,
});
} else {
names.push({
description: servers[key].description || "",
detail: serverDetail(servers[key]),
name: key,
});
}
names.push({
description: servers[key].description || "",
detail: serverDetail(servers[key]),
name: key,
});
}
}
}
Expand All @@ -60,10 +38,5 @@ export function getServerNames(scope?: vscode.ConfigurationScope, sorted?: boole

// Append them
allNames.push(...names);

// Append the embedded servers unless suppressed
if (!vscode.workspace.getConfiguration("intersystems.servers", scope).get("/hideEmbeddedEntries")) {
allNames.push(...embeddedNames);
}
return allNames;
}
43 changes: 42 additions & 1 deletion src/api/getServerSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export async function getServerSpec(
if (flushCredentialCache) {
credentialCache[name] = undefined;
}
let server: IServerSpec | undefined = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name);
// To avoid breaking existing users, continue to return a default server definition even after we dropped that feature
let server: IServerSpec | undefined = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name) || legacyEmbeddedServer(name);

// Unknown server
if (!server) {
Expand All @@ -51,3 +52,43 @@ export async function getServerSpec(
}
return server;
}

/**
* If name is one of the embedded server definitions we previously (pre-3.4.2) specified in the "default" section of the "intersystems.servers"
* object spec in package.json then return what getConfiguration() would have returned.
*
* @param name The name.
* @returns Server specification or undefined.
*/
export function legacyEmbeddedServer(name: string): IServerSpec | undefined {
return {
"default~iris": {
"name": "default~iris",
"webServer": {
"scheme": "http",
"host": "127.0.0.1",
"port": 52773
},
"description": "Connection to local InterSystems IRIS™ installed with default settings."
},
"default~cache": {
"name": "default~cache",
"webServer": {
"scheme": "http",
"host": "127.0.0.1",
"port": 57772
},
"description": "Connection to local InterSystems Caché installed with default settings."
},
"default~ensemble": {
"name": "default~ensemble",
"webServer": {
"scheme": "http",
"host": "127.0.0.1",
"port": 57772
},
"description": "Connection to local InterSystems Ensemble installed with default settings."
}
}[name];
}

4 changes: 3 additions & 1 deletion src/api/getServerSummary.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as vscode from "vscode";
import { IServerName, IServerSpec } from "@intersystems-community/intersystems-servermanager";
import { legacyEmbeddedServer } from "./getServerSpec";

export function getServerSummary(name: string, scope?: vscode.ConfigurationScope): IServerName | undefined {
const server: IServerSpec | undefined = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name);
// To avoid breaking existing users, continue to return a default server definition even after we dropped that feature
const server: IServerSpec | undefined = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name) || legacyEmbeddedServer(name);
if (!server) {
return undefined;
}
Expand Down

0 comments on commit bff5b16

Please sign in to comment.