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
114 changes: 3 additions & 111 deletions language-server/src/features/Hover.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, test, expect, beforeEach, afterEach } from "vitest";
import { HoverRequest, PublishDiagnosticsNotification } from "vscode-languageserver";
import { HoverRequest } from "vscode-languageserver";
import { TestClient } from "../test/TestClient.ts";

describe("Hover", () => {
Expand All @@ -16,12 +16,6 @@ describe("Hover", () => {
});

test("should return title and description on hover over a property value", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand All @@ -38,8 +32,6 @@ describe("Hover", () => {
await client.writeDocument("instance.json", instanceText);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 10 }
Expand Down Expand Up @@ -72,12 +64,6 @@ _hyperjump-json-language-server_`
});

test("should return null on hover over a property with no title or description", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand All @@ -89,8 +75,6 @@ _hyperjump-json-language-server_`
await client.writeDocument("instance.json", `{\n "$schema": "${fixtureSchemaUri}",\n "age": 30\n}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 8 }
Expand All @@ -100,12 +84,6 @@ _hyperjump-json-language-server_`
});

test("should return only title when description is absent", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand All @@ -120,8 +98,6 @@ _hyperjump-json-language-server_`
await client.writeDocument("instance.json", `{\n "$schema": "${fixtureSchemaUri}",\n "status": "active"\n}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 12 }
Expand All @@ -140,12 +116,6 @@ _hyperjump-json-language-server_`
});

test("should return only description when title is absent", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand All @@ -160,8 +130,6 @@ _hyperjump-json-language-server_`
await client.writeDocument("instance.json", `{\n "$schema": "${fixtureSchemaUri}",\n "status": "active"\n}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 12 }
Expand Down Expand Up @@ -192,12 +160,6 @@ _hyperjump-json-language-server_`
});

test("Hover should drop annotations for failing schemas", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand Down Expand Up @@ -226,8 +188,6 @@ _hyperjump-json-language-server_`
}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 10 }
Expand All @@ -248,12 +208,6 @@ _hyperjump-json-language-server_`
});

test("Hover should return all annotations if multiple are applicable at an instanceLocation", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument(
"schema.json",
`{
Expand Down Expand Up @@ -282,8 +236,6 @@ _hyperjump-json-language-server_`
}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 10 }
Expand All @@ -308,12 +260,6 @@ _hyperjump-json-language-server_`
});

test("should not duplicate annotations when the referenced schema is edited while the instance stays open", async () => {
const initialValidation: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand All @@ -327,18 +273,12 @@ _hyperjump-json-language-server_`
}`);

await client.writeDocument("instance.json", `{\n "$schema": "${fixtureSchemaUri}",\n "age": 25\n}`);
const initialValidation = client.getDiagnostics("instance.json");
const uri = await client.openDocument("instance.json");

await initialValidation;

const secondValidation: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
if (params.uri === uri) {
resolve();
}
});
});

const secondValidation = client.getDiagnostics("instance.json");
await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand Down Expand Up @@ -373,12 +313,6 @@ _hyperjump-json-language-server_`
});

test("if schema fails as a whole but a sub-schema passes then hover should return annotations for passing sub-schemas", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand All @@ -401,8 +335,6 @@ _hyperjump-json-language-server_`
}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 10 }
Expand All @@ -421,12 +353,6 @@ _hyperjump-json-language-server_`
});

test("hover with an invalid schema", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "invalid",
Expand All @@ -444,8 +370,6 @@ _hyperjump-json-language-server_`
}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 1, character: 10 }
Expand All @@ -455,12 +379,6 @@ _hyperjump-json-language-server_`
});

test("should return markdownDescription on hover when present", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand All @@ -479,8 +397,6 @@ _hyperjump-json-language-server_`
}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 10 }
Expand All @@ -501,12 +417,6 @@ _hyperjump-json-language-server_`
});

test("should prefer markdownDescription over description when both are present", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand All @@ -526,8 +436,6 @@ _hyperjump-json-language-server_`
}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 10 }
Expand All @@ -548,12 +456,6 @@ _hyperjump-json-language-server_`
});

test("should return markdownDescription when hovering over the property key", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

fixtureSchemaUri = await client.writeDocument("schema.json", `{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
Expand All @@ -571,8 +473,6 @@ _hyperjump-json-language-server_`
}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

// Hover over "name" key
const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
Expand All @@ -592,12 +492,6 @@ _hyperjump-json-language-server_`
});

test("should return markdownDescription from a dialect that includes the vscode vocabulary", async () => {
const diagnostics: Promise<void> = new Promise((resolve) => {
client.onNotification(PublishDiagnosticsNotification.type, () => {
resolve();
});
});

await client.writeDocument("meta-schema.json", `{
"$id": "https://example.com/dialect/vscode",
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand Down Expand Up @@ -632,8 +526,6 @@ _hyperjump-json-language-server_`
}`);
const uri = await client.openDocument("instance.json");

await diagnostics;

const result = await client.sendRequest(HoverRequest.type, {
textDocument: { uri },
position: { line: 2, character: 10 }
Expand Down
Loading
Loading