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

How to register custom json schema which is applied on file match pattern #38

Closed
npenin opened this issue Jun 29, 2016 · 15 comments
Closed
Assignees

Comments

@npenin
Copy link

npenin commented Jun 29, 2016

Hi Team,

I am looking for registering my own schema. Additionnaly, I would like this schema automatically applied based on file uri match. I know this is doable in vscode (https://code.visualstudio.com/docs/languages/json#_json-schemas-settings) but could not find a way to do it. Could you please guide me ?

Thanks,
Nicolas

@npenin
Copy link
Author

npenin commented Jun 29, 2016

I also found the JSONContribution which seems interesting also in my case, but could not find a way to register my own.

@alexdima
Copy link
Member

@aeschli will know

@alexdima
Copy link
Member

Oh, but first we'd need to ship a new monaco-editor that contains the now extracted monaco-json.

@aeschli
Copy link
Contributor

aeschli commented Jun 29, 2016

The JSON plugin has an API that lets you add schemas (and schema associations).
Check out https://github.com/Microsoft/monaco-json/blob/master/src/monaco.d.ts

@alexdima
Copy link
Member

@aeschli I don't think we've shipped an editor version that contains the json language as a plugin yet

@npenin
Copy link
Author

npenin commented Jul 11, 2016

up ?

I also cannot see the JsonContribution interface in https://github.com/Microsoft/monaco-json/blob/master/src/monaco.d.ts. Any chance to see it appearing ?

@aeschli
Copy link
Contributor

aeschli commented Jul 11, 2016

@npenin
Copy link
Author

npenin commented Jul 11, 2016

Thanks, this is one part of the solution. The other part would be to have the posibility to apply the schema based on a file pattern (eg. package.json files).

@aeschli
Copy link
Contributor

aeschli commented Jul 12, 2016

Use the fileMatch property for that...

monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
    schemas: [{
        uri: "http://myserver/foo-schema.json",
        fileMatch: [ 'foo.json' ],
        schema: {
            type: "object",
            properties: {
                p1: {
                    enum: [ "v1", "v2"]
                },
                p2: {
                    $ref: "http://myserver/bar-schema.json"
                }
            }
        }
    },{
        uri: "http://myserver/bar-schema.json",
        schema: {
            type: "object",
            properties: {
                q1: {
                    enum: [ "x1", "x2"]
                }
            }
        }
    }]
});

monaco.editor.create(document.getElementById("container"), {
    model: monaco.editor.createModel("{\n}\n", 'json', "inmemory://inmemory/foo.json")
});

@npenin
Copy link
Author

npenin commented Jul 12, 2016

great ! 👍

Is it possible also to have custom values for intellisense (like dependencies in package.json files) ?

@aeschli
Copy link
Contributor

aeschli commented Jul 13, 2016

@npenin
Copy link
Author

npenin commented Jul 13, 2016

awesome.

Thanks a lot.

@npenin npenin closed this as completed Jul 13, 2016
@npenin
Copy link
Author

npenin commented Jul 13, 2016

One question though, wouldn't it be cleaner to expose the Jsoncontribution interface and a way to add customs ?

It just looked better to my eyes as the retrieval of the current "node" is done in background.

@aeschli
Copy link
Contributor

aeschli commented Jul 13, 2016

That's not so easy as the JSON language service runs in a web worker. Your contribution would have to be bundled as part of this web worker.
Sure possible to do, the parts are all there.

@jasonHzq
Copy link

I have tried fileMatch but useless..

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants