eclipse-lsp4e / eclipse-lsp4e/lsp4e
BadLocationException during Marker update
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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