Add button to open database config from the new databases UI (#1719)

This commit is contained in:
Shati Patel
2022-11-07 13:24:15 +00:00
committed by GitHub
parent 3f001c981d
commit 3bb10d8c6e
6 changed files with 45 additions and 1 deletions

View File

@@ -360,6 +360,14 @@
"command": "codeQL.copyVersion",
"title": "CodeQL: Copy Version Information"
},
{
"command": "codeQLDatabasesExperimental.openConfigFile",
"title": "Open Database Configuration File",
"icon": {
"light": "media/light/edit.svg",
"dark": "media/dark/edit.svg"
}
},
{
"command": "codeQLDatabases.chooseDatabaseFolder",
"title": "Choose Database from Folder",
@@ -758,6 +766,11 @@
"command": "codeQLEvalLogViewer.clear",
"when": "view == codeQLEvalLogViewer",
"group": "navigation"
},
{
"command": "codeQLDatabasesExperimental.openConfigFile",
"when": "view == codeQLDatabasesExperimental",
"group": "navigation"
}
],
"view/item/context": [
@@ -976,6 +989,10 @@
"command": "codeQL.chooseDatabaseLgtm",
"when": "config.codeQL.canary"
},
{
"command": "codeQLDatabasesExperimental.openConfigFile",
"when": "false"
},
{
"command": "codeQLDatabases.setCurrentDatabase",
"when": "false"

View File

@@ -33,6 +33,10 @@ export class DbConfigStore extends DisposableObject {
return cloneDbConfig(this.config);
}
public getConfigPath(): string {
return this.configPath;
}
private async loadConfig(): Promise<void> {
if (!await fs.pathExists(this.configPath)) {
await fs.writeJSON(this.configPath, this.createEmptyConfig(), { spaces: 2 });

View File

@@ -16,4 +16,8 @@ export class DbManager {
createLocalTree()
];
}
public getConfigPath(): string {
return this.dbConfigStore.getConfigPath();
}
}

View File

@@ -27,6 +27,8 @@ export class DbModule extends DisposableObject {
const dbManager = new DbManager(dbConfigStore);
const dbPanel = new DbPanel(dbManager);
await dbPanel.initialize();
extensionContext.subscriptions.push(dbPanel);
this.push(dbPanel);
this.push(dbConfigStore);

View File

@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import { commandRunner } from '../../commandRunner';
import { DisposableObject } from '../../pure/disposable-object';
import { DbManager } from '../db-manager';
import { DbTreeDataProvider } from './db-tree-data-provider';
@@ -7,7 +8,7 @@ export class DbPanel extends DisposableObject {
private readonly dataProvider: DbTreeDataProvider;
public constructor(
dbManager: DbManager
private readonly dbManager: DbManager
) {
super();
@@ -20,4 +21,19 @@ export class DbPanel extends DisposableObject {
this.push(treeView);
}
public async initialize(): Promise<void> {
this.push(
commandRunner(
'codeQLDatabasesExperimental.openConfigFile',
() => this.openConfigFile(),
)
);
}
private async openConfigFile(): Promise<void> {
const configPath = this.dbManager.getConfigPath();
const document = await vscode.workspace.openTextDocument(configPath);
await vscode.window.showTextDocument(document);
}
}

View File

@@ -39,6 +39,7 @@ describe('commands declared in package.json', function() {
}
else if (
command.match(/^codeQLDatabases\./)
|| command.match(/^codeQLDatabasesExperimental\./)
|| command.match(/^codeQLQueryHistory\./)
|| command.match(/^codeQLAstViewer\./)
|| command.match(/^codeQLEvalLogViewer\./)