Using the linter plugin for code errors

I’m using the linter plugin in an IDE-like UI to display run time errors from the code being edited. This setup is a bit weird compared to the usual linting flow in that, it is more imperative and a result of the code being run rather than an operation that can be run on the code itself.

Right now I’m accomplishing this by using setDiagnostics after retrieving errors. However, the moment the user modifies the document (or even clicks in and alters the selection), the diagnostics will disappear as the linter will rerun. I am working around this by setting a config of { delay: Infinity }. This seems to solve the problem for me.

Couple questions about all this.

  1. Is using the linter plugin for setting code errors like this a good solution? Or does it make more sense to create my own extension?
  2. Is the workaround of setting delay: Infinity a good idea? Or will I run into some unintended consequences and/or break down the line?

Don’t use linter(...) in your configuration to avoid having any linter run automatically. setDiagnostics will still work.

ahhh also found this conversation about this issue: Linter that only refreshes on needsRefresh - #3 by kim

I’m not explicitly adding a linter but using @uiw/react-codemirror which probably adds something (though I thought I disabled everything).

What would be the easiest way to find another linter being added? setting a breakpoint in linter() didn’t seem to find anything

figured it out! wasn’t actually being caused by a linter but rather by the extensions being reconfigured on focus/unfocus events because of this line: react-codemirror/core/src/useCodeMirror.ts at master · uiwjs/react-codemirror · GitHub which was firing off a view.dispatch({ effects: StateEffect.reconfigure.of(getExtensions) })

this is clearly not a CodeMirror bug per se, but leaving the findings here for anyone else. Once we wrapped all our callbacks in useCallback, we were able to avoid these reconfigure state effects, and solve the issue. I’m guessing by manually creating a linter extension, we avoided the lints being destroyed.