Skip to content

Range must be inside element being annotated: a diagnostic falls outside the file right after a completion #2030

Closed

Description

@lagergren

LSPDiagnosticsApplier collects the diagnostics of a file in a non-blocking read action that doesn't wait for the file's document to be committed. LSPDiagnosticFeature.createAnnotation places a diagnostic at offsets of the document, but annotates the Psi file. Right after a completion inserts text, the document is longer than the Psi file until it is committed, so a diagnostic of the inserted text falls outside the Psi file and IntelliJ throws:

com.intellij.diagnostic.PluginException: Range must be inside element being annotated: (0,735); but got: (766,772)
	at com.intellij.codeInsight.daemon.impl.B.range(B.java:200)
	at com.redhat.devtools.lsp4ij.client.features.LSPDiagnosticFeature.createAnnotation(LSPDiagnosticFeature.java:110)
	at com.redhat.devtools.lsp4ij.features.diagnostics.LSPDiagnosticsCollector.collect(LSPDiagnosticsCollector.java:122)
	at com.redhat.devtools.lsp4ij.features.diagnostics.LSPDiagnosticsApplier.collectDiagnostics(LSPDiagnosticsApplier.java:241)
	at com.redhat.devtools.lsp4ij.features.diagnostics.LSPDiagnosticsApplier.lambda$scheduleRefresh$2(LSPDiagnosticsApplier.java:115)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$OTelMonitor.callWrapped(NonBlockingReadActionImpl.java:1055)

The IDE reports Last Action: EditorChooseLookupItem. The refresh fails, so the file's new diagnostics aren't shown until the next update. LSPDiagnosticsCollector catches an IndexOutOfBoundsException from a stale range, but not this.

Seen in a language plugin's UI tests on IntelliJ IDEA 2026.2.3 with LSP4IJ 0.30.1: 3 of 8 runs once the test IDE no longer synchronized files on frame activation, which in those tests happened often enough to commit the document first.

Activity

  1. added this to the 0.30.2 milestone on Nov 20, 2026
  2. added a commit that references this issue on Nov 21, 2026
    e4518e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions