[commit: ghc] master: Fix ghci tab completion of duplicate identifiers. (1d71e96)

git at git.haskell.org git at git.haskell.org
Mon Jul 14 02:39:39 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/1d71e96958cb4374b383e2f254b5358386bf835c/ghc

>---------------------------------------------------------------

commit 1d71e96958cb4374b383e2f254b5358386bf835c
Author: Shachaf Ben-Kiki <shachaf at gmail.com>
Date:   Sun Jul 13 15:19:33 2014 -0500

    Fix ghci tab completion of duplicate identifiers.
    
    Summary:
    Currently, if the same identifier is imported via multiple modules, ghci
    shows multiple completions for it. Use the nub of the completions
    instead so that it only shows up once.
    
    Signed-off-by: Shachaf Ben-Kiki <shachaf at gmail.com>
    
    Test Plan: by hand
    
    Reviewers: simonmar, austin, hvr
    
    Reviewed By: austin, hvr
    
    Subscribers: hvr, simonmar, relrod, carter
    
    Differential Revision: https://phabricator.haskell.org/D58


>---------------------------------------------------------------

1d71e96958cb4374b383e2f254b5358386bf835c
 compiler/utils/Util.lhs | 6 +++++-
 ghc/InteractiveUI.hs    | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs
index 0274c59..2dcc73f 100644
--- a/compiler/utils/Util.lhs
+++ b/compiler/utils/Util.lhs
@@ -47,7 +47,7 @@ module Util (
         nTimes,
 
         -- * Sorting
-        sortWith, minWith,
+        sortWith, minWith, nubSort,
 
         -- * Comparisons
         isEqual, eqListBy, eqMaybeBy,
@@ -126,6 +126,7 @@ import Data.Ord         ( comparing )
 import Data.Bits
 import Data.Word
 import qualified Data.IntMap as IM
+import qualified Data.Set as Set
 
 import Data.Time
 #if __GLASGOW_HASKELL__ < 705
@@ -490,6 +491,9 @@ sortWith get_key xs = sortBy (comparing get_key) xs
 minWith :: Ord b => (a -> b) -> [a] -> a
 minWith get_key xs = ASSERT( not (null xs) )
                      head (sortWith get_key xs)
+
+nubSort :: Ord a => [a] -> [a]
+nubSort = Set.toAscList . Set.fromList
 \end{code}
 
 %************************************************************************
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index c3d9f25..ef48c34 100644
--- a/ghc/InteractiveUI.hs
+++ b/ghc/InteractiveUI.hs
@@ -2536,14 +2536,14 @@ unionComplete f1 f2 line = do
 
 wrapCompleter :: String -> (String -> GHCi [String]) -> CompletionFunc GHCi
 wrapCompleter breakChars fun = completeWord Nothing breakChars
-    $ fmap (map simpleCompletion) . fmap sort . fun
+    $ fmap (map simpleCompletion . nubSort) . fun
 
 wrapIdentCompleter :: (String -> GHCi [String]) -> CompletionFunc GHCi
 wrapIdentCompleter = wrapCompleter word_break_chars
 
 wrapIdentCompleterWithModifier :: String -> (Maybe Char -> String -> GHCi [String]) -> CompletionFunc GHCi
 wrapIdentCompleterWithModifier modifChars fun = completeWordWithPrev Nothing word_break_chars
-    $ \rest -> fmap (map simpleCompletion) . fmap sort . fun (getModifier rest)
+    $ \rest -> fmap (map simpleCompletion . nubSort) . fun (getModifier rest)
  where
   getModifier = find (`elem` modifChars)
 



More information about the ghc-commits mailing list