Search code examples
codemirror

CodeMirror 3.x -- Is there an event that fires each time the linter completes?


Background

  • I'm currently using CodeMirror 3.13
  • I have multiple editors on a page (probably not significant)

The Ask

I want to count the number and type of linting errors and display a summary elsewhere in the page. To do that I would like to know when the linter completes execution so that I don't have to poll for changes.

What is the event-based solution?

Thank you for your time! (I upvote all valid attempts ...that aren't obviously wrong of course)

References

Here is my error counter snippet (coffeescript):

for eachError in doc.getAllMarks()
  numStaticErrors++ if eachError.className is "CodeMirror-lint-mark-error"
  numStaticErrors++ if eachError.className is "CodeMirror-lint-marker-warning"
  numStaticErrors++ if eachError.className is "CodeMirror-lint-marker-multiple"

Solution

  • Currently, the only way to be notified of a linting event is to set the "lintWith" option to an object containing an onUpdateLinting property, which is a callback that will be called with the list of linting errors/warning as its first argument whenever the markers are updated.