Use contributes jsonValidation instead

This commit is contained in:
Nora
2022-11-04 11:24:46 +01:00
parent 544ff89bf8
commit f6b50bb3d6
4 changed files with 12 additions and 13 deletions

View File

@@ -84,6 +84,12 @@
"editor.wordBasedSuggestions": false
}
},
"jsonValidation": [
{
"fileMatch": "workspace-databases.json",
"url": "./workspace-databases-schema.json"
}
],
"languages": [
{
"id": "ql",

View File

@@ -10,7 +10,7 @@ export class DbConfigStore extends DisposableObject {
private config: DbConfig;
private configWatcher: chokidar.FSWatcher | undefined;
public constructor(workspaceStoragePath: string, private readonly extensionPath: string) {
public constructor(workspaceStoragePath: string) {
super();
this.configPath = path.join(workspaceStoragePath, 'workspace-databases.json');
@@ -35,12 +35,7 @@ export class DbConfigStore extends DisposableObject {
private async loadConfig(): Promise<void> {
if (!await fs.pathExists(this.configPath)) {
const schemaPath = path.resolve(this.extensionPath, 'workspace-databases-schema.json');
const json = {
'$schema': `file://${schemaPath}`,
...this.createEmptyConfig()
};
await fs.writeJSON(this.configPath, json, { spaces: 2 });
await fs.writeJSON(this.configPath, this.createEmptyConfig(), { spaces: 2 });
}
await this.readConfig();

View File

@@ -22,8 +22,7 @@ export class DbModule extends DisposableObject {
void logger.log('Initializing database module');
const storagePath = extensionContext.storageUri?.fsPath || extensionContext.globalStorageUri.fsPath;
const extensionPath = extensionContext.extensionPath;
const dbConfigStore = new DbConfigStore(storagePath, extensionPath);
const dbConfigStore = new DbConfigStore(storagePath);
await dbConfigStore.initialize();
const dbManager = new DbManager(dbConfigStore);

View File

@@ -6,7 +6,6 @@ import { expect } from 'chai';
describe('db config store', async () => {
const tempWorkspaceStoragePath = path.join(__dirname, 'test-workspace');
const testDataStoragePath = path.join(__dirname, 'data');
const extensionPath = path.join(__dirname, 'data');
beforeEach(async () => {
await fs.ensureDir(tempWorkspaceStoragePath);
@@ -19,7 +18,7 @@ describe('db config store', async () => {
it('should create a new config if one does not exist', async () => {
const configPath = path.join(tempWorkspaceStoragePath, 'workspace-databases.json');
const configStore = new DbConfigStore(tempWorkspaceStoragePath, extensionPath);
const configStore = new DbConfigStore(tempWorkspaceStoragePath);
await configStore.initialize();
expect(await fs.pathExists(configPath)).to.be.true;
@@ -30,7 +29,7 @@ describe('db config store', async () => {
});
it('should load an existing config', async () => {
const configStore = new DbConfigStore(testDataStoragePath, extensionPath);
const configStore = new DbConfigStore(testDataStoragePath);
await configStore.initialize();
const config = configStore.getConfig();
@@ -45,7 +44,7 @@ describe('db config store', async () => {
});
it('should not allow modification of the config', async () => {
const configStore = new DbConfigStore(testDataStoragePath, extensionPath);
const configStore = new DbConfigStore(testDataStoragePath);
await configStore.initialize();
const config = configStore.getConfig();