Recommended way of doing validation when using an external state?

Let’s say CodeMirror is used as part of a larger form. For now we are using linter() plugin. However it is pretty tied to codemirror internal state. I.e. you have a function which should return an array of Diagnostics. The problem is that it is “enclosed” in that function.

If we try to leverage external validation (e.g. from react hook form) it doesn’t seem to be a good idea. Because we should still return an array of diagnostics but also synchronise errors with react hook frorm errors).