ryan
ryan

Reputation: 91

How do I add a custom error to the gutter in Ace Editor?

I'm using react-ace to write a custom JS Editor. I want to throw a custom error in the gutter when the user tries to import a module other than ones from a list I specify. How do I go about doing this? I've tried extending a custom mode but this seems to only customize syntax highlighting, I've peaked around ESLint but am not sure if that's the right path. Please help I'm quite lost.

Upvotes: 2

Views: 2006

Answers (1)

Harsha pps
Harsha pps

Reputation: 2208

To get the data from the editor, use getValue() and then scan the string for the modules you don't want to see and then use the same row and column number and display the error using setAnnotations

editor.getSession().setAnnotations([{
  row: 1,
  column: 0,
  text: "Error Message", 
  type: "error" //This would give a red x on the gutter
}]);

Upvotes: 2

Related Questions