Skip to content

Commit

Permalink
Allow users to change the default k8s schema
Browse files Browse the repository at this point in the history
Add a new notification to allow users to change the default Kubernetes schema on the fly.
  • Loading branch information
someone-stole-my-name authored and tricktron committed Mar 19, 2023
1 parent c51b12c commit c739bce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/languageserver/handlers/notificationHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LanguageService, SchemaConfiguration } from '../../languageservice/yaml
import {
CustomSchemaRequest,
DynamicCustomSchemaRequestRegistration,
KubernetesURLNotification,
SchemaAssociationNotification,
SchemaSelectionRequests,
VSCodeContentRequestRegistration,
Expand Down Expand Up @@ -36,10 +37,15 @@ export class NotificationHandlers {
this.schemaAssociationNotificationHandler(associations)
);
this.connection.onNotification(DynamicCustomSchemaRequestRegistration.type, () => this.dynamicSchemaRequestHandler());
this.connection.onNotification(KubernetesURLNotification.type, (url) => this.kubernetesURLNotification(url));
this.connection.onNotification(VSCodeContentRequestRegistration.type, () => this.vscodeContentRequestHandler());
this.connection.onNotification(SchemaSelectionRequests.type, () => this.schemaSelectionRequestHandler());
}

private kubernetesURLNotification(url: string): void {
this.yamlSettings.kubernetesSchemaUrl = url;
}

/**
* Received a notification from the client with schema associations from other extensions
* Update the associations in the server
Expand Down
5 changes: 2 additions & 3 deletions src/languageserver/handlers/settingsHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export class SettingsHandler {
languageSettings.schemas.push({ uri, fileMatch: fileMatch, schema: schema, priority: priorityLevel });
}

if (uri.normalize().includes('kubernetes')) {
if (uri === this.yamlSettings.kubernetesSchemaUrl) {
if (fileMatch.constructor === Array) {
fileMatch.forEach((url) => {
this.yamlSettings.specificValidatorPaths.push(url);
Expand All @@ -347,7 +347,6 @@ export class SettingsHandler {
this.yamlSettings.specificValidatorPaths.push(fileMatch);
}
}

return languageSettings;
}
}
}
4 changes: 4 additions & 0 deletions src/requestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export namespace DynamicCustomSchemaRequestRegistration {
export const type: NotificationType<{}> = new NotificationType('yaml/registerCustomSchemaRequest');
}

export namespace KubernetesURLNotification {
export const type: NotificationType<string> = new NotificationType('yaml/kubernetesURL');
}

export namespace VSCodeContentRequestRegistration {
export const type: NotificationType<{}> = new NotificationType('yaml/registerContentRequest');
}
Expand Down
3 changes: 2 additions & 1 deletion src/yamlSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ISchemaAssociations } from './requestTypes';
import { URI } from 'vscode-uri';
import { JSONSchema } from './languageservice/jsonSchema';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { JSON_SCHEMASTORE_URL } from './languageservice/utils/schemaUrls';
import { JSON_SCHEMASTORE_URL, KUBERNETES_SCHEMA_URL } from './languageservice/utils/schemaUrls';
import { YamlVersion } from './languageservice/parser/yamlParser07';

// Client settings interface to grab settings relevant for the language server
Expand Down Expand Up @@ -77,6 +77,7 @@ export class SettingsState {
customTags = [];
schemaStoreEnabled = true;
schemaStoreUrl = JSON_SCHEMASTORE_URL;
kubernetesSchemaUrl = KUBERNETES_SCHEMA_URL;
indentation: string | undefined = undefined;
disableAdditionalProperties = false;
disableDefaultProperties = false;
Expand Down

0 comments on commit c739bce

Please sign in to comment.