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

Move exe specific types out of core #889

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion GhcModExe/Boot.hs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import GhcModExe.Flag
import GhcModExe.Lang
import GhcModExe.Modules
import Language.Haskell.GhcMod.Monad
import Language.Haskell.GhcMod.Types (defaultBrowseOpts)
import Language.Haskell.GhcMod.Types

-- | Printing necessary information for front-end booting.
boot :: IOish m => GhcModT m String
17 changes: 16 additions & 1 deletion GhcModExe/Browse.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{-# LANGUAGE CPP #-}
module GhcModExe.Browse (
browse,
BrowseOpts(..)
BrowseOpts(..),
defaultBrowseOpts
) where

import Safe
@@ -167,3 +168,17 @@ removeForAlls' ty (Just (pre, ftype))

showOutputable :: Outputable a => DynFlags -> a -> String
showOutputable dflag = unwords . lines . showPage dflag styleUnqualified . ppr

data BrowseOpts = BrowseOpts {
optBrowseOperators :: Bool
-- ^ If 'True', operators are also returned.
, optBrowseDetailed :: Bool
-- ^ If 'True', types are also returned.
, optBrowseParents :: Bool
-- ^ If 'True', parents are also returned.
, optBrowseQualified :: Bool
-- ^ If 'True', will return fully qualified names
} deriving (Show)

defaultBrowseOpts :: BrowseOpts
defaultBrowseOpts = BrowseOpts False False False False
23 changes: 20 additions & 3 deletions GhcModExe/Find.hs
Original file line number Diff line number Diff line change
@@ -44,9 +44,6 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import Data.IORef

import System.Directory.ModTime
import System.IO.Unsafe

import GHC.Generics (Generic)

import Data.Map (Map)
@@ -55,8 +52,14 @@ import Data.Set (Set)
import qualified Data.Set as S
import Language.Haskell.GhcMod.PathsAndFiles
import System.Directory
import System.Directory.ModTime
import System.Environment
import System.FilePath
import System.IO.Unsafe
import Prelude

import Paths_ghc_mod (getBinDir)

----------------------------------------------------------------

-- | Type of function and operation names.
@@ -125,6 +128,20 @@ loadSymbolDb = do
out <- liftIO $ readProc ghcMod ["--verbose", "error", "dumpsym"] ""
return $!! decode out

ghcModExecutable :: IO FilePath
ghcModExecutable = do
exe <- getExecutablePath
stack <- lookupEnv "STACK_EXE"
case takeBaseName exe of
"spec" | Just _ <- stack ->
(</> "ghc-mod") <$> getBinDir
"spec" ->
(</> "dist/build/ghc-mod-real/ghc-mod-real") <$> getCurrentDirectory
"ghc-mod-real" ->
return exe
_ ->
return $ takeDirectory exe </> "ghc-mod"

----------------------------------------------------------------
-- used 'ghc-mod dumpsym'

1 change: 0 additions & 1 deletion GhcModExe/Internal.hs
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ module GhcModExe.Internal (
, GmEnv(..)
-- * Various Paths
, ghcLibDir
, ghcModExecutable
-- * Logging
, withLogger
, setNoWarningFlags
10 changes: 10 additions & 0 deletions GhcModExe/Lint.hs
Original file line number Diff line number Diff line change
@@ -28,3 +28,13 @@ lint opt file = ghandle handler $
| srcSpanFilename (ideaSpan idea) == temp
= idea{ideaSpan=(ideaSpan idea){srcSpanFilename = orig}}
substFile _ _ idea = idea

-- | Options for "lintWith" function
data LintOpts = LintOpts {
optLintHlintOpts :: [String]
-- ^ options that will be passed to hlint executable
} deriving (Show)

-- | Default "LintOpts" instance
defaultLintOpts :: LintOpts
defaultLintOpts = LintOpts []
26 changes: 0 additions & 26 deletions core/Language/Haskell/GhcMod/Types.hs
Original file line number Diff line number Diff line change
@@ -373,32 +373,6 @@ instance Binary ChEntrypoint where
put = ggput . from
get = to `fmap` ggget

-- | Options for "lintWith" function
data LintOpts = LintOpts {
optLintHlintOpts :: [String]
-- ^ options that will be passed to hlint executable
} deriving (Show)

-- | Default "LintOpts" instance
defaultLintOpts :: LintOpts
defaultLintOpts = LintOpts []

-- | Options for "browseWith" function
data BrowseOpts = BrowseOpts {
optBrowseOperators :: Bool
-- ^ If 'True', "browseWith" also returns operators.
, optBrowseDetailed :: Bool
-- ^ If 'True', "browseWith" also returns types.
, optBrowseParents :: Bool
-- ^ If 'True', "browseWith" also returns parents.
, optBrowseQualified :: Bool
-- ^ If 'True', "browseWith" will return fully qualified name
} deriving (Show)

-- | Default "BrowseOpts" instance
defaultBrowseOpts :: BrowseOpts
defaultBrowseOpts = BrowseOpts False False False False

mkLabel ''GhcModCaches
mkLabel ''GhcModState
mkLabel ''Options
26 changes: 0 additions & 26 deletions core/Language/Haskell/GhcMod/Utils.hs
Original file line number Diff line number Diff line change
@@ -34,13 +34,10 @@ import Language.Haskell.GhcMod.Error
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Monad.Types
import System.Directory
import System.Environment
import System.FilePath
import System.IO.Temp (createTempDirectory)
import System.Process (readProcess)
import Text.Printf

import Paths_ghc_mod (getLibexecDir, getBinDir)
import Utils
import Prelude

@@ -76,29 +73,6 @@ newTempDir _dir =
whenM :: Monad m => m Bool -> m () -> m ()
whenM mb ma = mb >>= flip when ma

-- | Returns the path to the currently running ghc-mod executable. With ghc<7.6
-- this is a guess but >=7.6 uses 'getExecutablePath'.
ghcModExecutable :: IO FilePath
ghcModExecutable = do
exe <- getExecutablePath'
stack <- lookupEnv "STACK_EXE"
case takeBaseName exe of
"spec" | Just _ <- stack ->
(</> "ghc-mod") <$> getBinDir
"spec" ->
(</> "dist/build/ghc-mod/ghc-mod") <$> getCurrentDirectory
"ghc-mod" ->
return exe
_ ->
return $ takeDirectory exe </> "ghc-mod"

getExecutablePath' :: IO FilePath
#if __GLASGOW_HASKELL__ >= 706
getExecutablePath' = getExecutablePath
#else
getExecutablePath' = getProgName
#endif

canonFilePath :: FilePath -> IO FilePath
canonFilePath f = do
p <- canonicalizePath f
4 changes: 3 additions & 1 deletion src/GHCMod/Options/Commands.hs
Original file line number Diff line number Diff line change
@@ -22,11 +22,13 @@ import Data.Semigroup
import Options.Applicative
import Options.Applicative.Types
import Options.Applicative.Builder.Internal
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Read
import Language.Haskell.GhcMod.Options.DocUtils
import Language.Haskell.GhcMod.Options.Help

import GhcModExe.Lint
import GhcModExe.Browse

type Symbol = String
type Expr = String
type Module = String
1 change: 1 addition & 0 deletions test/BrowseSpec.hs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ module BrowseSpec where

import Control.Applicative
import GhcMod
import GhcModExe.Browse
import Test.Hspec
import Prelude

1 change: 1 addition & 0 deletions test/FileMappingSpec.hs
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import System.IO.Temp
import System.Directory

import GhcMod
import GhcModExe.Lint

spec :: Spec
spec = do
2 changes: 1 addition & 1 deletion test/LintSpec.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module LintSpec where

import GhcMod
import GhcModExe.Lint
import Test.Hspec
import TestUtils