Skip to content

Commit 5af40d1

Browse files
authored
Enable the HTTP resolver in all tabs (#115)
Fixes: #103 Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent ea33529 commit 5af40d1

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

test/vscode/extension.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as assert from 'assert';
22
import * as vscode from 'vscode';
3+
import * as path from 'path';
34
import testSchema from './fixtures/test-schema.json';
45

56
suite('Extension Test Suite', () => {
@@ -120,4 +121,28 @@ suite('Extension Test Suite', () => {
120121
assert.ok(extension, 'Extension should exist');
121122
assert.ok(extension?.isActive, 'Extension should remain active with no file selected');
122123
});
124+
125+
test('Should handle schema with HTTP $ref without errors', async function() {
126+
this.timeout(30000);
127+
128+
const extension = vscode.extensions.getExtension('sourcemeta.sourcemeta-studio');
129+
if (extension && !extension.isActive) {
130+
await extension.activate();
131+
}
132+
133+
const fixtureDir = path.join(__dirname, '..', '..', '..', 'test', 'vscode', 'fixtures');
134+
const schemaPath = path.join(fixtureDir, 'geojson-ref-schema.json');
135+
136+
const document = await vscode.workspace.openTextDocument(vscode.Uri.file(schemaPath));
137+
await vscode.window.showTextDocument(document);
138+
139+
await vscode.commands.executeCommand('sourcemeta-studio.openPanel');
140+
141+
await new Promise(resolve => setTimeout(resolve, 10000));
142+
143+
const diagnostics = vscode.languages.getDiagnostics(document.uri);
144+
assert.strictEqual(diagnostics.length, 0, 'Schema with HTTP $ref should have no diagnostic errors');
145+
146+
assert.ok(extension?.isActive, 'Extension should remain active after processing HTTP $ref');
147+
});
123148
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://example.com/test-geojson-ref",
4+
"title": "Test Schema with HTTP Reference",
5+
"type": "object",
6+
"properties": {
7+
"location": {
8+
"$ref": "https://schemas.sourcemeta.com/geojson/v1.0.0/geojson.json"
9+
}
10+
}
11+
}

vscode/src/commands/CommandExecutor.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@ export class CommandExecutor {
6666
/**
6767
* Run lint command on a file
6868
*/
69-
async lint(filePath: string): Promise<string> {
69+
async lint(filePath: string, useHttp: boolean = true): Promise<string> {
7070
try {
71-
const result = await this.executeCommand(['lint', '--json', filePath]);
71+
const args = ['lint', '--json'];
72+
if (useHttp) {
73+
args.push('--http');
74+
}
75+
args.push(filePath);
76+
const result = await this.executeCommand(args);
7277
return result.output;
7378
} catch (error) {
7479
throw error;
@@ -78,9 +83,14 @@ export class CommandExecutor {
7883
/**
7984
* Run format check command on a file
8085
*/
81-
async formatCheck(filePath: string): Promise<CommandResult> {
86+
async formatCheck(filePath: string, useHttp: boolean = true): Promise<CommandResult> {
8287
try {
83-
return await this.executeCommand(['fmt', '--check', '--json', filePath]);
88+
const args = ['fmt', '--check', '--json'];
89+
if (useHttp) {
90+
args.push('--http');
91+
}
92+
args.push(filePath);
93+
return await this.executeCommand(args);
8494
} catch (error) {
8595
throw error;
8696
}
@@ -89,8 +99,13 @@ export class CommandExecutor {
8999
/**
90100
* Run format command on a file
91101
*/
92-
async format(filePath: string): Promise<void> {
93-
const result = await this.executeCommand(['fmt', '--json', filePath]);
102+
async format(filePath: string, useHttp: boolean = true): Promise<void> {
103+
const args = ['fmt', '--json'];
104+
if (useHttp) {
105+
args.push('--http');
106+
}
107+
args.push(filePath);
108+
const result = await this.executeCommand(args);
94109
if (result.exitCode !== 0) {
95110
try {
96111
const errorObj = JSON.parse(result.output);

0 commit comments

Comments
 (0)