vscode-yaml: Registered custom schemas stopped working in 0.5.0

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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 26 (23 by maintainers)

Most upvoted comments

The latest VSIX seems to work. I noticed that it wasn’t showing hover tips for ‘live’ k8s resources (those viewed directly on a cluster via the k8s extension’s Cluster Explorer), but that seemed to be the case in 0.4.1 as well so that’s not a regression. I think the problem may be that the YAML extension only registers the file: and untitled: URL schemes with the YAML language server - ‘live’ resource views use the k8smsx: scheme and I’m not yet sure how to address this. I suggest we get the immediate fix out, and then circle round to that one - does that work for you?

Once again, I am very much appreciating your efforts on this.