Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
"smoke-test": "npm run test-compile && vscode-test smoke-test/*",
"compile-smoke-test-web": "webpack --config smoke-test/webpack.config",
"smoke-test-web": "npm run compile-smoke-test-web && vscode-test-web --extensionDevelopmentPath=. --extensionTestsPath=./out/smoke-test/smoke-test-runner.js ./smoke-test",
"run-in-chromium": "npm run compile && vscode-test-web --browserType=chromium --extensionDevelopmentPath=. ."
"run-in-chromium": "npm run compile && vscode-test-web --browserType=chromium --extensionDevelopmentPath=. smoke-test"
},
"devDependencies": {
"@types/chai": "^4.2.12",
Expand Down
5 changes: 5 additions & 0 deletions smoke-test/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"yaml.schemas": {
"dressSize.json": "references-schema-settings.yaml"
}
}
2 changes: 2 additions & 0 deletions smoke-test/references-schema-settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dress:
size: -2
19 changes: 18 additions & 1 deletion smoke-test/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ suite('Smoke test suite', function () {
const DIAGNOSTICS_DELAY = 4_000;

const SCHEMA_INSTANCE_NAME = 'references-schema.yaml';
const THROUGH_SETTINGS_NAME = 'references-schema-settings.yaml';

let schemaInstanceUri: URI;
let throughSettingsUri: URI;

this.beforeAll(async function () {
const workspaceUri = vscode.workspace.workspaceFolders[0].uri;
schemaInstanceUri = workspaceUri.with({ path: workspaceUri.path + (workspaceUri.path.endsWith('/') ? '' : '/') + SCHEMA_INSTANCE_NAME });
schemaInstanceUri = workspaceUri.with({
path: workspaceUri.path + (workspaceUri.path.endsWith('/') ? '' : '/') + SCHEMA_INSTANCE_NAME,
});
throughSettingsUri = workspaceUri.with({
path: workspaceUri.path + (workspaceUri.path.endsWith('/') ? '' : '/') + THROUGH_SETTINGS_NAME,
});
});

test('instance has right diagnostics', async function () {
Expand All @@ -26,4 +33,14 @@ suite('Smoke test suite', function () {
assert.strictEqual(diagnostics.length, 1);
assert.strictEqual(diagnostics[0].message, 'Value is below the minimum of 0.');
});

test('has right diagnostics when schema is referenced through settings', async function () {
const textDocument = await vscode.workspace.openTextDocument(throughSettingsUri);
await vscode.window.showTextDocument(textDocument);
await new Promise((resolve) => setTimeout(resolve, DIAGNOSTICS_DELAY));
const diagnostics = vscode.languages.getDiagnostics(throughSettingsUri);

assert.strictEqual(diagnostics.length, 1);
assert.strictEqual(diagnostics[0].message, 'Value is below the minimum of 0.');
});
});
14 changes: 13 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import { workspace, ExtensionContext, extensions, window, commands, Uri, l10n } from 'vscode';
import { workspace, ExtensionContext, extensions, window, commands, Uri } from 'vscode';
import {
CommonLanguageClient,
LanguageClientOptions,
Expand Down Expand Up @@ -67,6 +67,8 @@ namespace FSReadFile {
export const type: RequestType<string, string, {}> = new RequestType('fs/readFile');
}

export const FSReadUriType: RequestType<string, string, unknown> = new RequestType('fs/readUri');

// eslint-disable-next-line @typescript-eslint/no-namespace
namespace DynamicCustomSchemaRequestRegistration {
// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down Expand Up @@ -199,6 +201,16 @@ export function startClient(
return new TextDecoder().decode(uint8array);
}
});
client.onRequest(FSReadUriType, async (uri: string) => {
try {
const parsedUri = Uri.parse(uri);
window.showInformationMessage(`uri: ${parsedUri.toString()}`);
const uint8array = await workspace.fs.readFile(parsedUri);
return new TextDecoder().decode(uint8array);
} catch (e) {
window.showErrorMessage(`Error while retrieving content of '${uri}': ${e}`);
}
});

sendStartupTelemetryEvent(runtime.telemetry, true);
// Adapted from:
Expand Down
Loading