我正在使用 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 但我没有找到任何东西。