Skip to content
This repository has been archived by the owner on Feb 10, 2020. It is now read-only.

Commit

Permalink
Filter exported names in psci autocomplete method purescript#238
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Mar 6, 2014
1 parent d21440c commit 973babe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 0 additions & 1 deletion docgen/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ renderModules ms = do
headerLevel 1 "Module Documentation"
mapM_ renderModule ms

-- TODO: filter everything by exports
renderModule :: P.Module -> Docs
renderModule (P.Module moduleName ds exps) =
let exported = filter (isExported exps) ds
Expand Down
3 changes: 3 additions & 0 deletions examples/passing/ExportExplicit.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module M1 (X(X), Z(..), foo) where
foo :: Number
foo = 0

bar :: Number
bar = 1

module Main where

import M1
Expand Down
15 changes: 10 additions & 5 deletions psci/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,18 @@ completion = completeWord Nothing " \t\n\r" findCompletions
files <- listFiles str
let matches = filter (isPrefixOf str) (names ms)
return $ sortBy sorter $ map simpleCompletion matches ++ files
getDeclName :: P.Declaration -> Maybe P.Ident
getDeclName (P.ValueDeclaration ident _ _ _) = Just ident
getDeclName _ = Nothing
getDeclName :: Maybe [P.DeclarationRef] -> P.Declaration -> Maybe P.Ident
getDeclName Nothing (P.ValueDeclaration ident _ _ _) = Just ident
getDeclName (Just exts) (P.ValueDeclaration ident _ _ _) | isExported = Just ident
where
isExported = flip any exts $ \e -> case e of
P.ValueRef ident' -> ident == ident'
_ -> False
getDeclName _ _ = Nothing
names :: [P.Module] -> [String]
names ms = nub [ show qual
| P.Module moduleName ds _ <- ms
, ident <- mapMaybe getDeclName ds
| P.Module moduleName ds exts <- ms
, ident <- mapMaybe (getDeclName exts) ds
, qual <- [ P.Qualified Nothing ident
, P.Qualified (Just moduleName) ident]
]
Expand Down

0 comments on commit 973babe

Please sign in to comment.