Skip to content

Commit 18423ca

Browse files
authored
Hide DB panel UI actions when config is broken/undefined (#1866)
1 parent 091d793 commit 18423ca

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

extensions/ql-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@
780780
},
781781
{
782782
"command": "codeQLDatabasesExperimental.addNewList",
783-
"when": "view == codeQLDatabasesExperimental",
783+
"when": "view == codeQLDatabasesExperimental && codeQLDatabasesExperimental.configError == false",
784784
"group": "navigation"
785785
}
786786
],

extensions/ql-vscode/src/databases/config/db-config-store.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class DbConfigStore extends DisposableObject {
2828
private configErrors: DbConfigValidationError[];
2929
private configWatcher: chokidar.FSWatcher | undefined;
3030

31-
public constructor(app: App) {
31+
public constructor(private readonly app: App) {
3232
super();
3333

3434
const storagePath = app.workspaceStoragePath || app.globalStoragePath;
@@ -147,13 +147,27 @@ export class DbConfigStore extends DisposableObject {
147147
message: `Failed to read config file: ${this.configPath}`,
148148
},
149149
];
150+
await this.app.executeCommand(
151+
"setContext",
152+
"codeQLDatabasesExperimental.configError",
153+
true,
154+
);
150155
}
151156

152157
if (newConfig) {
153158
this.configErrors = this.configValidator.validate(newConfig);
154159
}
155160

156-
this.config = this.configErrors.length === 0 ? newConfig : undefined;
161+
if (this.configErrors.length === 0) {
162+
this.config = newConfig;
163+
await this.app.executeCommand(
164+
"setContext",
165+
"codeQLDatabasesExperimental.configError",
166+
false,
167+
);
168+
} else {
169+
this.config = undefined;
170+
}
157171
}
158172

159173
private readConfigSync(): void {
@@ -167,14 +181,27 @@ export class DbConfigStore extends DisposableObject {
167181
message: `Failed to read config file: ${this.configPath}`,
168182
},
169183
];
184+
void this.app.executeCommand(
185+
"setContext",
186+
"codeQLDatabasesExperimental.configError",
187+
true,
188+
);
170189
}
171190

172191
if (newConfig) {
173192
this.configErrors = this.configValidator.validate(newConfig);
174193
}
175194

176-
this.config = this.configErrors.length === 0 ? newConfig : undefined;
177-
195+
if (this.configErrors.length === 0) {
196+
this.config = newConfig;
197+
void this.app.executeCommand(
198+
"setContext",
199+
"codeQLDatabasesExperimental.configError",
200+
false,
201+
);
202+
} else {
203+
this.config = undefined;
204+
}
178205
this.onDidChangeConfigEventEmitter.fire();
179206
}
180207

0 commit comments

Comments
 (0)