Skip to content

expose the jsonSchemaRegistry in the extension API #252610

Open
@Kosta-Github

Description

@Kosta-Github

I would like to request to expose the jsonSchemaRegistry in the public API for extensions.

The interface IJSONContributionRegistry is defined here:

export interface IJSONContributionRegistry {
readonly onDidChangeSchema: Event<string>;
readonly onDidChangeSchemaAssociations: Event<void>;
/**
* Register a schema to the registry.
*/
registerSchema(uri: string, unresolvedSchemaContent: IJSONSchema, store?: DisposableStore): void;
registerSchemaAssociation(uri: string, glob: string): IDisposable;
/**
* Notifies all listeners that the content of the given schema has changed.
* @param uri The id of the schema
*/
notifySchemaChanged(uri: string): void;
/**
* Get all schemas
*/
getSchemaContributions(): ISchemaContributions;
getSchemaAssociations(): { [uri: string]: string[] };
/**
* Gets the (compressed) content of the schema with the given schema ID (if any)
* @param uri The id of the schema
*/
getSchemaContent(uri: string): string | undefined;
/**
* Returns true if there's a schema that matches the given schema ID
* @param uri The id of the schema
*/
hasSchemaContent(uri: string): boolean;
}

I would like to be able to do the same as the internal LanguageModelToolsService is doing here but within an extension:

jsonSchemaRegistry.registerSchema(schemaUrl, toolData.inputSchema, store);
store.add(jsonSchemaRegistry.registerSchemaAssociation(schemaUrl, `/lm/tool/${toolData.id}/tool_input.json`));

  1. first register a new schema
  2. associate that schema with a specific file in the workspace/editor

I cannot use the contributes.jsonValidation (in package.json) for this, since I need to construct a JSON schema on-the-fly depending on the content of the to-be-analyzed JSON file and the JSON file itself doesn't have a specific filename pattern that could be used with the contributes.jsonValidation mechanism.

If the internal jsonSchemaRegistry as defined here:

const jsonSchemaRegistry = Registry.as<JSONContributionRegistry.IJSONContributionRegistry>(JSONContributionRegistry.Extensions.JSONContribution);

would be exposed I could register and unregister the JSON schemas with the different files dynamically/on-the-fly. This would also solve this feature request over here: #230136

Pseudo code would look like this:

const jsonSchemaRegistry: IJSONContributionRegistry = vscode....getJsonSchemaRegistry();

...
const unregisterAssocCb = jsonSchemaRegistry.registerSchemaAssociation(schemaUri, fileUri);

...
unregisterAssocCb();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions