redhat-developer / redhat-developer/vscode-yaml

Allow requestSchema to return Promise

Open
#1,004 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
829
Forks
260
Avg merge
5h 43m
Merged PRs (30d)
1

Description

Is your enhancement related to a problem? Please describe.

We integrate vscode-yaml to provide language support for our yaml project configuration files. Nature of the config is such that you can't decide just by looking at the name of the file what "type" of configuration file it is. To find if given file is even part of our project configuration and if so what role it plays (thus what schema to apply) we need to invoke some async code, which we can't do because requestSchema requires immediate string result.

Describe the solution you would like

We'd like the ExtensionAPI.registerContributor to be extended like this

  registerContributor(
    schema: string,
    requestSchema: (resource: string) => Promise<string> | string,  // << Allows `Promise<string>` here
    requestSchemaContent: (uri: string) => Promise<string> | string,
    label?: string
  ): boolean;

this change should be backwards compatible as simple string result is still allowed.

Looking at the history I see requestSchemaContent also started as allowing only string return but in time was extended to also allow Promise<string> - was there some reason to keep requestSchema synchronous only or was there simply no usecase for also extending it so it was left as is?

Describe alternatives you have considered

It is possible to work around this limitation by eagerly caching results for requestSchema so when this callback is invoked we can return the cached value (if already available) but we'd like to fall back to this solution as last resort as it will introduce significant complexity for our implementation and consume extra time+memory for the user (we have to eagerly prefetch everything to have it ready for when requestSchema gets called)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ExtensionAPI.registerContributor entry point and compare requestSchema with the existing requestSchemaContent callback, which already supports synchronous and Promise results. Trace how the requestSchema return value is consumed. Done means Promise is accepted while existing string callbacks remain supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.