Skip to content

Commit 7637f94

Browse files
committed
Calculate hidden configuration keys using package.json
1 parent c85ef15 commit 7637f94

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

extensions/ql-vscode/src/config.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ export const ALL_SETTINGS: Setting[] = [];
1010
export class Setting {
1111
name: string;
1212
parent?: Setting;
13+
private _hasChildren = false;
1314

14-
constructor(name: string, parent?: Setting, public readonly isHidden = false) {
15+
constructor(name: string, parent?: Setting) {
1516
this.name = name;
1617
this.parent = parent;
17-
18+
if (parent !== undefined) {
19+
parent._hasChildren = true;
20+
}
1821
ALL_SETTINGS.push(this);
1922
}
2023

24+
get hasChildren() {
25+
return this._hasChildren;
26+
}
27+
2128
get qualifiedName(): string {
2229
if (this.parent === undefined) {
2330
return this.name;
@@ -328,7 +335,7 @@ export function isQuickEvalCodelensEnabled() {
328335
/**
329336
* Enables canary features of this extension. Recommended for all internal users.
330337
*/
331-
export const CANARY_FEATURES = new Setting('canary', ROOT_SETTING, true);
338+
export const CANARY_FEATURES = new Setting('canary', ROOT_SETTING);
332339

333340
export function isCanary() {
334341
return !!CANARY_FEATURES.getValue<boolean>();
@@ -337,7 +344,7 @@ export function isCanary() {
337344
/**
338345
* Enables the experimental query server
339346
*/
340-
export const CANARY_QUERY_SERVER = new Setting('canaryQueryServer', ROOT_SETTING, true);
347+
export const CANARY_QUERY_SERVER = new Setting('canaryQueryServer', ROOT_SETTING);
341348

342349

343350
export function allowCanaryQueryServer() {

extensions/ql-vscode/src/vscode-tests/test-config.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as fs from 'fs-extra';
2+
import * as path from 'path';
13
import { ConfigurationTarget } from 'vscode';
24
import { ALL_SETTINGS, InspectionResult, Setting } from '../config';
35

@@ -59,12 +61,21 @@ class TestSetting<T> {
5961
}
6062
}
6163

64+
// Public configuration keys are the ones defined in the package.json.
65+
// These keys are documented in the settings page. Other keys are
66+
// internal and not documented.
67+
const PKG_CONFIGURATION: Record<string, any> = (function initConfigurationKeys() {
68+
// Note we are using synchronous file reads here. This is fine because
69+
// we are in tests.
70+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8'));
71+
return pkg.contributes.configuration.properties;
72+
}());
73+
74+
6275
// The test settings are all settings in ALL_SETTINGS which don't have any children
63-
// and are also not hiddent settings like the Canary setting.
76+
// and are also not hidden settings like the codeQL.canary.
6477
const TEST_SETTINGS = ALL_SETTINGS
65-
.filter(setting => !setting.isHidden &&
66-
ALL_SETTINGS.filter(s =>
67-
s.parent === setting).length === 0)
78+
.filter(setting => (setting.qualifiedName in PKG_CONFIGURATION) && !setting.hasChildren)
6879
.map(setting => new TestSetting(setting));
6980

7081
export const getTestSetting = (setting: Setting): TestSetting<unknown> | undefined => {

0 commit comments

Comments
 (0)