Skip to content

Commit 3bb10d8

Browse files
authored
Add button to open database config from the new databases UI (#1719)
1 parent 3f001c9 commit 3bb10d8

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

extensions/ql-vscode/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,14 @@
360360
"command": "codeQL.copyVersion",
361361
"title": "CodeQL: Copy Version Information"
362362
},
363+
{
364+
"command": "codeQLDatabasesExperimental.openConfigFile",
365+
"title": "Open Database Configuration File",
366+
"icon": {
367+
"light": "media/light/edit.svg",
368+
"dark": "media/dark/edit.svg"
369+
}
370+
},
363371
{
364372
"command": "codeQLDatabases.chooseDatabaseFolder",
365373
"title": "Choose Database from Folder",
@@ -758,6 +766,11 @@
758766
"command": "codeQLEvalLogViewer.clear",
759767
"when": "view == codeQLEvalLogViewer",
760768
"group": "navigation"
769+
},
770+
{
771+
"command": "codeQLDatabasesExperimental.openConfigFile",
772+
"when": "view == codeQLDatabasesExperimental",
773+
"group": "navigation"
761774
}
762775
],
763776
"view/item/context": [
@@ -976,6 +989,10 @@
976989
"command": "codeQL.chooseDatabaseLgtm",
977990
"when": "config.codeQL.canary"
978991
},
992+
{
993+
"command": "codeQLDatabasesExperimental.openConfigFile",
994+
"when": "false"
995+
},
979996
{
980997
"command": "codeQLDatabases.setCurrentDatabase",
981998
"when": "false"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export class DbConfigStore extends DisposableObject {
3333
return cloneDbConfig(this.config);
3434
}
3535

36+
public getConfigPath(): string {
37+
return this.configPath;
38+
}
39+
3640
private async loadConfig(): Promise<void> {
3741
if (!await fs.pathExists(this.configPath)) {
3842
await fs.writeJSON(this.configPath, this.createEmptyConfig(), { spaces: 2 });

extensions/ql-vscode/src/databases/db-manager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ export class DbManager {
1616
createLocalTree()
1717
];
1818
}
19+
20+
public getConfigPath(): string {
21+
return this.dbConfigStore.getConfigPath();
22+
}
1923
}

extensions/ql-vscode/src/databases/db-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export class DbModule extends DisposableObject {
2727

2828
const dbManager = new DbManager(dbConfigStore);
2929
const dbPanel = new DbPanel(dbManager);
30+
await dbPanel.initialize();
31+
extensionContext.subscriptions.push(dbPanel);
3032

3133
this.push(dbPanel);
3234
this.push(dbConfigStore);

extensions/ql-vscode/src/databases/ui/db-panel.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode';
2+
import { commandRunner } from '../../commandRunner';
23
import { DisposableObject } from '../../pure/disposable-object';
34
import { DbManager } from '../db-manager';
45
import { DbTreeDataProvider } from './db-tree-data-provider';
@@ -7,7 +8,7 @@ export class DbPanel extends DisposableObject {
78
private readonly dataProvider: DbTreeDataProvider;
89

910
public constructor(
10-
dbManager: DbManager
11+
private readonly dbManager: DbManager
1112
) {
1213
super();
1314

@@ -20,4 +21,19 @@ export class DbPanel extends DisposableObject {
2021

2122
this.push(treeView);
2223
}
24+
25+
public async initialize(): Promise<void> {
26+
this.push(
27+
commandRunner(
28+
'codeQLDatabasesExperimental.openConfigFile',
29+
() => this.openConfigFile(),
30+
)
31+
);
32+
}
33+
34+
private async openConfigFile(): Promise<void> {
35+
const configPath = this.dbManager.getConfigPath();
36+
const document = await vscode.workspace.openTextDocument(configPath);
37+
await vscode.window.showTextDocument(document);
38+
}
2339
}

extensions/ql-vscode/test/pure-tests/command-lint.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('commands declared in package.json', function() {
3939
}
4040
else if (
4141
command.match(/^codeQLDatabases\./)
42+
|| command.match(/^codeQLDatabasesExperimental\./)
4243
|| command.match(/^codeQLQueryHistory\./)
4344
|| command.match(/^codeQLAstViewer\./)
4445
|| command.match(/^codeQLEvalLogViewer\./)

0 commit comments

Comments
 (0)