Hide DB panel UI actions when config is broken/undefined (#1866)

This commit is contained in:
Shati Patel
2022-12-15 10:50:13 +00:00
committed by GitHub
parent 091d793f13
commit 18423ca518
2 changed files with 32 additions and 5 deletions

View File

@@ -780,7 +780,7 @@
},
{
"command": "codeQLDatabasesExperimental.addNewList",
"when": "view == codeQLDatabasesExperimental",
"when": "view == codeQLDatabasesExperimental && codeQLDatabasesExperimental.configError == false",
"group": "navigation"
}
],

View File

@@ -28,7 +28,7 @@ export class DbConfigStore extends DisposableObject {
private configErrors: DbConfigValidationError[];
private configWatcher: chokidar.FSWatcher | undefined;
public constructor(app: App) {
public constructor(private readonly app: App) {
super();
const storagePath = app.workspaceStoragePath || app.globalStoragePath;
@@ -147,13 +147,27 @@ export class DbConfigStore extends DisposableObject {
message: `Failed to read config file: ${this.configPath}`,
},
];
await this.app.executeCommand(
"setContext",
"codeQLDatabasesExperimental.configError",
true,
);
}
if (newConfig) {
this.configErrors = this.configValidator.validate(newConfig);
}
this.config = this.configErrors.length === 0 ? newConfig : undefined;
if (this.configErrors.length === 0) {
this.config = newConfig;
await this.app.executeCommand(
"setContext",
"codeQLDatabasesExperimental.configError",
false,
);
} else {
this.config = undefined;
}
}
private readConfigSync(): void {
@@ -167,14 +181,27 @@ export class DbConfigStore extends DisposableObject {
message: `Failed to read config file: ${this.configPath}`,
},
];
void this.app.executeCommand(
"setContext",
"codeQLDatabasesExperimental.configError",
true,
);
}
if (newConfig) {
this.configErrors = this.configValidator.validate(newConfig);
}
this.config = this.configErrors.length === 0 ? newConfig : undefined;
if (this.configErrors.length === 0) {
this.config = newConfig;
void this.app.executeCommand(
"setContext",
"codeQLDatabasesExperimental.configError",
false,
);
} else {
this.config = undefined;
}
this.onDidChangeConfigEventEmitter.fire();
}