微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

摩纳哥编辑器默认 json uri 架构

如何解决摩纳哥编辑器默认 json uri 架构

我正在使用 monaco 编辑器来编辑 JSON,我想设置自定义诊断选项。 我正在尝试https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-json-defaults

// Configures two JSON schemas,with references.

var jsonCode = [
    '{','    "p1": "v3",','    "p2": false',"}"
].join('\n');
var modelUri = monaco.Uri.parse("a://b/foo.json"); // a made up unique URI for our model
var model = monaco.editor.createModel(jsonCode,"json",modelUri);

// configure the JSON language support with schemas and schema associations
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
    validate: true,schemas: [{
        uri: "http://myserver/foo-schema.json",// id of the first schema
        fileMatch: [modelUri.toString()],// associate with our model
        schema: {
            type: "object",properties: {
                p1: {
                    enum: ["v1","v2"]
                },p2: {
                    $ref: "http://myserver/bar-schema.json" // reference the second schema
                }
            }
        }
    },{
        uri: "http://myserver/bar-schema.json",// id of the second schema
        schema: {
            type: "object",properties: {
                q1: {
                    enum: ["x1","x2"]
                }
            }
        }
    }]
});

monaco.editor.create(document.getElementById("container"),{
    model: model
});

uri: "http://myserver/foo-schema.json" 来自哪里?我只想使用认的 JSON 模式。不是我自己的。

像这样设置 uri 有效: uri: "http://localhost:4200/assets/monaco-editor/min/vs/language/json/jsonMode.js",

但是有没有一种干净的方法来设置这个值?也许 JSON 的 uri 值在某处可用?我搜索了 monaco.languages.json.jsonDefaults 但我没有找到任何东西。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。