diff --git a/language-server/src/features/deprecated.js b/language-server/src/features/deprecated.js index bdd05f9..9accc0b 100644 --- a/language-server/src/features/deprecated.js +++ b/language-server/src/features/deprecated.js @@ -1,16 +1,18 @@ import { DiagnosticSeverity, DiagnosticTag } from "vscode-languageserver"; import * as SchemaNode from "../schema-node.js"; -import { subscribe } from "../pubsub.js"; +import { subscribe, unsubscribe } from "../pubsub.js"; /** @import { Feature } from "../build-server.js" */ const annotationDialectUri = "https://json-schema.org/draft/2020-12/schema"; +/** @type string */ +let subscriptionToken; /** @type Feature */ export default { load() { - subscribe("diagnostics", async (_message, { schemaDocument, diagnostics }) => { + subscriptionToken = subscribe("diagnostics", async (_message, { schemaDocument, diagnostics }) => { for (const schemaResource of schemaDocument.schemaResources) { for (const deprecated of SchemaNode.annotatedWith(schemaResource, "deprecated", annotationDialectUri)) { if (SchemaNode.annotation(deprecated, "deprecated", annotationDialectUri).some((deprecated) => deprecated)) { @@ -34,5 +36,6 @@ export default { }, onShutdown() { + unsubscribe("diagnostics", subscriptionToken); } }; diff --git a/language-server/src/features/if-then-completion.js b/language-server/src/features/if-then-completion.js index 0dd07b2..42fee82 100644 --- a/language-server/src/features/if-then-completion.js +++ b/language-server/src/features/if-then-completion.js @@ -1,14 +1,16 @@ import { CompletionItemKind, InsertTextFormat } from "vscode-languageserver"; import * as SchemaDocument from "../schema-document.js"; -import { subscribe } from "../pubsub.js"; +import { subscribe, unsubscribe } from "../pubsub.js"; /** @import { Feature } from "../build-server.js" */ +/** @type string */ +let subscriptionToken; /** @type Feature */ export default { load() { - subscribe("completions", async (_message, { schemaDocument, offset, completions }) => { + subscriptionToken = subscribe("completions", async (_message, { schemaDocument, offset, completions }) => { const currentProperty = SchemaDocument.findNodeAtOffset(schemaDocument, offset); if (currentProperty && currentProperty.pointer.endsWith("/if") && currentProperty.type === "property") { completions.push(...ifThenPatternCompletion); @@ -24,6 +26,7 @@ export default { }, onShutdown() { + unsubscribe("completions", subscriptionToken); } }; diff --git a/language-server/src/features/schema-completion.js b/language-server/src/features/schema-completion.js index f9e122c..7e5b330 100644 --- a/language-server/src/features/schema-completion.js +++ b/language-server/src/features/schema-completion.js @@ -1,10 +1,12 @@ import { CompletionItemKind } from "vscode-languageserver"; import { getDialectIds } from "@hyperjump/json-schema/experimental"; import * as SchemaDocument from "../schema-document.js"; -import { subscribe } from "../pubsub.js"; +import { subscribe, unsubscribe } from "../pubsub.js"; /** @import { Feature } from "../build-server.js"; */ +/** @type string */ +let subscriptionToken; /** @type Feature */ export default { @@ -16,7 +18,7 @@ export default { ]); const shouldHaveTrailingHash = (/** @type string */ uri) => trailingHashDialects.has(uri); - subscribe("completions", async (_message, { schemaDocument, offset, completions }) => { + subscriptionToken = subscribe("completions", async (_message, { schemaDocument, offset, completions }) => { const currentProperty = SchemaDocument.findNodeAtOffset(schemaDocument, offset); if (currentProperty && currentProperty.pointer.endsWith("/$schema") && currentProperty.type === "string") { completions.push(...getDialectIds().map((uri) => ({ @@ -35,5 +37,6 @@ export default { }, onShutdown() { + unsubscribe("completions", subscriptionToken); } }; diff --git a/language-server/src/features/validate-references.js b/language-server/src/features/validate-references.js index b5132e1..ba3c3e1 100644 --- a/language-server/src/features/validate-references.js +++ b/language-server/src/features/validate-references.js @@ -1,5 +1,5 @@ import * as SchemaNode from "../schema-node.js"; -import { subscribe } from "../pubsub.js"; +import { subscribe, unsubscribe } from "../pubsub.js"; import { keywordNameFor } from "../util.js"; /** @@ -8,10 +8,13 @@ import { keywordNameFor } from "../util.js"; */ +/** @type string */ +let subscriptionToken; + /** @type Feature */ export default { load() { - subscribe("diagnostics", async (_message, { schemaDocument, diagnostics }) => { + subscriptionToken = subscribe("diagnostics", async (_message, { schemaDocument, diagnostics }) => { for (const schemaResource of schemaDocument.schemaResources) { for (const node of references(schemaResource)) { const reference = SchemaNode.value(node); @@ -32,6 +35,7 @@ export default { }, onShutdown() { + unsubscribe("diagnostics", subscriptionToken); } };