monaco-yaml
monaco-yaml copied to clipboard
Cannot set schema validation severity level?
Monaco's built-in JSON support allows schema validation to produce either warnings or errors, as specified in the typing here. Is it possible to add such support to monaco-yaml?
I can think of 2 solutions:
- Allow to specify a severity override to the
monaco-yaml
options. - Add a marker data interceptor function to process them before sending the results in the editor.
I personally think option 2 is the better one. It’s a bit dangerous to assume what severity is reported. Currently YAML errors and schema violations are reported as warnings, unused anchors as hints. Who knows what more diagnostics will be reported un the future. This logic exists in yaml-language-server
. monaco-yaml
just translates it to a format Monaco editor understands.
Interesting. I dug a bit further and found that this file is doing the validation heavy lifting in yaml-language-server. That is always returning warnings, as you said.
With option 2, there's not really much to go off of on the markers themselves, or even what's returned by yaml-language-server. I'd probably just have to upgrade all warnings to errors, which also seems dangerous.
With option 1, yaml-language-server could be modified to take a severity option, similar to how Monaco's validation works, and this library could add support for the option.
Ultimately, I could probably work with either solution, but I do agree that it seems out of place to have this library do any kind of severity override itself.
May I ask why you need this feature? I can also imagine YAML syntax errors should be errors, but schema violations warnings. I think that would conflict with your feature request.
If yaml-language-server
would introduce a severity, I’ll gladly implement it in monaco-yaml
too. This aligns with the main goal, which is to bring yaml-language-server
options into monaco-editor
. Can you create an upstream issue? Preferably link this one.
I have built an Angular component around monaco-editor. I needed YAML support, so I've added monaco-yaml to the mix. The component provides its own validation: if the monaco-editor instance has "errors", then the component reports itself as invalid. Of course I could get fancier with that logic and check for YAML schema warnings, but really I'd like the markers to be red as well. I could post-process the markers after they've been applied, but going through them beforehand at least seems better. Still, if there's a setting on yaml-language-server to return errors instead of warnings, that would at least be consistent with the native JSON support. So, I will file an upstream issue there.
I will implement this if yaml-language-server
supports this option. I’m closing this issue, as it’s non-actionable from monaco-yaml
.