Skip to content

Commit fcc814c

Browse files
committed
Call db config and initialize with extension path
1 parent ea08876 commit fcc814c

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ export class DbConfigStore extends DisposableObject {
1010
private config: DbConfig;
1111
private configWatcher: chokidar.FSWatcher | undefined;
1212

13-
public constructor(workspaceStoragePath: string) {
13+
public constructor(workspaceStoragePath: string, private readonly extensionPath: string) {
1414
super();
15+
1516
this.configPath = path.join(workspaceStoragePath, 'workspace-databases.json');
1617

1718
this.config = this.createEmptyConfig();
@@ -34,7 +35,13 @@ export class DbConfigStore extends DisposableObject {
3435

3536
private async loadConfig(): Promise<void> {
3637
if (!await fs.pathExists(this.configPath)) {
37-
await fs.writeJSON(this.configPath, this.createEmptyConfig(), { spaces: 2 });
38+
const schemaPath = path.resolve(this.extensionPath, 'workspace-databases-schema.json');
39+
await fs.writeJSON(this.configPath, fs.readJson(schemaPath), {});
40+
const json = {
41+
'$schema': `file://${schemaPath}`,
42+
...this.createEmptyConfig()
43+
};
44+
await fs.writeJSON(this.configPath, json, { spaces: 2 });
3845
}
3946

4047
await this.readConfig();

extensions/ql-vscode/src/extension.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import { createVariantAnalysisContentProvider } from './remote-queries/variant-a
119119
import { VSCodeMockGitHubApiServer } from './mocks/vscode-mock-gh-api-server';
120120
import { VariantAnalysisResultsManager } from './remote-queries/variant-analysis-results-manager';
121121
import { initializeDbModule } from './databases/db-module';
122+
import { DbConfigStore } from './databases/db-config-store';
122123

123124
/**
124125
* extension.ts
@@ -1225,6 +1226,11 @@ async function activateWithInstalledDistribution(
12251226
)
12261227
);
12271228

1229+
const storagePath = ctx.storageUri?.fsPath || ctx.globalStorageUri.fsPath;
1230+
const extensionPath = ctx.extensionPath;
1231+
const dbConfigStore = new DbConfigStore(storagePath, extensionPath);
1232+
await dbConfigStore.initialize();
1233+
12281234
await commands.executeCommand('codeQLDatabases.removeOrphanedDatabases');
12291235

12301236
void logger.log('Reading query history');

extensions/ql-vscode/test/pure-tests/databases/db-config-store.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { expect } from 'chai';
66
describe('db config store', async () => {
77
const tempWorkspaceStoragePath = path.join(__dirname, 'test-workspace');
88
const testDataStoragePath = path.join(__dirname, 'data');
9+
const extensionPath = path.join(__dirname, 'data');
910

1011
beforeEach(async () => {
1112
await fs.ensureDir(tempWorkspaceStoragePath);
@@ -18,7 +19,7 @@ describe('db config store', async () => {
1819
it('should create a new config if one does not exist', async () => {
1920
const configPath = path.join(tempWorkspaceStoragePath, 'workspace-databases.json');
2021

21-
const configStore = new DbConfigStore(tempWorkspaceStoragePath);
22+
const configStore = new DbConfigStore(tempWorkspaceStoragePath, extensionPath);
2223
await configStore.initialize();
2324

2425
expect(await fs.pathExists(configPath)).to.be.true;
@@ -29,7 +30,7 @@ describe('db config store', async () => {
2930
});
3031

3132
it('should load an existing config', async () => {
32-
const configStore = new DbConfigStore(testDataStoragePath);
33+
const configStore = new DbConfigStore(testDataStoragePath, extensionPath);
3334
await configStore.initialize();
3435

3536
const config = configStore.getConfig();
@@ -44,7 +45,7 @@ describe('db config store', async () => {
4445
});
4546

4647
it('should not allow modification of the config', async () => {
47-
const configStore = new DbConfigStore(testDataStoragePath);
48+
const configStore = new DbConfigStore(testDataStoragePath, extensionPath);
4849
await configStore.initialize();
4950

5051
const config = configStore.getConfig();

0 commit comments

Comments
 (0)