Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 369289

Summary: Hook up CodeMirror error styles to annotation model in CodeMirrorStyler
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: EditorAssignee: Jay Arthanareeswaran <jarthana>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, Silenio_Quarti
Version: 0.4Flags: mamacdon: review?
Target Milestone: 0.4 RC2   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Proposed fix none

Description Mark Macdonald CLA 2012-01-20 15:36:42 EST
When a CodeMirror mode styles a chunk of text with the "cm-error" style (see the htmlmixed.js mode for an example), it should be displayed as a squiggly line underneath the region of text where the error occurs.

To do this, CodeMirrorStyler must update the AnnotationModel and create appropriate annotations when part of a line is styled with the "cm-error" class.
Comment 1 Jay Arthanareeswaran CLA 2012-01-31 09:48:32 EST
I have a patch at hand. I will post it after adding tests and testing a bit more.
Comment 2 Jay Arthanareeswaran CLA 2012-02-02 07:00:35 EST
Created attachment 210440 [details]
Proposed fix

Path doesn't include tests yet. I will include the tests for the codemirror styler soon.
Comment 3 Mark Macdonald CLA 2012-02-03 08:45:34 EST
Thanks Jay! I'll take a look at the patch.
Comment 4 Jay Arthanareeswaran CLA 2012-02-03 11:45:23 EST
(In reply to comment #3)
> Thanks Jay! I'll take a look at the patch.

Mark, I can't figure out an easier way to get the line index, though I believe there must be a better way to do it. Thanks for taking time to look at the patch.
Comment 5 Mark Macdonald CLA 2012-02-09 19:49:34 EST
Hi again... I haven't forgotten about this one, just got pulled away by other stuff. I started reviewing/testing the patch.

Can you please post a comment here confirming that you authored this code? Something like this:

> "I wrote all this code and have the rights to contribute it to Eclipse under the
> eclipse.org web site terms of use."

We need this for legal reasons. Thanks!
Comment 6 Jay Arthanareeswaran CLA 2012-02-09 23:13:02 EST
(In reply to comment #2)
> Created attachment 210440 [details]
> Proposed fix
> 
> Path doesn't include tests yet. I will include the tests for the codemirror
> styler soon.

I wrote all this code and have the rights to contribute it to Eclipse under the eclipse.org web site terms of use.
Comment 7 Mark Macdonald CLA 2012-02-14 02:10:26 EST
I am going to commit the patch, with a second change to fix up a few things, namely:
- The "Syntax Error" string must be externalized, since the editor now uses i18n
- Minor style changes
- The logic can be simplified somewhat by exploiting the fact that every element of 'rangesAndErrors' is guaranteed to fall within the line being styled (e.lineIndex in the code). This lets us remove the 'for' loop and some min/max counting, and instead just replace the annotations between getLineStart(e.lineIndex) and getLineEnd(e.lineIndex). The annotations for any subsequent lines will be handled by later onLineStyle() calls.
Comment 8 Jay Arthanareeswaran CLA 2012-02-14 02:31:32 EST
(In reply to comment #7)
> I am going to commit the patch, with a second change to fix up a few things,
> namely:
> - The "Syntax Error" string must be externalized, since the editor now uses
> i18n
> - Minor style changes

Thanks, Mark! 

> - The logic can be simplified somewhat by exploiting the fact that every
> element of 'rangesAndErrors' is guaranteed to fall within the line being styled
> (e.lineIndex in the code). This lets us remove the 'for' loop and some min/max
> counting, and instead just replace the annotations between
> getLineStart(e.lineIndex) and getLineEnd(e.lineIndex). The annotations for any
> subsequent lines will be handled by later onLineStyle() calls.

I did think about it but wasn't very sure, particularly about the old annotations on subsequent lines being removed. If you can confirm it works for that case, it's fine then.
Comment 9 Mark Macdonald CLA 2012-02-14 15:12:54 EST
(In reply to comment #8)
> I did think about it but wasn't very sure, particularly about the old
> annotations on subsequent lines being removed. If you can confirm it works for
> that case, it's fine then.

Yes, the TextView API guarantees that our onLineStyle() listener will be called for subsequent lines before they are rendered, which will give us a chance to update their annotations (and styles) to whatever they should be.

I've tested and it works ok.

Adding Silenio for review since this is editor/styler related. The commit is in orion/bug369289:
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?h=bug369289&id=b5d7be1c09acaf6231a0b31880649b6c9ac1dc5c
Comment 10 Silenio Quarti CLA 2012-02-15 10:37:39 EST
The changes are fine.

But note that the highlight error annotations are not shown in the rulers (annotation and overview). If they where shown in the overview ruler, onLineStyle() would not be the right place to add the annotations, since it is generally only called for visible lines.  The user would not see the annotations until the lines containing the annotations were drawn.