Skip to content

Commit

Permalink
use document change
Browse files Browse the repository at this point in the history
  • Loading branch information
JPMoresmau committed Feb 10, 2013
1 parent 0f0bb09 commit 2561011
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/releasenotes/net.sf.eclipsefp.haskell_2.5.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Features:
- Refactor->rename can rename local bindings
- Synchronize from editor use a long running buildwrapper instance, should enhance performance. Closing the editor for a file closes the long running process, so no memory hog.
- https://github.com/JPMoresmau/eclipsefp/issues/86: symbols like $ and + are a different colors than alphanumeric identifiers
- The folder where the buildwrapper executable is is always passed as the path to buildwrapper calls (so that for examples preprocessors in the same folder are found)

Internal:
- Start SQLite in a thread to avoid native locking (maybe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ job_clean=Cleaning project {0}
job_synchronize=Synchronizing project {0}
job_components=Retrieving components for project {0}
job_dependencies=Retrieving dependencies for project {0}
job_import_clean=Cleaning import for {0}
job_import_clean=Organizing imports for {0}

outline_job_name=Generating outline for {0}
editor_job_name=Synchronizing editor content for {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor;
import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ltk.core.refactoring.DocumentChange;
import org.eclipse.swt.widgets.Display;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.ui.texteditor.ITextEditor;


Expand Down Expand Up @@ -59,31 +64,60 @@ public int compare( final ImportClean o1, final ImportClean o2 ) {
return Integer.valueOf(o2.getLocation().getStartLine()).compareTo(Integer.valueOf(o1.getLocation().getStartLine()));
}
} );
final DocumentChange dc=new DocumentChange("import",d);
MultiTextEdit mte=new MultiTextEdit();
dc.setEdit( mte );
//dc.addEdit( edit )
for (ImportClean cl:cleans){
try {
int offset=cl.getLocation().getStartOffset( d );
int length=cl.getLocation().getLength( d );
if (cl.getText().length()==0){ // nothing more on deleted line: delete the whole line
int line=d.getLineOfOffset( offset );
int len=d.getLineLength(line);
String del=d.getLineDelimiter( line );
int lenDel=del!=null?del.length():0;
if (length==len-lenDel){
length+=lenDel;
}
}
ReplaceEdit re=new ReplaceEdit( offset, length, cl.getText() );
mte.addChild( re );
} catch (BadLocationException ble){
HaskellUIPlugin.log( ble );
}
}

display.asyncExec( new Runnable(){
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
for (ImportClean cl:cleans){
//replaceWithFormatting(d,cl);
try {
int start=cl.getLocation().getStartOffset( d );
int length=cl.getLocation().getLength( d );
d.replace( start , length, cl.getText());
// remove empty lines
if (cl.getText().length()==0){
int line=d.getLineOfOffset( start );
int len=d.getLineLength(line );
String del=d.getLineDelimiter( line );
if (del!=null && del.length()==len){
d.replace( start, len,"" );
}
}
} catch (BadLocationException ble){
HaskellUIPlugin.log( ble );
}
try {
dc.perform( new NullProgressMonitor() );
} catch (CoreException ce){
HaskellUIPlugin.log( ce );
}
// for (ImportClean cl:cleans){
// //replaceWithFormatting(d,cl);
// try {
// int start=cl.getLocation().getStartOffset( d );
// int length=cl.getLocation().getLength( d );
// d.replace( start , length, cl.getText());
// // remove empty lines
// if (cl.getText().length()==0){
// int line=d.getLineOfOffset( start );
// int len=d.getLineLength(line );
// String del=d.getLineDelimiter( line );
// if (del!=null && del.length()==len){
// d.replace( start, len,"" );
// }
// }
// } catch (BadLocationException ble){
// HaskellUIPlugin.log( ble );
// }
// }

}
} );
Expand Down

0 comments on commit 2561011

Please sign in to comment.