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

Bug 321507

Summary: [formatter] Formatting in script region deletes some of the script code
Product: [WebTools] JSDT Reporter: Ian Tewksbury <itewksbu>
Component: GeneralAssignee: Ian Tewksbury <itewksbu>
Status: CLOSED DUPLICATE QA Contact: Nitin Dahyabhai <thatnitind>
Severity: normal    
Priority: P3 CC: cmjaun, jzhang
Version: 3.2   
Target Milestone: 3.2.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Sample File
none
Fix Patch
none
JUnit Patch none

Description Ian Tewksbury CLA 2010-08-02 09:23:00 EDT
Created attachment 175709 [details]
Sample File

When formatting the attached page the end of the script region gets cut off deleting some of the script and making the code invalid.
Comment 1 Jim Zhang CLA 2010-08-12 16:19:53 EDT
I saw the same thing today.  It was in the script region of an HTML file.
Comment 2 Ian Tewksbury CLA 2010-08-17 11:31:40 EDT
The problem here has to do with when there are edits in the document before the JSDT edits.  The issue is that the translation is based off the model which does not include any of the edits that have been preformed by the formatter thus far and thus all the offsets are based on the un-formatted document, but then we apply the changes to the document that has already had its beginning formatted and our offsets are all off.
Comment 3 Ian Tewksbury CLA 2010-08-17 16:55:22 EDT
Created attachment 176847 [details]
Fix Patch

The problem is two fold.  Number one the JsTranslator does not pay attention to edits during a write session which means the translation is not aware of changes made to the document thus far once the JSDT formatter is reached. This means that if any document changes occurred during the formatting before the JSDT formatting runs then the offsets will all be off.  The fix to this is to make it so when requesting the JS text from the translator, if during a write-session, invoke a translator reset to be sure the translation has picked up the latest document changes.  The second problem is that for some reason the the FormattingStrategyJSDT was using the compilation unit text to create the edits when it should be using the JS text from the translator.

These two fixes combined together fix the issue.

JUnit patch to follow.
Comment 4 Ian Tewksbury CLA 2010-08-17 16:55:51 EDT
Created attachment 176848 [details]
JUnit Patch

A new JUnit for this fix.
Comment 5 Ian Tewksbury CLA 2010-08-19 11:21:01 EDT
because this touches the same bits of code as Bug 319855 and so I am going to merge both patches into that bug.

*** This bug has been marked as a duplicate of bug 319855 ***