diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2013-11-02 11:58:09 +0100 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2013-11-04 09:11:28 +0100 |
commit | 7e4406b282647587384981f6b5ee8d7c6309373d (patch) | |
tree | b6e8a81440304e87598462cdb6e3f10dd623439a /ghc | |
parent | 7ea0c63b0f8672d98ee834cadb2ab9f7cf4a4248 (diff) | |
download | haskell-7e4406b282647587384981f6b5ee8d7c6309373d.tar.gz |
Tweak lookup semantics for GHCi macros
This changes the prefix-based lookup to prefer macros over builtins only if
the macro name matches an existing builtin name. See #8305 for more details.
Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
Diffstat (limited to 'ghc')
-rw-r--r-- | ghc/InteractiveUI.hs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs index eb32aa6e0c..5413a1ac5c 100644 --- a/ghc/InteractiveUI.hs +++ b/ghc/InteractiveUI.hs @@ -986,15 +986,23 @@ lookupCommand' ":" = return Nothing lookupCommand' str' = do macros <- liftIO $ readIORef macros_ref ghci_cmds <- ghci_commands `fmap` getGHCiState - let{ (str, cmds) = case str' of - ':' : rest -> (rest, ghci_cmds) -- "::" selects a builtin command - _ -> (str', macros ++ ghci_cmds) } -- otherwise prefer macros - -- look for exact match first, then the first prefix match - return $ case [ c | c <- cmds, str == cmdName c ] of - c:_ -> Just c - [] -> case [ c | c@(s,_,_) <- cmds, str `isPrefixOf` s ] of - [] -> Nothing - c:_ -> Just c + let (str, xcmds) = case str' of + ':' : rest -> (rest, []) -- "::" selects a builtin command + _ -> (str', macros) -- otherwise include macros in lookup + + lookupExact s = find $ (s ==) . cmdName + lookupPrefix s = find $ (s `isPrefixOf`) . cmdName + + builtinPfxMatch = lookupPrefix str ghci_cmds + + -- first, look for exact match (while preferring macros); then, look + -- for first prefix match (preferring builtins), *unless* a macro + -- overrides the builtin; see #8305 for motivation + return $ lookupExact str xcmds <|> + lookupExact str ghci_cmds <|> + (builtinPfxMatch >>= \c -> lookupExact (cmdName c) xcmds) <|> + builtinPfxMatch <|> + lookupPrefix str xcmds getCurrentBreakSpan :: GHCi (Maybe SrcSpan) getCurrentBreakSpan = do |