Skip to content

Registered custom schemas stopped working in 0.5.0 #216

@itowlson

Description

@itowlson

In 0.4.1 you could call registerContributor on the extension API object and get intellisense - e.g. code completion, red wigglies, hover text, etc. In 0.5.0 this stopped working - no error but you get no intellisense.

To reproduce, create a new VS Code extension via yo code and add an onLanguage:yaml activation event. Then paste the following as the new contents of src/extension.ts:

'use strict';
import * as vscode from 'vscode';

export async function activate(context: vscode.ExtensionContext) {
    await registerYamlSchema();
}

const SCHEMA = "foozzzzzz";

const schemaJSON = JSON.stringify({
    type: "object",
    properties: {
        version: {
            type: "string",
            description: "A stringy string string"
        }
    }
});

export async function registerYamlSchema() {
    const yamlPlugin = await activateYamlExtension();
    if (!yamlPlugin) {
        vscode.window.showWarningMessage("NO YAMLS");
        return;
    }

    yamlPlugin.registerContributor(SCHEMA, onRequestSchemaURI, onRequestSchemaContent);
}

function onRequestSchemaURI(resource: string): string | undefined {
    if (resource.endsWith('porter.yaml')) {
        return `${SCHEMA}://schema/porter`;
    }
    return undefined;
}

function onRequestSchemaContent(schemaUri: string): string | undefined {
    const parsedUri = vscode.Uri.parse(schemaUri);
    if (parsedUri.scheme !== SCHEMA) {
        return undefined;
    }
    if (!parsedUri.path || !parsedUri.path.startsWith('/')) {
        return undefined;
    }

    return schemaJSON;
}

const VSCODE_YAML_EXTENSION_ID = 'redhat.vscode-yaml';

export interface YamlExtension {
    registerContributor(
        schema: string,
        requestSchema: (resource: string) => string | undefined,
        requestSchemaContent: (uri: string) => string | undefined
    ): void;
}

export async function activateYamlExtension(): Promise<YamlExtension | undefined> {
    const extension = vscode.extensions.getExtension(VSCODE_YAML_EXTENSION_ID);
    if (!extension) {
        return undefined;
    }

    const extensionAPI = await extension.activate();
    if (!extensionAPI || !extensionAPI.registerContributor) {
        return undefined;
    }

    return extensionAPI;
}

Run this and test it with a file named porter.yaml containing a version attribute e.g.

name: HELLO
version: 0.1.0
description: "An example Porter configuration"

With vscode-yaml 0.4.1 installed, hovering over version gives a hover containing the description from the schema.

With vscode-yaml 0.5.1 (and, from other tests, I believe also 0.5.0), hovering over version produces hover requests in the verbose trace log, but no hover appears.

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