Calculate hidden configuration keys using package.json

This commit is contained in:
Andrew Eisenberg
2022-10-19 11:18:04 -07:00
parent c85ef15d9e
commit 7637f9428a
2 changed files with 26 additions and 8 deletions

View File

@@ -10,14 +10,21 @@ export const ALL_SETTINGS: Setting[] = [];
export class Setting {
name: string;
parent?: Setting;
private _hasChildren = false;
constructor(name: string, parent?: Setting, public readonly isHidden = false) {
constructor(name: string, parent?: Setting) {
this.name = name;
this.parent = parent;
if (parent !== undefined) {
parent._hasChildren = true;
}
ALL_SETTINGS.push(this);
}
get hasChildren() {
return this._hasChildren;
}
get qualifiedName(): string {
if (this.parent === undefined) {
return this.name;
@@ -328,7 +335,7 @@ export function isQuickEvalCodelensEnabled() {
/**
* Enables canary features of this extension. Recommended for all internal users.
*/
export const CANARY_FEATURES = new Setting('canary', ROOT_SETTING, true);
export const CANARY_FEATURES = new Setting('canary', ROOT_SETTING);
export function isCanary() {
return !!CANARY_FEATURES.getValue<boolean>();
@@ -337,7 +344,7 @@ export function isCanary() {
/**
* Enables the experimental query server
*/
export const CANARY_QUERY_SERVER = new Setting('canaryQueryServer', ROOT_SETTING, true);
export const CANARY_QUERY_SERVER = new Setting('canaryQueryServer', ROOT_SETTING);
export function allowCanaryQueryServer() {

View File

@@ -1,3 +1,5 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import { ConfigurationTarget } from 'vscode';
import { ALL_SETTINGS, InspectionResult, Setting } from '../config';
@@ -59,12 +61,21 @@ class TestSetting<T> {
}
}
// Public configuration keys are the ones defined in the package.json.
// These keys are documented in the settings page. Other keys are
// internal and not documented.
const PKG_CONFIGURATION: Record<string, any> = (function initConfigurationKeys() {
// Note we are using synchronous file reads here. This is fine because
// we are in tests.
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8'));
return pkg.contributes.configuration.properties;
}());
// The test settings are all settings in ALL_SETTINGS which don't have any children
// and are also not hiddent settings like the Canary setting.
// and are also not hidden settings like the codeQL.canary.
const TEST_SETTINGS = ALL_SETTINGS
.filter(setting => !setting.isHidden &&
ALL_SETTINGS.filter(s =>
s.parent === setting).length === 0)
.filter(setting => (setting.qualifiedName in PKG_CONFIGURATION) && !setting.hasChildren)
.map(setting => new TestSetting(setting));
export const getTestSetting = (setting: Setting): TestSetting<unknown> | undefined => {