Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

format imports

  • Loading branch information...
commit 694d51019bfb558334b38f13ebb307bdd89345a4 1 parent 3e6bd3d
@JPMoresmau authored
View
1  docs/releasenotes/net.sf.eclipsefp.haskell_2.4.3.txt
@@ -13,6 +13,7 @@ Fixes:
- Viewing a package in the browser from the Cabal Packages view the first time could cause a NullPointerException
- Removing via quick fix an unused type in import list did not remove constructors
- Report errors from alex and happy building
+ - Syntax highlighting more stable on big files
Features:
- Cabal Packages view shows a green tick on installed packages and versions when you display the list of all hackage packages.
View
3  net.sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/BWFacade.java
@@ -670,11 +670,12 @@ public BuildFlags getBuildFlags(IFile file){
return null;
}
- public List<ImportClean> cleanImports(IFile file){
+ public List<ImportClean> cleanImports(IFile file,boolean format){
String path=file.getProjectRelativePath().toOSString();
LinkedList<String> command=new LinkedList<String>();
command.add("cleanimports");
command.add("--file="+path);
+ command.add("--format="+format);
addEditorStanza(file,command);
JSONArray arr=run(command,ARRAY);
List<ImportClean> ret=new ArrayList<ImportClean>();
View
4 net.sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/JobFacade.java
@@ -325,7 +325,7 @@ public IProject getProject() {
return realFacade.getProject();
}
- public void cleanImport(final IFile file, final ImportCleanHandler handler){
+ public void cleanImport(final IFile file,final boolean format, final ImportCleanHandler handler){
final String jobNamePrefix = NLS.bind(BWText.job_import_clean, file.getName());
Job buildJob = new Job (jobNamePrefix) {
@@ -334,7 +334,7 @@ protected IStatus run(IProgressMonitor monitor) {
try {
monitor.beginTask(jobNamePrefix, IProgressMonitor.UNKNOWN);
//long t0=System.currentTimeMillis();
- handler.handleImportCleans(realFacade.cleanImports(file));
+ handler.handleImportCleans(realFacade.cleanImports(file,format));
//long t1=System.currentTimeMillis();
//BuildWrapperPlugin.logInfo("thingAtPoint:"+(t1-t0)+"ms");
} finally {
View
61 ...eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/imports/ImportCleaner.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2012 by JP Moresmau
+ * Copyright (c) 2013 by JP Moresmau
* This code is made available under the terms of the Eclipse Public License,
* version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
*/
@@ -22,11 +22,16 @@
/**
+ * Process the imports cleaning instructions from buildwrapper
* @author JP Moresmau
*
*/
public class ImportCleaner {
+ public boolean doFormat(){
+ return true;
+ }
+
public void cleanFile(final ITextEditor editor){
if (editor instanceof HaskellEditor) {
HaskellEditor hEditor = (HaskellEditor) editor;
@@ -36,11 +41,14 @@ public void cleanFile(final ITextEditor editor){
if (bwf!=null){
final IDocument d= ( ( HaskellEditor )editor ).getDocument();
final Display display=Display.findDisplay( Thread.currentThread() );
- bwf.cleanImport( f, new ImportCleanHandler() {
+ bwf.cleanImport( f,doFormat(), new ImportCleanHandler() {
@Override
public void handleImportCleans( final List<ImportClean> cleans ) {
if (cleans!=null){
+ /**
+ * order in reverse order to keep lines always valid even when document changes
+ */
Collections.sort( cleans,new Comparator<ImportClean>() {
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
@@ -57,10 +65,11 @@ public int compare( final ImportClean o1, final ImportClean o2 ) {
@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() );
+ d.replace( start , length, cl.getText());
} catch (BadLocationException ble){
HaskellUIPlugin.log( ble );
}
@@ -79,6 +88,48 @@ public void run() {
}
}
-
-
+// private static void replaceWithFormatting(final IDocument d,final ImportClean cl){
+// try {
+// int start=cl.getLocation().getStartOffset( d );
+// int length=cl.getLocation().getLength( d );
+// String s=d.get( start , length );
+// int sp=getExtraSpacesAfterImport( s );
+// String rep=cl.getText();
+// if (sp>0){
+// rep=setExtraSpacesAfterImport( rep, sp );
+// }
+//
+// d.replace( start , length, rep);
+// } catch (BadLocationException ble){
+// HaskellUIPlugin.log( ble );
+// }
+// }
+//
+// private static int getExtraSpacesAfterImport(final String s){
+// int ix=s.indexOf( "import" );
+// if (ix>-1){
+// int sp=0;
+// ix+="import".length();
+// for (;ix<s.length() && Character.isWhitespace( s.charAt( ix ));ix++){
+// sp++;
+// }
+// return sp-1;
+// }
+// return 0;
+// }
+//
+// private static String setExtraSpacesAfterImport(final String s,final int spaces){
+// int ix=s.indexOf( "import" );
+// if (ix>-1){
+// StringBuilder sb=new StringBuilder();
+// ix+="import".length();
+// sb.append(s.substring( 0,ix ));
+// for (int a=0;a<spaces;a++){
+// sb.append(' ');
+// }
+// sb.append(s.substring( ix ));
+// return sb.toString();
+// }
+// return s;
+// }
}
Please sign in to comment.
Something went wrong with that request. Please try again.