Hide DB panel UI actions when config is broken/undefined (#1866)
This commit is contained in:
@@ -780,7 +780,7 @@
|
||||
},
|
||||
{
|
||||
"command": "codeQLDatabasesExperimental.addNewList",
|
||||
"when": "view == codeQLDatabasesExperimental",
|
||||
"when": "view == codeQLDatabasesExperimental && codeQLDatabasesExperimental.configError == false",
|
||||
"group": "navigation"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user