Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[json] Allow users to register a json validator through code similarly to how they can register one through package.json #77433

Closed
lexrey opened this issue Jul 15, 2019 · 7 comments
Assignees
Labels
info-needed Issue requires more information from poster json JSON support issues

Comments

@lexrey
Copy link

lexrey commented Jul 15, 2019

Create a function similar to registerCompletionItemProvider that can take in a json schema that provides json validation.

@vscodebot vscodebot bot added the json JSON support issues label Jul 15, 2019
@aeschli aeschli changed the title Allow users to register a json validator through code similarly to how they can register one through package.json [json] Allow users to register a json validator through code similarly to how they can register one through package.json Jul 16, 2019
@aeschli
Copy link
Contributor

aeschli commented Jul 16, 2019

@lexrey Can you describe a use case?

@aeschli aeschli added the info-needed Issue requires more information from poster label Jul 16, 2019
@lexrey
Copy link
Author

lexrey commented Jul 16, 2019

Sure @aeschli I'd like to collect telemetry on my extension and one of the things it offers is json validation. By registering my own json validator, I could then make the telemetry function calls on use of the snippets provided by the schema as well as hovers used.

@aeschli
Copy link
Contributor

aeschli commented Jul 17, 2019

If what you provide is a JSON schema, then all you could measure is how many accesses there are to the schema. Only the JSON language service would know when proposals or hovers are provided.

-> It's already possible to provide schemas programmatically by registering a TextDocumentContentProvider

To know what proposals or hovers are requested, you would have to implement a hover and completion provider.

@lexrey
Copy link
Author

lexrey commented Jul 17, 2019

Could you provide an example on how to measure the amount of accesses to the schema? It seems that recreating the functionality of the jsonValidation supplied by package.json is much more difficult than recreating the snippets provided by it.

@aeschli
Copy link
Contributor

aeschli commented Jul 18, 2019

  • register a TextDocumentContentProvider for a new URL schema (let's say 'fooSchema')
  • in your extension, associate file extensions with an URL of that schema
      {
        "fileMatch": "*.foo",
        "url": "fooSchema://schemas/schema"
      },

in the TextDocumentContentProvider, serve your JSON schema when requested and collect telemetry

@lexrey
Copy link
Author

lexrey commented Jul 18, 2019

Thank you for the example. And before closing just for clarification, the association for the file extensions would be set in the contributes.jsonValidation section of package.json?

@aeschli
Copy link
Contributor

aeschli commented Jul 25, 2019

Yes, correct

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster json JSON support issues
Projects
None yet
Development

No branches or pull requests

2 participants