Permalink
Browse files

Do not set selection on quick fix import+ pragma

  • Loading branch information...
1 parent 4e0ea01 commit 7530f1d2bad758eb11b189fe0cf217a4731e1cc5 @JPMoresmau committed Feb 5, 2014
@@ -15,7 +15,7 @@
import net.sf.eclipsefp.haskell.buildwrapper.types.Location;
import net.sf.eclipsefp.haskell.core.cabalmodel.TestDocument;
import net.sf.eclipsefp.haskell.util.PlatformUtil;
-import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.junit.Test;
@@ -32,7 +32,7 @@ public void testRemoveSimple(){
Location loc=new Location( "TestSimpleRemove.hs",2,0,2,44);
ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "singleton" , "remove" );
+ ICompletionProposal cp=ai.removeItem( td, "singleton" , "remove" );
assertNotNull( cp );
cp.apply( td );
// test at end
@@ -56,7 +56,7 @@ public void testRemoveConstructor(){
Location loc=new Location( "TestSimpleRemove.hs",2,0,2,48);
ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "Seq" , "remove" );
+ ICompletionProposal cp=ai.removeItem( td, "Seq" , "remove" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton, empty)"+PlatformUtil.NL,td.get());
@@ -69,7 +69,7 @@ public void testRemoveConstructorAtEnd(){
Location loc=new Location( "TestSimpleRemove.hs",2,0,2,48);
ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "Seq" , "remove" );
+ ICompletionProposal cp=ai.removeItem( td, "Seq" , "remove" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton, empty)"+PlatformUtil.NL,td.get());
@@ -82,7 +82,7 @@ public void testRemoveMultipleAtEnd(){
Location loc=new Location( "TestSimpleRemove.hs",2,0,2,48);
ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, Arrays.asList("Seq","singleton") , "remove" );
+ ICompletionProposal cp=ai.removeItem( td, Arrays.asList("Seq","singleton") , "remove" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (empty)"+PlatformUtil.NL,td.get());
@@ -95,7 +95,7 @@ public void testRemoveLast(){
Location loc=new Location( "TestSimpleRemove.hs",2,0,2,26);
ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "Seq" , "remove" );
+ ICompletionProposal cp=ai.removeItem( td, "Seq" , "remove" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ()"+PlatformUtil.NL,td.get());
@@ -120,7 +120,7 @@ public void testRemoveOperator(){
Location loc=new Location( "TestSimpleRemove.hs",2,0,2,32);
ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "><" , "remove" );
+ ICompletionProposal cp=ai.removeItem( td, "><" , "remove" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq)"+PlatformUtil.NL,td.get());
@@ -132,7 +132,7 @@ public void testRemoveSuperStringBefore(){
Location loc=new Location( "testRemoveSuperString.hs",2,0,2,56);
ImportDef def=new ImportDef( "Control.Monad.Trans.Reader", loc, false, false, null );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "runReader" , "remove" );
+ ICompletionProposal cp=ai.removeItem( td, "runReader" , "remove" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Control.Monad.Trans.Reader (runReaderT)"+PlatformUtil.NL,td.get());
@@ -144,7 +144,7 @@ public void testRemoveSuperStringAfter(){
Location loc=new Location( "testRemoveSuperString.hs",2,0,2,56);
ImportDef def=new ImportDef( "Control.Monad.Trans.Reader", loc, false, false, null );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "runReader" , "remove" );
+ ICompletionProposal cp=ai.removeItem( td, "runReader" , "remove" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Control.Monad.Trans.Reader (runReaderT)"+PlatformUtil.NL,td.get());
@@ -161,7 +161,7 @@ public void testAddSimple(){
def.getChildren().add(sp1);
def.getChildren().add(sp2);
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.addItem(td, "singleton" , "add" );
+ ICompletionProposal cp=ai.addItem(td, "singleton" , "add" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ((><), Seq, singleton)"+PlatformUtil.NL,td.get());
@@ -176,7 +176,7 @@ public void testAddToNoChildren(){
Location loc=new Location( "TestSimpleRemove.hs",2,0,2,20);
ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.addItem(td, "singleton" , "add" );
+ ICompletionProposal cp=ai.addItem(td, "singleton" , "add" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton)"+PlatformUtil.NL,td.get());
@@ -189,7 +189,7 @@ public void testAddToEmptyChildren(){
ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
def.setChildren( new ArrayList<ImportSpecDef>() );
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.addItem(td, "singleton" , "add" );
+ ICompletionProposal cp=ai.addItem(td, "singleton" , "add" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton)"+PlatformUtil.NL,td.get());
@@ -204,7 +204,7 @@ public void testAddOperator(){
def.setChildren( new ArrayList<ImportSpecDef>() );
def.getChildren().add(sp1);
AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.addItem(td, "><" , "add" );
+ ICompletionProposal cp=ai.addItem(td, "><" , "add" );
assertNotNull( cp );
cp.apply( td );
assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, (><))"+PlatformUtil.NL,td.get());
@@ -39,10 +39,11 @@
import net.sf.eclipsefp.haskell.core.util.ResourceUtil;
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor;
+import net.sf.eclipsefp.haskell.ui.internal.resolve.DiscreteCompletionProposal;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
/**
* Represents information about an import: if it's qualified,
@@ -353,7 +354,7 @@ public static void outlineToBrowser( final OutlineDef def ,final OutlineDef pare
}
}
- public CompletionProposal addItem(final IDocument doc, final String item, final String label) {
+ public ICompletionProposal addItem(final IDocument doc, final String item, final String label) {
try {
String ritem=item;
char c0=ritem.charAt( 0 );
@@ -371,8 +372,8 @@ public CompletionProposal addItem(final IDocument doc, final String item, final
int pos = contents.indexOf( '(' );
if (pos==-1){
- return new CompletionProposal( " ("+ritem+")", en, 0,
- ritem.length(), ImageCache.MODULE, label, null, "" );
+ return new DiscreteCompletionProposal( " ("+ritem+")", en, 0,
+ ImageCache.MODULE, label, null, "" );
}
// We have some items
// Trim end the elements
@@ -385,7 +386,7 @@ public CompletionProposal addItem(final IDocument doc, final String item, final
if (importDef.getChildren()!=null && importDef.getChildren().size()>0){
contentsToAdd = ", " + ritem;
}
- return new CompletionProposal( contentsToAdd, insert, 0, contentsToAdd.length(),
+ return new DiscreteCompletionProposal( contentsToAdd, insert, 0,
ImageCache.MODULE, label, null, "" );
} catch (Exception e) {
e.printStackTrace();
@@ -422,7 +423,7 @@ public CompletionProposal addItem(final IDocument doc, final String item, final
return new int[]{tstart,tend};
}
- public CompletionProposal removeItem(final IDocument doc, final String item, final String label) {
+ public ICompletionProposal removeItem(final IDocument doc, final String item, final String label) {
// try {
// String contents = importDef.getLocation().getContents( doc );
// int ixP=contents.indexOf( "(" );
@@ -467,7 +468,7 @@ private boolean isItemBoundary(final char c){
return Character.isWhitespace( c ) || c==',' || c=='(' || c==')';
}
- public CompletionProposal removeItem(final IDocument doc, final Collection<String> items, final String label) {
+ public ICompletionProposal removeItem(final IDocument doc, final Collection<String> items, final String label) {
try {
String contents = importDef.getLocation().getContents( doc );
String newContents=contents;
@@ -515,15 +516,15 @@ public CompletionProposal removeItem(final IDocument doc, final Collection<Strin
}
}
int st=importDef.getLocation().getStartOffset( doc );
- return new CompletionProposal( newContents.toString(), st, contents.length(),
- 0, ImageCache.MODULE, label, null, "" );
+ return new DiscreteCompletionProposal( newContents.toString(), st, contents.length(),
+ ImageCache.MODULE, label, null, "" );
} catch (Exception e) {
HaskellUIPlugin.log( e );
}
return null;
}
- public CompletionProposal replaceItem(final IDocument doc, final String item, final String newItem, final String label) {
+ public ICompletionProposal replaceItem(final IDocument doc, final String item, final String newItem, final String label) {
try {
String contents = importDef.getLocation().getContents( doc );
@@ -533,8 +534,8 @@ public CompletionProposal replaceItem(final IDocument doc, final String item, fi
int st=importDef.getLocation().getStartOffset( doc );
String newContents=contents.substring( 0,ix )+newItem+contents.substring( end );
- return new CompletionProposal( newContents.toString(), st, contents.length(),
- 0, ImageCache.MODULE, label, null, "" );
+ return new DiscreteCompletionProposal( newContents.toString(), st, contents.length(),
+ ImageCache.MODULE, label, null, "" );
}
} catch (Exception e) {
HaskellUIPlugin.log( e );
@@ -20,10 +20,11 @@
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor;
import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.imports.AnImport.FileDocumented;
+import net.sf.eclipsefp.haskell.ui.internal.resolve.DiscreteCompletionProposal;
import net.sf.eclipsefp.haskell.util.PlatformUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
/**
* Manages information and changed in the imports section
@@ -148,7 +149,7 @@ private void getImportDeclarations(final Map<String, Imported> r,final AnImport
}
}
- public CompletionProposal addImport( final String name, final String place, final String qualified, final String label ) {
+ public ICompletionProposal addImport( final String name, final String place, final String qualified, final String label ) {
AnImport lastImport = null;
for (AnImport imp : parseImports()) {
lastImport = imp;
@@ -183,7 +184,7 @@ public CompletionProposal addImport( final String name, final String place, fina
contents = "import " + place + " (" + name + ")";
}
// 3. Create the proposal
- return new CompletionProposal( contents + PlatformUtil.NL, offsetToPut, 0, contents.length() + 1, ImageCache.MODULE, label, null, "" );
+ return new DiscreteCompletionProposal( contents + PlatformUtil.NL, offsetToPut, 0, ImageCache.MODULE, label, null, "" );
} catch (Exception e) {
HaskellUIPlugin.log( e );
return null;
@@ -205,7 +206,7 @@ public CompletionProposal addImport( final String name, final String place, fina
// return null;
// }
- public CompletionProposal removeItemInImport(final Collection<String> names, final int line, final String label) {
+ public ICompletionProposal removeItemInImport(final Collection<String> names, final int line, final String label) {
try {
for (AnImport imp : parseImports()) {
int importLine =imp.getImportDef().getLocation().getStartLine();
@@ -220,7 +221,7 @@ public CompletionProposal removeItemInImport(final Collection<String> names, fin
return null;
}
- public CompletionProposal replaceItemInImport(final String name,final String newName, final int line, final String label) {
+ public ICompletionProposal replaceItemInImport(final String name,final String newName, final int line, final String label) {
try {
for (AnImport imp : parseImports()) {
int importLine =imp.getImportDef().getLocation().getStartLine();
@@ -8,7 +8,6 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.osgi.util.NLS;
@@ -103,7 +102,7 @@ public ICompletionProposal getCompletionProposal( final IMarker marker,final IDo
}
}
- return new CompletionProposal(repl, lineOffset+pragmaOffset, 0, 0,null,getLabel(),null,null );
+ return new DiscreteCompletionProposal(repl, lineOffset+pragmaOffset, 0,null,getLabel(),null,null );
} catch( BadLocationException ex ) {
HaskellUIPlugin.log( ex );
}
Oops, something went wrong.

0 comments on commit 7530f1d

Please sign in to comment.