react-ace icon indicating copy to clipboard operation
react-ace copied to clipboard

Error highlighter not displayed for yaml files

Open rosemaryjose opened this issue 5 years ago • 3 comments

Problem

I am using react-ace in my project. I have to put yaml file in ace-editor. But error is not displaying if user edit the file. In case of json its doing both highlighting and error display. In case of yaml, only syntax highlighting is working. How to enable error display/syntax validation for yaml files in react-ace.

Sample code to reproduce your issue

I have imported "brace/mode/yaml" and made "showGutter={true}" in ace-editor

import "brace/mode/yaml";

<AceEditor focus style={{ width: "100%" }} mode="yaml" theme="github" name="template_file" ref="editorInput" onChange={this.props.input.onChange} value={this.props.input.value} fontSize={20} showPrintMargin showGutter={true} highlightActiveLine setOptions={{ showLineNumbers: true, tabSize: 2 }} editorProps={{ $blockScrolling: true }} />

References

Progress on: #

rosemaryjose avatar May 02 '19 11:05 rosemaryjose

Has anyone found the solution ?

UditManiyar avatar Jul 15 '19 19:07 UditManiyar

+1 same issue. Other modes work fine and shows the error messages as mentioned above. Even the annotations array is empty when checked. Additionally imported brace at the top too. Still it didnt help.

Anyway found this and it mentions the syntax validation is available only for few lang. https://github.com/ajaxorg/ace/wiki/Syntax-validation

Also read this as it also mentions the ways to add linter for other languages.

Had to use other library which can parse yaml like yaml-js to get the errors and manually set the annotations. Even after setting the annotations props it doesnt work properly so had to get the editor reference and set it manually using editor.setAnnotations.

ngmgit avatar Aug 05 '19 09:08 ngmgit

Add a note above. It doesn't work by using editor.renderer.setAnnotations() synchronously. With rending ajaxorg/ace source code, I provide some useful code links:

  • renderer.setAnnotations() https://github.com/ajaxorg/ace/blob/master/lib/ace/virtual_renderer.js#L1181
  • gutterLayer.setAnnotations() https://github.com/ajaxorg/ace/blob/master/lib/ace/layer/gutter.js#L79
  • loop.schedule() https://github.com/ajaxorg/ace/blob/master/lib/ace/renderloop.js#L72

So I guess the action of setAnnotations was ignored when paste yaml string to the editor is pending. After putting editor.renderer.setAnnotations() in the setTimeout function, It works fluently.

yunsii avatar Oct 21 '20 06:10 yunsii