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

Merge ghc-imported-from into ghc-mod #810

Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
2485221
Merging the ghc-imported-from utility.
carlohamalainen Jul 12, 2016
5126454
Dependencies for imported-from command.
carlohamalainen Jul 12, 2016
4e4f69c
Add imported-from command.
carlohamalainen Jul 12, 2016
bd62eb0
Fix a type error.
carlohamalainen Jul 12, 2016
5d26b71
Remove bound on process-streaming.
carlohamalainen Jul 12, 2016
6339f63
Fix bounds for haddock-api with ghc 7.x and 8.x
carlohamalainen Jul 12, 2016
875b513
Revert ghc-mod.cabal to current master.
carlohamalainen Jul 15, 2016
ae39594
Import in alphabetical position.
carlohamalainen Jul 15, 2016
47becac
LANGUAGE extensions on one line.
carlohamalainen Jul 15, 2016
ffc755b
Remove unused import.
carlohamalainen Jul 15, 2016
cfb9693
Revert to current master.
carlohamalainen Jul 15, 2016
07e4be3
Remove dependency on System.Process.Streaming
carlohamalainen Jul 15, 2016
af4e620
Use gmReadProcess. Builds and tests pass with ghc-7.10.3
carlohamalainen Jul 15, 2016
1736e24
Fix import for Control.Applicative
carlohamalainen Jul 16, 2016
d9c9477
Avoid use of "traverse" which is not in ghc-7.6.3
carlohamalainen Jul 16, 2016
7b8d5a7
Builds on ghc-7.6.3; added some fallback cases for earlier versions o…
carlohamalainen Jul 16, 2016
7fa7b12
Move #if things to Language.Haskell.GhcMod.Gap.
carlohamalainen Jul 16, 2016
1557ef1
Add type sig.
carlohamalainen Jul 16, 2016
d276260
Remove definition of tdflags (also gets rid of unsafeGlobalDynFlags).
carlohamalainen Jul 17, 2016
7106525
Remove constraints on GmOut and GmLog.
carlohamalainen Jul 17, 2016
048eaac
Fewer imports; move moduleNameToHtmlFile into a where clause.
carlohamalainen Jul 17, 2016
13e5cda
Move filterMatchingQualifiedImport to a where clause; tidy up
carlohamalainen Jul 17, 2016
f52077c
Use parameter of ```gmLog GmDebug``` instead of passing ```""```.
carlohamalainen Jul 17, 2016
50a52d2
Reformat some very long lines.
carlohamalainen Jul 17, 2016
1339dc5
Merge changes from master.
carlohamalainen Jul 17, 2016
ec38b27
Merging changes from master.
carlohamalainen Jul 17, 2016
84579ef
Tweaks for building on earlier versions of ghc.
carlohamalainen Jul 17, 2016
b94f2f4
Adjust ghc version bound on ghcIdeclHiding.
carlohamalainen Jul 17, 2016
6b11e9d
Tweaks for building on GHC8.
carlohamalainen Jul 19, 2016
ae4badb
Use exit code instead of printing SUCCESS / FAIL.
carlohamalainen Jul 19, 2016
fb1c146
Add ImportedFromSpec to test suite.
carlohamalainen Jul 19, 2016
fa1417a
Use top-level error GMEMissingHaddock when missing haddock html.
carlohamalainen Jul 19, 2016
40e3daf
Use GMError type instead of calling plain "error".
carlohamalainen Jul 19, 2016
b1c1b2a
Tidying up logging.
carlohamalainen Jul 20, 2016
9eb0cc8
Add note about setting documentation:True in .cabal/config.
carlohamalainen Jul 24, 2016
6f83fab
Tweak for resolver on internal symbols (tested with GHC8; added testc…
carlohamalainen Jul 24, 2016
2edda72
Forgot "$$".
carlohamalainen Jul 24, 2016
704cff6
Drop parens in qualified name. New in GHC8?
carlohamalainen Jul 24, 2016
cdbe0ef
Adding some more test cases.
carlohamalainen Jul 29, 2016
e2f6092
Remove dependency on parsec.
carlohamalainen Jul 30, 2016
f6ba25b
Tidyup some warnings.
carlohamalainen Jul 30, 2016
0961feb
Accidentally removed import of Control.Applicative.
carlohamalainen Jul 30, 2016
ea1d4a0
Instead of throwing an exception if the haddock file is missing,
carlohamalainen Aug 8, 2016
c37907c
Improved tests for imported-from command. Actually checks the output
carlohamalainen Aug 8, 2016
e413cea
Merge remote-tracking branch 'remotes/upstream/master' into ghc-impor…
carlohamalainen Aug 8, 2016
5eefa23
Don't use Python-style leading underscore.
carlohamalainen Aug 9, 2016
122cfd5
Remove dead code.
carlohamalainen Aug 9, 2016
f3c9268
Use things from Control.Monad.Trans.Maybe.
carlohamalainen Aug 9, 2016
fc02ddc
Remove unused dependency.
carlohamalainen Aug 9, 2016
a9fa573
Remove stackoverflow snippet.
carlohamalainen Aug 9, 2016
4897f16
Remove another ```fromMaybe (throw ...)``` pattern.
carlohamalainen Aug 9, 2016
2be2742
fail instead of throw; tidy up some definitions.
carlohamalainen Aug 9, 2016
8d4d2c7
Use a view pattern.
carlohamalainen Aug 9, 2016
21a81b2
Tidying up.
carlohamalainen Aug 9, 2016
e36a3c3
Flag for cabal install is --only-dependencies not --dependencies-only.
carlohamalainen Aug 9, 2016
83f27c6
Avoid use of ```nub```.
carlohamalainen Aug 9, 2016
c995e15
Note on use of ```last```.
carlohamalainen Aug 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
785 changes: 785 additions & 0 deletions Language/Haskell/GhcMod/ImportedFrom.hs

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Language/Haskell/GhcMod/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ gmRenderDoc = renderStyle docStyle

gmComponentNameDoc :: ChComponentName -> Doc
gmComponentNameDoc ChSetupHsName = text $ "Setup.hs"
gmComponentNameDoc (ChLibName "") = text $ "library"
gmComponentNameDoc (ChLibName n) = text $ "library:" ++ n
gmComponentNameDoc ChLibName = text $ "library"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're backpatching cabal-helper to <0.7, please don't :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this one, sorry for the weirdness.

commit cfb96931b2317743feab767fe565f5512ba286f5
Author: Carlo Hamalainen <[email protected]>
Date:   Fri Jul 15 22:42:57 2016 +1000

    Revert to current master.

Language/Haskell/GhcMod/Pretty.hs

gmComponentNameDoc (ChExeName n) = text $ "exe:" ++ n
gmComponentNameDoc (ChTestName n) = text $ "test:" ++ n
gmComponentNameDoc (ChBenchName n) = text $ "bench:" ++ n
Expand Down
13 changes: 12 additions & 1 deletion ghc-mod.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Library
Language.Haskell.GhcMod.Flag
Language.Haskell.GhcMod.Gap
Language.Haskell.GhcMod.GhcPkg
Language.Haskell.GhcMod.ImportedFrom
Copy link
Owner

@DanielG DanielG Jul 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"H" comes before "I", I like to keep this list (semi) sorted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit ae395943d94c340821c277181abdd90b1f5a0d57
Author: Carlo Hamalainen <[email protected]>
Date:   Fri Jul 15 21:13:05 2016 +1000

    Import in alphabetical position.

Language.Haskell.GhcMod.HomeModuleGraph
Language.Haskell.GhcMod.Info
Language.Haskell.GhcMod.Lang
Expand Down Expand Up @@ -174,9 +175,10 @@ Library
, bytestring < 0.11
, binary < 0.9 && >= 0.5.1.0
, containers < 0.6
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove the bounds please :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted ghc-mod.cabal:

commit 875b5137a867416bfa7416493a0aac0165c91222
Author: Carlo Hamalainen <[email protected]>
Date:   Fri Jul 15 21:09:59 2016 +1000

    Revert ghc-mod.cabal to current master.

, cabal-helper < 0.8 && >= 0.7.1.0
, cabal-helper
, deepseq < 1.5
, directory < 1.3
, exceptions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upper bounds please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now

exceptions        < 0.9

, filepath < 1.5
, ghc < 8.2 && >= 7.6
, ghc-paths < 0.2
Expand All @@ -193,6 +195,9 @@ Library
, transformers-base < 0.5
, mtl < 2.3 && >= 2.0
, monad-control < 1.1 && >= 1
, parsec
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upper bounds too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsec            < 3.2

, process
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate depdency, thats already declared above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

, process-streaming
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be used for much anything important. I'd rather not depend on it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed; not used anymore.

, split < 0.3
, haskell-src-exts < 1.18
, text < 1.3
Expand All @@ -209,6 +214,12 @@ Library
if impl(ghc >= 8.0)
Build-Depends: ghc-boot

if impl(ghc >= 8.0)
Build-Depends: haddock-api >= 2.17.2

if impl(ghc >=7.10 && < 7.12)
Build-Depends: haddock-api <= 2.16.1

Executable ghc-mod
Default-Language: Haskell2010
Main-Is: GHCMod.hs
Expand Down
2 changes: 2 additions & 0 deletions src/GHCMod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Language.Haskell.GhcMod.Internal hiding (MonadIO,liftIO)
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Monad
import Language.Haskell.GhcMod.Find (AsyncSymbolDb, newAsyncSymbolDb, getAsyncSymbolDb)
import Language.Haskell.GhcMod.ImportedFrom (importedFrom)
import System.FilePath ((</>))
import System.Directory (setCurrentDirectory, getAppUserDataDirectory,
removeDirectoryRecursive)
Expand Down Expand Up @@ -150,6 +151,7 @@ ghcCommands (CmdLint opts file) = lint opts file
ghcCommands (CmdBrowse opts ms) = concat <$> browse opts `mapM` ms
ghcCommands (CmdCheck files) = checkSyntax files
ghcCommands (CmdExpand files) = expandTemplate files
ghcCommands (CmdImportedFrom file (line, col) symb) = importedFrom file line col $ Expression symb
ghcCommands (CmdInfo file symb) = info file $ Expression symb
ghcCommands (CmdType wCon file (line, col)) = types wCon file line col
ghcCommands (CmdSplit file (line, col)) = splits file line col
Expand Down
7 changes: 6 additions & 1 deletion src/GHCMod/Options/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ data GhcModCommands =
| CmdDebugComponent [String]
| CmdCheck [FilePath]
| CmdExpand [FilePath]
| CmdImportedFrom FilePath Point Expr
| CmdInfo FilePath Symbol
| CmdType Bool FilePath Point
| CmdSplit FilePath Point
Expand Down Expand Up @@ -133,6 +134,9 @@ commands =
<> command "expand"
$$ info expandArgSpec
$$ progDesc "Like `check' but also pass `-ddump-splices' to GHC"
<> command "imported-from"
$$ info importedFromArgSpec
$$ progDesc "Get the Haddock URL of the expression under (LINE,COL)"
<> command "info"
$$ info infoArgSpec
$$ progDesc' $$$ do
Expand Down Expand Up @@ -228,7 +232,7 @@ locArgSpec x = x

modulesArgSpec, docArgSpec, findArgSpec,
lintArgSpec, browseArgSpec, checkArgSpec, expandArgSpec,
infoArgSpec, typeArgSpec, autoArgSpec, splitArgSpec,
importedFromArgSpec, infoArgSpec, typeArgSpec, autoArgSpec, splitArgSpec,
sigArgSpec, refineArgSpec, debugComponentArgSpec,
mapArgSpec, unmapArgSpec, legacyInteractiveArgSpec :: Parser GhcModCommands

Expand Down Expand Up @@ -268,6 +272,7 @@ browseArgSpec = CmdBrowse
debugComponentArgSpec = filesArgsSpec (pure CmdDebugComponent)
checkArgSpec = filesArgsSpec (pure CmdCheck)
expandArgSpec = filesArgsSpec (pure CmdExpand)
importedFromArgSpec = locArgSpec (pure CmdImportedFrom) <*> strArg "SYMBOL"
infoArgSpec = CmdInfo
<$> strArg "FILE"
<*> strArg "SYMBOL"
Expand Down
91 changes: 91 additions & 0 deletions test/ImportedFromSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{-# LANGUAGE CPP #-}
module ImportedFromSpec where

import Control.Applicative
import Language.Haskell.GhcMod
import System.FilePath
import Test.Hspec
import TestUtils
import Prelude

import Language.Haskell.GhcMod.Utils

---------------------------------------------------
import Language.Haskell.GhcMod.ImportedFrom
import System.FilePath()
import Test.Hspec

import Control.Exception as E
import System.Directory
---------------------------------------------------

isRight :: forall a b. Either a b -> Bool
isRight = either (const False) (const True)

spec :: Spec
spec = do
describe "checkImportedFrom" $ do
it "can look up Maybe" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 11 11 (Expression "Maybe")
res `shouldSatisfy` isRight

it "can look up Just" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 12 7 (Expression "Just")
res `shouldSatisfy` isRight

it "can look up Just" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 16 10 (Expression "Just")
res `shouldSatisfy` isRight

it "can look up String" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 20 14 (Expression "String")
res `shouldSatisfy` isRight

it "can look up Int" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 22 23 (Expression "Int")
res `shouldSatisfy` isRight

it "can look up DL.length" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 23 5 (Expression "DL.length")
res `shouldSatisfy` isRight

it "can look up print" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 25 8 (Expression "print")
res `shouldSatisfy` isRight

it "can look up DM.fromList" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 27 5 (Expression "DM.fromList")
res `shouldSatisfy` isRight

it "can look up Safe.headMay" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 29 6 (Expression "Safe.headMay")
res `shouldSatisfy` isRight

it "can look up Foo.Bar.length" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom01.hs" 34 17 (Expression "Foo.Bar.length")
res `shouldSatisfy` isRight

it "can look up map" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom02.hs" 14 5 (Expression "map")
res `shouldSatisfy` isRight

it "can look up head" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom02.hs" 16 5 (Expression "head")
res `shouldSatisfy` isRight

it "can look up when" $ do
withDirectory_ "test/data/imported-from" $ do
(res, _) <- runGmOutDef $ runGhcModT defaultOptions $ importedFrom "ImportedFrom03.hs" 15 5 (Expression "when")
res `shouldSatisfy` isRight
34 changes: 34 additions & 0 deletions test/data/imported-from/ImportedFrom01.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- ImportedFrom01.hs

module ImportedFrom01 where

import Data.Maybe
import qualified Data.List as DL
import qualified Data.Map as DM
import qualified Safe
import qualified Data.List as Foo.Bar

f :: a -> Maybe a
f x = Just x

g :: IO ()
g = do
let (Just _, _) = (Just 3, Just 4)

return ()

s = "boo" :: String
s' = head s
t = Just 100 :: Maybe Int
r = DL.length [1, 2, 3]

main = print "Hello, World!"

h = DM.fromList [("x", "y")]

sh = Safe.headMay []

i = 3 :: Int
i' = 3 :: Integer

len = Foo.Bar.length
19 changes: 19 additions & 0 deletions test/data/imported-from/ImportedFrom02.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- ImportedFrom02.hs

module ImportedFrom02 where

import Data.List hiding (map)
import System.Environment (getArgs)
import qualified Safe






m = map (+1) [1, 2, 3]

h = head [1, 2, 3]

h' = Safe.headMay []

15 changes: 15 additions & 0 deletions test/data/imported-from/ImportedFrom03.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- ImportedFrom03.hs

module ImportedFrom03 where

import Control.Monad ( forM_, liftM, filterM, when, unless )
import Control.Monad.Identity
import Control.Monad.Reader
import Control.Monad.Trans.Writer.Lazy





main = do
when True $ do print "hah"