Permalink
Browse files

resolve multiple suggestions

  • Loading branch information...
JPMoresmau committed Jan 15, 2013
1 parent 75401ef commit 934ac4fc8d655953a0f8c6043fb016271041bb76
@@ -15,6 +15,7 @@ Fixes:
- Report errors from alex and happy building
- Syntax highlighting more stable on big files
- Haskell test results does not reclaim focus on each refresh, less flicker on update
+ - Quick fix on multiple GHC suggestions
Features:
- Cabal Packages view shows a green tick on installed packages and versions when you display the list of all hackage packages.
@@ -37,6 +37,7 @@
public static String NOT_IN_SCOPE_START="not in scope: "; //$NON-NLS-1$
public static String NOT_IN_SCOPE_END="'"; //$NON-NLS-1$
public static String NOT_IN_SCOPE_SUGGESTION="perhaps you meant"; //$NON-NLS-1$
+ public static String NOT_IN_SCOPE_SUGGESTION_MULTIPLE="perhaps you meant one of these:"; //$NON-NLS-1$
public static String IS_A_DATA_CONSTRUCTOR="is a data constructor"; //$NON-NLS-1$
@@ -0,0 +1,50 @@
+/**
+ * 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
+ */
+package net.sf.eclipsefp.haskell.ui.internal.resolve;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.util.List;
+import org.junit.Test;
+
+
+/**
+ * Test resolution from GHCMessages
+ * @author JP Moresmau
+ *
+ */
+public class ResolveFromMessageTests {
+
+ @Test
+ public void testOneSuggestion(){
+ String msg="Perhaps you meant `maybe' (imported from Prelude)";
+ List<String> sugs=ReplaceTextResolution.getSuggestionsFromGHCMessage( msg );
+ assertNotNull( sugs );
+ assertEquals( 1, sugs.size() );
+ assertEquals("maybe",sugs.get( 0 ));
+ }
+
+ @Test
+ public void testTwoSuggestions(){
+ String msg="Perhaps you meant one of these:\n `unzip' (imported from Prelude), `unzip3' (imported from Prelude)";
+ List<String> sugs=ReplaceTextResolution.getSuggestionsFromGHCMessage( msg );
+ assertNotNull( sugs );
+ assertEquals( 2, sugs.size() );
+ assertEquals("unzip",sugs.get( 0 ));
+ assertEquals("unzip3",sugs.get( 1 ));
+ }
+
+ @Test
+ public void testQualifiedSuggestion(){
+ String msg="Perhaps you meant List.foldl' (imported from Data.List)";
+ List<String> sugs=ReplaceTextResolution.getSuggestionsFromGHCMessage( msg );
+ assertNotNull( sugs );
+ assertEquals( 1, sugs.size() );
+ assertEquals("List.foldl'",sugs.get( 0 ));
+ }
+
+
+}
@@ -136,16 +136,10 @@ else if (msgL.indexOf(GhcMessages.MISSING_MODULE)>-1){
else if (msgL.indexOf( GhcMessages.NOT_IN_SCOPE_START )>-1){
int start = msgL.indexOf( '`',msgL.indexOf( GhcMessages.NOT_IN_SCOPE_START ));
int l=msgL.indexOf( "\n",start+1 );
- String suggestion=null;
+ List<String> suggestions=null;
if (l>-1){
String sug=msg.substring( l );
- int startSug = sug.indexOf( '`');
- if(startSug>-1){
- int endSug=sug.lastIndexOf( GhcMessages.NOT_IN_SCOPE_END );
- if (endSug>-1){
- suggestion=sug.substring(startSug+1,endSug);
- }
- }
+ suggestions=ReplaceTextResolution.getSuggestionsFromGHCMessage( sug,msgL.substring( l ) );
msgL=msgL.substring( 0,l );
}
int end = msgL.lastIndexOf( GhcMessages.NOT_IN_SCOPE_END );
@@ -159,8 +153,10 @@ else if (msgL.indexOf( GhcMessages.NOT_IN_SCOPE_START )>-1){
name = notInScope;
qualified = null;
}
- if (suggestion!=null){
- res.add( new ReplaceTextResolution( notInScope, suggestion ) );
+ if (suggestions!=null){
+ for (String suggestion:suggestions){
+ res.add( new ReplaceTextResolution( notInScope, suggestion ) );
+ }
}
try {
if (BrowserPlugin.getSharedInstance().isAnyDatabaseLoaded()) {
@@ -5,6 +5,10 @@
*/
package net.sf.eclipsefp.haskell.ui.internal.resolve;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import net.sf.eclipsefp.haskell.buildwrapper.types.GhcMessages;
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
import net.sf.eclipsefp.haskell.ui.util.HaskellUIImages;
@@ -60,4 +64,46 @@ public ICompletionProposal getCompletionProposal( final IMarker marker,
}
return null;
}
+
+ public static List<String> getSuggestionsFromGHCMessage(final String msg){
+ return getSuggestionsFromGHCMessage( msg ,msg.toLowerCase( Locale.ENGLISH ));
+ }
+
+ public static List<String> getSuggestionsFromGHCMessage(String msg,final String msgL){
+ List<String> suggestions=new ArrayList<String>();
+ int start=msgL.indexOf( GhcMessages.NOT_IN_SCOPE_SUGGESTION_MULTIPLE );
+ if (start==-1){
+ start=msgL.indexOf( GhcMessages.NOT_IN_SCOPE_SUGGESTION );
+ if (start>-1){
+ start+=GhcMessages.NOT_IN_SCOPE_SUGGESTION.length();
+ }
+ } else {
+ start+=GhcMessages.NOT_IN_SCOPE_SUGGESTION_MULTIPLE.length();
+ }
+ if (start==-1){
+ return suggestions;
+ }
+ msg=msg.substring( start);
+ int openParensIx=msg.indexOf( '(' );
+ while (openParensIx>-1){
+ String sug=msg.substring( 0,openParensIx );
+ if (sug.startsWith( "," )){
+ sug=sug.substring( 1 );
+ }
+ sug=sug.trim();
+ if (sug.startsWith( "`") && sug.endsWith( "'" )){
+ sug=sug.substring( 1,sug.length()-1 );
+ }
+ suggestions.add(sug);
+ int closeParensIx=msg.indexOf( ')',openParensIx );
+ if (closeParensIx>-1){
+ msg=msg.substring( closeParensIx+1 );
+ openParensIx=msg.indexOf( '(' );
+ } else {
+ openParensIx=-1;
+ }
+ }
+
+ return suggestions;
+ }
}

0 comments on commit 934ac4f

Please sign in to comment.