Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unsubscribe for missing subscriptions #54

Merged
merged 1 commit into from
Jul 12, 2024
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
7 changes: 5 additions & 2 deletions language-server/src/features/deprecated.js
Original file line number Diff line number Diff line change
@@ -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)) {
Expand All @@ -34,5 +36,6 @@ export default {
},

onShutdown() {
unsubscribe("diagnostics", subscriptionToken);
}
};
7 changes: 5 additions & 2 deletions language-server/src/features/if-then-completion.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -24,6 +26,7 @@ export default {
},

onShutdown() {
unsubscribe("completions", subscriptionToken);
}
};

Expand Down
7 changes: 5 additions & 2 deletions language-server/src/features/schema-completion.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) => ({
Expand All @@ -35,5 +37,6 @@ export default {
},

onShutdown() {
unsubscribe("completions", subscriptionToken);
}
};
8 changes: 6 additions & 2 deletions language-server/src/features/validate-references.js
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand All @@ -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);
Expand All @@ -32,6 +35,7 @@ export default {
},

onShutdown() {
unsubscribe("diagnostics", subscriptionToken);
}
};

Expand Down