@@ -25,7 +25,7 @@ import Control.Monad.Trans.Class
2525import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
2626import Control.Monad.Trans.State
2727
28−import Data.List (intercalate, isPrefixOf, nub, sort)
28+import Data.List (intercalate, isPrefixOf, nub, sortBy)
2929import Data.Maybe (mapMaybe)
3030import Data.Traversable (traverse)
3131
@@ -158,17 +158,20 @@ completion ms = completeWord Nothing " \t\n\r" findCompletions
158158 findCompletions :: String -> IO [Completion]
159159 findCompletions str = do
160160 files <- listFiles str
161− let names = nub [ show qual
162− | P.Module moduleName ds <- ms
163− , ident <- mapMaybe getDeclName ds
164− , qual <- [ P.Qualified Nothing ident
165− , P.Qualified (Just moduleName) ident]
166− ]
167− let matches = sort $ filter (isPrefixOf str) names
168− return $ map simpleCompletion matches ++ files
161+ let matches = filter (isPrefixOf str) names
162+ return $ sortBy sorter $ map simpleCompletion matches ++ files
169163 getDeclName :: P.Declaration -> Maybe P.Ident
170164 getDeclName (P.ValueDeclaration ident _ _ _) = Just ident
171165 getDeclName _ = Nothing
166+ names :: [String]
167+ names = nub [ show qual
168+ | P.Module moduleName ds <- ms
169+ , ident <- mapMaybe getDeclName ds
170+ , qual <- [ P.Qualified Nothing ident
171+ , P.Qualified (Just moduleName) ident]
172+ ]
173+ sorter :: Completion -> Completion -> Ordering
174+ sorter (Completion _ d1 _) (Completion _ d2 _) = compare d1 d2
172175
173176-- Compilation
174177