Git Product home page Git Product logo

Comments (15)

npenin avatar npenin commented on May 14, 2024

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

from monaco-editor.

alexdima avatar alexdima commented on May 14, 2024

@aeschli will know

from monaco-editor.

alexdima avatar alexdima commented on May 14, 2024

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

from monaco-editor.

aeschli avatar aeschli commented on May 14, 2024

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

from monaco-editor.

alexdima avatar alexdima commented on May 14, 2024

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

from monaco-editor.

npenin avatar npenin commented on May 14, 2024

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 ?

from monaco-editor.

aeschli avatar aeschli commented on May 14, 2024

Yes, I made the update.
Check out https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-json-defaults

from monaco-editor.

npenin avatar npenin commented on May 14, 2024

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).

from monaco-editor.

aeschli avatar aeschli commented on May 14, 2024

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")
});

from monaco-editor.

npenin avatar npenin commented on May 14, 2024

great ! 👍

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

from monaco-editor.

aeschli avatar aeschli commented on May 14, 2024

I added https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-completion-provider-example to show how to add custom completions.

from monaco-editor.

npenin avatar npenin commented on May 14, 2024

awesome.

Thanks a lot.

from monaco-editor.

npenin avatar npenin commented on May 14, 2024

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.

from monaco-editor.

aeschli avatar aeschli commented on May 14, 2024

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.

from monaco-editor.

jasonHzq avatar jasonHzq commented on May 14, 2024

I have tried fileMatch but useless..

from monaco-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.