Skip to content

Commit

Permalink
Merge pull request #65 from gjsjohnmurray/fix-64
Browse files Browse the repository at this point in the history
fix #64 Add '/hideEmbeddedEntries' boolean to 'intersystems.servers'
Also fixes '/default'
  • Loading branch information
gjsjohnmurray authored Jan 28, 2021
2 parents 08e5ed6 + bd195a2 commit 02591a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@
"properties": {
"/default": {
"type": "string",
"description": "Name of the default server."
"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
23 changes: 18 additions & 5 deletions src/api/getServerNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,30 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[]
const servers = vscode.workspace.getConfiguration('intersystems', scope).get('servers');

if (typeof servers === 'object' && servers) {
const myDefault: string = vscode.workspace.getConfiguration('intersystems.servers', scope).inspect('/default')?.defaultValue ? '' : servers['/default'] || '';

// 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 (myDefault.length > 0 && servers[myDefault]) {
names.push({
name: myDefault,
description: `${servers[myDefault].description || ''} (default)`,
detail: serverDetail(servers[myDefault])
});
}

// Process the rest
for (const key in servers) {
if (!key.startsWith('/') && key !== myDefault) {
const inspected = vscode.workspace.getConfiguration('intersystems.servers', scope).inspect(key);

// At least in VS Code 1.49 the defaultValue unexpectedly returns undefined
// even for keys that are defined in package.json as defaults. So we have to check negatively all the other possibilities.
if (!inspected?.globalLanguageValue && !inspected?.globalValue && !inspected?.workspaceFolderLanguageValue && !inspected?.workspaceFolderValue && !inspected?.workspaceLanguageValue && !inspected?.workspaceValue) {
// Collect embedded (default~*) servers separately
if (notSet(inspected)) {
defaultNames.push({
name: key,
description: servers[key].description || '',
Expand All @@ -37,7 +46,11 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[]
}
}
}
names.push(...defaultNames);

// Append the embedded servers unless suppressed
if (!vscode.workspace.getConfiguration('intersystems.servers', scope).get('/hideEmbeddedEntries')) {
names.push(...defaultNames);
}
return names;
}

Expand Down

0 comments on commit 02591a3

Please sign in to comment.