Call db config and initialize with extension path
This commit is contained in:
@@ -10,8 +10,9 @@ export class DbConfigStore extends DisposableObject {
|
|||||||
private config: DbConfig;
|
private config: DbConfig;
|
||||||
private configWatcher: chokidar.FSWatcher | undefined;
|
private configWatcher: chokidar.FSWatcher | undefined;
|
||||||
|
|
||||||
public constructor(workspaceStoragePath: string) {
|
public constructor(workspaceStoragePath: string, private readonly extensionPath: string) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.configPath = path.join(workspaceStoragePath, 'workspace-databases.json');
|
this.configPath = path.join(workspaceStoragePath, 'workspace-databases.json');
|
||||||
|
|
||||||
this.config = this.createEmptyConfig();
|
this.config = this.createEmptyConfig();
|
||||||
@@ -34,7 +35,13 @@ export class DbConfigStore extends DisposableObject {
|
|||||||
|
|
||||||
private async loadConfig(): Promise<void> {
|
private async loadConfig(): Promise<void> {
|
||||||
if (!await fs.pathExists(this.configPath)) {
|
if (!await fs.pathExists(this.configPath)) {
|
||||||
await fs.writeJSON(this.configPath, this.createEmptyConfig(), { spaces: 2 });
|
const schemaPath = path.resolve(this.extensionPath, 'workspace-databases-schema.json');
|
||||||
|
await fs.writeJSON(this.configPath, fs.readJson(schemaPath), {});
|
||||||
|
const json = {
|
||||||
|
'$schema': `file://${schemaPath}`,
|
||||||
|
...this.createEmptyConfig()
|
||||||
|
};
|
||||||
|
await fs.writeJSON(this.configPath, json, { spaces: 2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.readConfig();
|
await this.readConfig();
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ import { createVariantAnalysisContentProvider } from './remote-queries/variant-a
|
|||||||
import { VSCodeMockGitHubApiServer } from './mocks/vscode-mock-gh-api-server';
|
import { VSCodeMockGitHubApiServer } from './mocks/vscode-mock-gh-api-server';
|
||||||
import { VariantAnalysisResultsManager } from './remote-queries/variant-analysis-results-manager';
|
import { VariantAnalysisResultsManager } from './remote-queries/variant-analysis-results-manager';
|
||||||
import { initializeDbModule } from './databases/db-module';
|
import { initializeDbModule } from './databases/db-module';
|
||||||
|
import { DbConfigStore } from './databases/db-config-store';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* extension.ts
|
* extension.ts
|
||||||
@@ -1225,6 +1226,11 @@ async function activateWithInstalledDistribution(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const storagePath = ctx.storageUri?.fsPath || ctx.globalStorageUri.fsPath;
|
||||||
|
const extensionPath = ctx.extensionPath;
|
||||||
|
const dbConfigStore = new DbConfigStore(storagePath, extensionPath);
|
||||||
|
await dbConfigStore.initialize();
|
||||||
|
|
||||||
await commands.executeCommand('codeQLDatabases.removeOrphanedDatabases');
|
await commands.executeCommand('codeQLDatabases.removeOrphanedDatabases');
|
||||||
|
|
||||||
void logger.log('Reading query history');
|
void logger.log('Reading query history');
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { expect } from 'chai';
|
|||||||
describe('db config store', async () => {
|
describe('db config store', async () => {
|
||||||
const tempWorkspaceStoragePath = path.join(__dirname, 'test-workspace');
|
const tempWorkspaceStoragePath = path.join(__dirname, 'test-workspace');
|
||||||
const testDataStoragePath = path.join(__dirname, 'data');
|
const testDataStoragePath = path.join(__dirname, 'data');
|
||||||
|
const extensionPath = path.join(__dirname, 'data');
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fs.ensureDir(tempWorkspaceStoragePath);
|
await fs.ensureDir(tempWorkspaceStoragePath);
|
||||||
@@ -18,7 +19,7 @@ describe('db config store', async () => {
|
|||||||
it('should create a new config if one does not exist', async () => {
|
it('should create a new config if one does not exist', async () => {
|
||||||
const configPath = path.join(tempWorkspaceStoragePath, 'workspace-databases.json');
|
const configPath = path.join(tempWorkspaceStoragePath, 'workspace-databases.json');
|
||||||
|
|
||||||
const configStore = new DbConfigStore(tempWorkspaceStoragePath);
|
const configStore = new DbConfigStore(tempWorkspaceStoragePath, extensionPath);
|
||||||
await configStore.initialize();
|
await configStore.initialize();
|
||||||
|
|
||||||
expect(await fs.pathExists(configPath)).to.be.true;
|
expect(await fs.pathExists(configPath)).to.be.true;
|
||||||
@@ -29,7 +30,7 @@ describe('db config store', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should load an existing config', async () => {
|
it('should load an existing config', async () => {
|
||||||
const configStore = new DbConfigStore(testDataStoragePath);
|
const configStore = new DbConfigStore(testDataStoragePath, extensionPath);
|
||||||
await configStore.initialize();
|
await configStore.initialize();
|
||||||
|
|
||||||
const config = configStore.getConfig();
|
const config = configStore.getConfig();
|
||||||
@@ -44,7 +45,7 @@ describe('db config store', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not allow modification of the config', async () => {
|
it('should not allow modification of the config', async () => {
|
||||||
const configStore = new DbConfigStore(testDataStoragePath);
|
const configStore = new DbConfigStore(testDataStoragePath, extensionPath);
|
||||||
await configStore.initialize();
|
await configStore.initialize();
|
||||||
|
|
||||||
const config = configStore.getConfig();
|
const config = configStore.getConfig();
|
||||||
|
|||||||
Reference in New Issue
Block a user