4

I have an Eclipse custom editor and I implemented 'report errors as you type', but every now and then my error squigglies (using JFace annotations) are not shown or linger after they should be removed.

I am using MonoReconciler with my implementation of IReconcilingStrategy. During the reconcile step I call annotationModel.replaceAnnotations to remove the old errors and add the new ones. Most of the times this works fine. Every now and then the updates are lost, and I notice the following:

  • the red stamp on the left ruler disappears, but the red underlines stay
  • on the next character I type, the underline disappears

I verified in the debugger that the annotations are correctly calculated. The underline disappears immediately after typing a character, and not after the 500ms delay of the reconciler. It looks like a lost UI update/redraw.

There must be a race condition somewhere (the reconciler runs in its own thread). What am I doing wrong? I couldn't find any documentation about this use-case.

Edit: To reproduce, checkout the scala-worksheet and create a new one. Type

 object Test {
   val m = Map( 't' -> 1 )
 }

Now edit the arrow: remove the >. The underline is missing. Type a space, it comes back. Add it back, the underline is still there until you type another space.

I fixed it by calling invalidateTextPresentation on the underling SourceViewer, but it seems to me that shouldn't be necessary. I'd like to understand what is the correct way to use editor annotations.

PS. The lost updates can also be seen in this screencast.

Iulian Dragos
  • 5,692
  • 23
  • 31

1 Answers1

0

It's hard to tell from a distance, typically in eclipse, any changes that impact the ui should be executed on the ui thread (and eclipse will not always warn about this). Normally you use Display.getDefault().asyncExec(...) to execute something on the ui thread but you probably already know this. It can happen that 2 queued up changes cause a race.

(I have implemented semantic highlighting, error highlighting etc several times for the company I work for, Sigasi. If you can point me to your implementation I may be able to figure out what's going wrong.)

llemieng
  • 563
  • 8
  • 8
  • Thanks for your answer. I tried running `replaceAnnotations` inside `asyncExec` but it didn't fix it. The code is in https://github.com/scala-ide/scala-worksheet/blob/master/org.scalaide.worksheet/src/org/scalaide/worksheet/reconciler/ScalaReconcilingStrategy.scala#L37 – Iulian Dragos Sep 20 '12 at 13:47
  • I can't find 'replaceAnnotations ' did you mean 'updateErrorAnnotations'? – llemieng Sep 20 '12 at 15:33
  • btw is there an easy way to reproduce this problem? – llemieng Sep 20 '12 at 16:05
  • I did not commit all my temporary changes during my tries. I will edit the question with a way to reproduce it. – Iulian Dragos Sep 21 '12 at 09:38