summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorlykahb@gmail.com <unknown>2010-09-01 16:01:53 +0000
committerlykahb@gmail.com <unknown>2010-09-01 16:01:53 +0000
commitcd307a057404c7fcdb428c4b30fecccc1da3401b (patch)
treec693a7e9e7cac281d9ece68ac87b38d1fc1bc52a /ghc
parentf10947d79cdfac8f8b065ef51a10d9c9cf3c19bc (diff)
downloadhaskell-cd307a057404c7fcdb428c4b30fecccc1da3401b.tar.gz
Remove context completion
Now completion suggests to remove only modules added to context before.
Diffstat (limited to 'ghc')
-rw-r--r--ghc/InteractiveUI.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 24079bb49b..7b3f6b9a59 100644
--- a/ghc/InteractiveUI.hs
+++ b/ghc/InteractiveUI.hs
@@ -140,7 +140,7 @@ builtin_commands = [
("kind", keepGoing' kindOfType, completeIdentifier),
("load", keepGoingPaths loadModule_, completeHomeModuleOrFile),
("list", keepGoing' listCmd, noCompletion),
- ("module", keepGoing setContext, completeModule),
+ ("module", keepGoing setContext, completeSetModule),
("main", keepGoing runMain, completeFilename),
("print", keepGoing printCmd, completeExpression),
("quit", quit, noCompletion),
@@ -1711,6 +1711,18 @@ completeModule = wrapIdentCompleter $ \w -> do
return $ filter (w `isPrefixOf`)
$ map (showSDoc.ppr) $ loaded_mods ++ pkg_mods
+completeSetModule = wrapIdentCompleterWithModifier "+-" $ \m w -> do
+ modules <- case m of
+ Just '-' -> do
+ (toplevs, exports) <- GHC.getContext
+ return $ map GHC.moduleName (nub (map fst exports) ++ toplevs)
+ otherwise -> do
+ dflags <- GHC.getSessionDynFlags
+ let pkg_mods = allExposedModules dflags
+ loaded_mods <- liftM (map GHC.ms_mod_name) getLoadedModules
+ return $ loaded_mods ++ pkg_mods
+ return $ filter (w `isPrefixOf`) $ map (showSDoc.ppr) modules
+
completeHomeModule = wrapIdentCompleter listHomeModules
listHomeModules :: String -> GHCi [String]
@@ -1748,6 +1760,12 @@ wrapCompleter breakChars fun = completeWord Nothing breakChars
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)
+ where
+ getModifier = find (`elem` modifChars)
+
allExposedModules :: DynFlags -> [ModuleName]
allExposedModules dflags
= concat (map exposedModules (filter exposed (eltsUFM pkg_db)))