Any way to broadly ignore invalid ranges?

For the given editor example (you can paste it directly into Try CodeMirror)

import {basicSetup, EditorView} from "codemirror"
import { linter } from '@codemirror/lint'

const lintSource = (editorView) => {
  return [
    { from: 0, to: 5, severity: 'error', message: 'one', },
    { from: 300, to: 305, severity: 'error', message: 'two', },

let view = new EditorView({
  doc: "type some text, click away, click back",
  extensions: [
  parent: document.body

If you run that code, type in the editor with pause on uncaught exceptions selected in developer tools, we get a RangeError from within codemirror/state .

A robust solution would be to ensure that the lintSource here doesn’t produce diagnostics outside the editor’s bounds, but I was wondering if there was any way to catch all invalid positions for any extension and simply ignore those changes. Is that possible?

You’ll have to do that in your lint source. Since, supposedly, you’re basing the ranges on the document, it shouldn’t be too hard to make sure they actually fit within that document.

I’m running into the same issue. For example, when my lint source has a diagnostic set at the last character, deleting that character results in an exception when LintState.diagnostics is being mapped to the new document in StateField.update (here). Is there any way to avoid these exceptions? Would a version of map that filters out invalid ranges make sense here?

It sounds like it has it set after the last character’s end position, or it would be valid to map. Again, clipping these when you first return them should solve your problem.

Ah, you’re right! It turns out was off by one. Thank you so much for the quick response (and the well-designed project).