Skip to content

Commit

Permalink
3 nit
Browse files Browse the repository at this point in the history
Signed-off-by: wthrajat <rajatkhanduri290102@gmail.com>
  • Loading branch information
wthrajat committed Jul 1, 2024
1 parent a686110 commit 0a25386
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 38 deletions.
85 changes: 48 additions & 37 deletions language-server/src/features/document-settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { ConfigurationRequest, DidChangeTextDocumentNotification, PublishDiagnosticsNotification } from "vscode-languageserver/node";
import {
ConfigurationRequest,
DidChangeTextDocumentNotification,
PublishDiagnosticsNotification
} from "vscode-languageserver";
import { getTestClient, closeDocument, initializeServer, openDocument } from "../test-utils.js";
getTestClient,
closeDocument,
initializeServer,
openDocument
} from "../test-utils.js";
import documentSettings from "./document-settings.js";
import schemaRegistry from "./schema-registry.js";
import workspace from "./workspace.js";
import validationErrorsFeature from "./validation-errors.js";

import type { Connection, Diagnostic } from "vscode-languageserver";


describe("Feature - Document Settings", () => {
let client: Connection;
let documentUri: string;
let client;
let documentUri;

beforeAll(async () => {
client = getTestClient([
Expand All @@ -34,86 +33,98 @@ describe("Feature - Document Settings", () => {
});

test("test default dialect", async () => {
documentUri = await openDocument(client, "./subject.schema.json", `{}`);
documentUri = "file://path/to/workspace/subjectA.schema.json";
await openDocument(client, documentUri, {});

const diagnosticsPromise = new Promise<Diagnostic[]>((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
const diagnosticsPromise = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification, (params) => {
resolve(params.diagnostics);
});
});

await client.sendNotification(DidChangeTextDocumentNotification.type, {
textDocument: { uri: documentUri, version: 1 },
const params = {
textDocument: { uri: documentUri },
contentChanges: []
});
};

await client.sendNotification(DidChangeTextDocumentNotification, params);

const diagnostics = await diagnosticsPromise;
expect(diagnostics).to.eql([]);
});

test("test no dialect", async () => {
documentUri = await openDocument(client, "./subject.schema.json", `{}`);
documentUri = "file://path/to/workspace/subjectB.schema.json";
await openDocument(client, documentUri, {});

client.onRequest(ConfigurationRequest.type, () => {
await client.onRequest(ConfigurationRequest, () => {
return [{}];
});

const diagnosticsPromise = new Promise<Diagnostic[]>((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
const diagnosticsPromise = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification, (params) => {
resolve(params.diagnostics);
});
});

await client.sendNotification(DidChangeTextDocumentNotification.type, {
textDocument: { uri: documentUri, version: 1 },
const params = {
textDocument: { uri: documentUri },
contentChanges: []
});
};

await client.sendNotification(DidChangeTextDocumentNotification, params);

const diagnostics = await diagnosticsPromise;
expect(diagnostics[0].message).to.eql("No dialect");
});

test("test unknown dialect", async () => {
documentUri = await openDocument(client, "./subject.schema.json", `{ "$schema": "" }`);
documentUri = "file://path/to/workspace/subjectC.schema.json";
await openDocument(client, documentUri, {"$schema":""});

client.onRequest(ConfigurationRequest.type, () => {
await client.onRequest(ConfigurationRequest, () => {
return [{}];
});

const diagnosticsPromise = new Promise<Diagnostic[]>((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
const diagnosticsPromise = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification, (params) => {
resolve(params.diagnostics);
});
});

await client.sendNotification(DidChangeTextDocumentNotification.type, {
textDocument: { uri: documentUri, version: 1 },
const params = {
textDocument: { uri: documentUri },
contentChanges: []
});
};

await client.sendNotification(DidChangeTextDocumentNotification, params);

const diagnostics = await diagnosticsPromise;
expect(diagnostics[0].message).to.eql("Unknown dialect");
});

test("test unknown dialect when default dialect is unknown", async () => {
documentUri = await openDocument(client, "./subject.schema.json", `{}`);
documentUri = "file://path/to/workspace/subjectD.schema.json";
await openDocument(client, documentUri, {});

client.onRequest(ConfigurationRequest.type, () => {
await client.onRequest(ConfigurationRequest, () => {
return [{ "defaultDialect": "" }];
});

const diagnosticsPromise = new Promise<Diagnostic[]>((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
const diagnosticsPromise = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification, (params) => {
resolve(params.diagnostics);
});
});

await client.sendNotification(DidChangeTextDocumentNotification.type, {
textDocument: { uri: documentUri, version: 1 },
const params = {
textDocument: { uri: documentUri },
contentChanges: []
});
};

await client.sendNotification(DidChangeTextDocumentNotification, params);

const diagnostics = await diagnosticsPromise;
expect(diagnostics[0].message).to.eql("Unknown dialect");
});
});
});
2 changes: 1 addition & 1 deletion language-server/src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const initializeServer = async (client: Connection, initParams: Partial<I
};

export const openDocument = async (client: Connection, uri: string, text?: string) => {
const baseUri = `file:///${randomUUID()}/`;
const baseUri = pathToFileURL(`/${randomUUID()}/`).toString();
const documentUri = resolveIri(uri, baseUri);

await client.sendNotification(DidOpenTextDocumentNotification.type, {
Expand Down

0 comments on commit 0a25386

Please sign in to comment.