eclipse-lsp4e / eclipse-lsp4e/lsp4e

BadLocationException during Marker update

Open
#1,451 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
85
Forks
69
Avg merge
8h 33m
Merged PRs (30d)
6

Description

I was adding and removing characters at the end of the file, which caused the LS to send diagnostics, which in turn caused a BadLocationException when updating markers:

org.eclipse.jface.text.BadLocationException: 532
	at org.eclipse.jface.text.TreeLineTracker.lineByOffset(TreeLineTracker.java:268)
	at org.eclipse.jface.text.TreeLineTracker.getLineNumberOfOffset(TreeLineTracker.java:1112)
	at org.eclipse.jface.text.AbstractLineTracker.getLineNumberOfOffset(AbstractLineTracker.java:246)
	at org.eclipse.jface.text.AbstractDocument.getLineOfOffset(AbstractDocument.java:863)
	at org.eclipse.core.internal.filebuffers.SynchronizableDocument.getLineOfOffset(SynchronizableDocument.java:429)
	at org.eclipse.lsp4e.operations.diagnostics.LSPDiagnosticsToMarkers.computeMarkerAttributes(LSPDiagnosticsToMarkers.java:328)
	at org.eclipse.lsp4e.operations.diagnostics.LSPDiagnosticsToMarkers$2.doRun(LSPDiagnosticsToMarkers.java:197)
	at org.eclipse.lsp4e.operations.diagnostics.LSPDiagnosticsToMarkers$2.runInWorkspace(LSPDiagnosticsToMarkers.java:156)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

More of general question, because I encountered a similar problem (#1439) recently:
I haven't really worked much with IDocument and friends, but I was wondering what is the proper way to handle asynchronous operations which try to access or change an IDocument outside of the UI thread? Locking the document in any way is probably not desirable, because this might lead to prolonged UI freezes. So should Jobs just repeatedly check if the document timestamp has changed and stop all work if it has changed?
Maybe someone with a deeper understanding of Eclipse document handling can give me some insights or point me in the right direction to some documentation?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with org.eclipse.lsp4e.operations.diagnostics.LSPDiagnosticsToMarkers, especially computeMarkerAttributes and the asynchronous job methods shown in the stack trace. Reproduce the issue by editing the end of a file while diagnostics are sent, then trace how document offsets become marker attributes. Done means marker updates no longer raise BadLocationException during asynchronous document changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.