Skip to content

Commit

Permalink
Merge pull request haskell#1255 from alanz/narrow-ghc-mod-core
Browse files Browse the repository at this point in the history
Narrow ghc mod core
  • Loading branch information
alanz authored May 12, 2019
2 parents ffcb0fc + 288e655 commit 6254c09
Show file tree
Hide file tree
Showing 23 changed files with 79 additions and 105 deletions.
1 change: 1 addition & 0 deletions app/HieWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Data.List
import Data.Foldable
import Data.Version (showVersion)
import qualified GhcMod.Monad as GM
import qualified GhcMod.Monad.Types as GM
import qualified GhcMod.Types as GM
import Haskell.Ide.Engine.MonadFunctions
import Haskell.Ide.Engine.Options
Expand Down
1 change: 0 additions & 1 deletion haskell-ide-engine.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ executable hie
other-modules: Paths_haskell_ide_engine
build-depends: base
, directory
, ghc-mod-core
, haskell-ide-engine
, haskell-lsp
, hie-plugin-api
Expand Down
2 changes: 1 addition & 1 deletion hie-plugin-api/Haskell/Ide/Engine/ArtifactMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import qualified GHC
import GHC (TypecheckedModule)
import qualified SrcLoc as GHC
import qualified Var
import qualified GhcMod.Gap as GM
import qualified GhcModCore as GM ( GhcRn, GhcTc, GhcPs )

import Language.Haskell.LSP.Types

Expand Down
6 changes: 3 additions & 3 deletions hie-plugin-api/Haskell/Ide/Engine/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Haskell.Ide.Engine.Context where
import Data.Generics
import Language.Haskell.LSP.Types
import GHC
import GhcMod.Gap (GhcPs) -- for GHC 8.2.2
import qualified GhcModCore as GM (GhcPs) -- for GHC 8.2.2
import Haskell.Ide.Engine.PluginUtils

-- | A context of a declaration in the program
Expand All @@ -20,15 +20,15 @@ data Context = TypeContext
getContext :: Position -> ParsedModule -> Maybe Context
getContext pos pm = everything join (Nothing `mkQ` go `extQ` goInline) decl
where decl = hsmodDecls $ unLoc $ pm_parsed_source pm
go :: LHsDecl GhcPs -> Maybe Context
go :: LHsDecl GM.GhcPs -> Maybe Context
go (L (RealSrcSpan r) (SigD {}))
| pos `isInsideRange` r = Just TypeContext
| otherwise = Nothing
go (L (GHC.RealSrcSpan r) (GHC.ValD {}))
| pos `isInsideRange` r = Just ValueContext
| otherwise = Nothing
go _ = Nothing
goInline :: GHC.LHsType GhcPs -> Maybe Context
goInline :: GHC.LHsType GM.GhcPs -> Maybe Context
goInline (GHC.L (GHC.RealSrcSpan r) _)
| pos `isInsideRange` r = Just TypeContext
| otherwise = Nothing
Expand Down
20 changes: 11 additions & 9 deletions hie-plugin-api/Haskell/Ide/Engine/Ghc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ import Bag
import Control.Monad.IO.Class
import Data.IORef
import qualified Data.Map.Strict as Map
import Data.Monoid ((<>))
import qualified Data.Set as Set
import qualified Data.Text as T
import ErrUtils
import qualified GhcMod.DynFlags as GM
import qualified GhcMod.Error as GM
import qualified GhcMod.Gap as GM
import qualified GhcMod.ModuleLoader as GM
import qualified GhcMod.Monad as GM
import Data.Monoid ((<>))
import qualified GhcMod.Target as GM
import qualified GhcMod.Types as GM
import qualified GhcMod.Utils as GM

import qualified GhcModCore as GM ( withDynFlags
, gcatches, GHandler(..), ghcExceptionDoc
, mkErrStyle', renderGm
, getModulesGhc'
, GmlT(..), getMMappedFiles, GmState(..), GhcModT, cradle
, cabalResolvedComponents
, IOish, GhcModError(..), GmGhcSession(..), GhcModState(..), GmModuleGraph(..), Cradle(..), gmcHomeModuleGraph
, mkRevRedirMapFunc )

import Haskell.Ide.Engine.MonadFunctions
import Haskell.Ide.Engine.MonadTypes
import Haskell.Ide.Engine.PluginUtils
Expand Down
2 changes: 1 addition & 1 deletion hie-plugin-api/Haskell/Ide/Engine/GhcModuleCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import qualified Data.Map as Map
import Data.Dynamic (Dynamic)
import Data.Typeable (TypeRep)

import qualified GhcMod.Types as GM
import qualified GhcModCore as GM ( Cradle(..) )

import GHC (TypecheckedModule, ParsedModule)

Expand Down
9 changes: 5 additions & 4 deletions hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ import Exception (ExceptionMonad)
import System.Directory
import System.FilePath

import qualified GhcMod.Cradle as GM
import qualified GhcMod.Monad as GM
import qualified GhcMod.Types as GM
import qualified GhcMod.Utils as GM
import qualified GhcModCore as GM ( findCradle'
, GmEnv(..), GmLog(..), GmlT(..), GmOut(..), cradle, options
, Cradle(..), GhcModEnv(..), MonadIO(..), Options(..)
, mkRevRedirMapFunc )

import qualified GHC as GHC

import Haskell.Ide.Engine.ArtifactMap
Expand Down
2 changes: 1 addition & 1 deletion hie-plugin-api/Haskell/Ide/Engine/PluginUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import Data.Monoid
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Maybe
import qualified GhcMod.Utils as GM
import qualified GhcModCore as GM ( makeAbsolute' )
import FastString
import Haskell.Ide.Engine.MonadTypes
import Haskell.Ide.Engine.MonadFunctions
Expand Down
5 changes: 3 additions & 2 deletions hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ import Data.Typeable ( TypeRep
, Typeable
)

import qualified GhcMod.Monad as GM
import qualified GhcMod.Types as GM
import qualified GhcModCore as GM ( GhcModT, runGhcModT, GmlT(..), gmlGetSession, gmlSetSession
, MonadIO(..), GmLogLevel(..), Options(..), defaultOptions, OutputOpts(..) )

import GHC.Generics
import GHC ( HscEnv )
import qualified DynFlags as GHC
Expand Down
6 changes: 3 additions & 3 deletions src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Data.Maybe
import Data.Monoid ((<>))
import qualified Data.Text as T
import GHC.Generics
import qualified GhcMod.Utils as GM
import qualified GhcModCore as GM ( mkRevRedirMapFunc, withMappedFile )
import Haskell.Ide.Engine.MonadFunctions
import Haskell.Ide.Engine.MonadTypes
import Haskell.Ide.Engine.PluginUtils
Expand Down Expand Up @@ -111,9 +111,9 @@ lintCmd = CmdSync $ \uri -> do
-- AZ:TODO: Why is this in IdeGhcM?
lintCmd' :: Uri -> IdeGhcM (IdeResult PublishDiagnosticsParams)
lintCmd' uri = pluginGetFile "lintCmd: " uri $ \fp -> do
eitherErrorResult <- GM.withMappedFile fp $ \file' ->
eitherErrorResult <- GM.withMappedFile fp $ \file' ->
liftIO (try $ runExceptT $ runLintCmd file' [] :: IO (Either IOException (Either [Diagnostic] [Idea])))

case eitherErrorResult of
Left err ->
return
Expand Down
48 changes: 9 additions & 39 deletions src/Haskell/Ide/Engine/Plugin/GhcMod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module Haskell.Ide.Engine.Plugin.GhcMod
-- * For tests
, Bindings(..)
, FunctionSig(..)
, InfoParams(..)
, TypeDef(..)
, TypeParams(..)
, TypedHoles(..) -- only to keep the GHC 8.4 and below unused field warning happy
Expand All @@ -21,8 +20,6 @@ module Haskell.Ide.Engine.Plugin.GhcMod
, extractMissingSignature
, extractRenamableTerms
, extractUnusedTerm
, infoCmd'
, lintCmd'
, newTypeCmd
, symbolProvider
) where
Expand All @@ -37,10 +34,7 @@ import Data.Monoid ((<>))
import qualified Data.Text as T
import Name
import GHC.Generics
import qualified GhcMod as GM
import qualified GhcMod.Gap as GM
import qualified GhcMod.SrcUtils as GM
import qualified GhcMod.Types as GM
import qualified GhcModCore as GM ( pretty, GhcPs )
import Haskell.Ide.Engine.Ghc
import Haskell.Ide.Engine.MonadTypes hiding (defaultOptions)
import Haskell.Ide.Engine.PluginUtils
Expand All @@ -66,10 +60,14 @@ ghcmodDescriptor plId = PluginDescriptor
<> "in editors. It strives to offer most of the features one has come to expect "
<> "from modern IDEs in any editor."
, pluginCommands =
[ PluginCommand "check" "check a file for GHC warnings and errors" checkCmd
, PluginCommand "lint" "Check files using `hlint'" lintCmd
, PluginCommand "info" "Look up an identifier in the context of FILE (like ghci's `:info')" infoCmd
[
-- This one is used in the dispatcher tests, and is a wrapper around what we are already using anyway
PluginCommand "check" "check a file for GHC warnings and errors" checkCmd

-- PluginCommand "info" "Look up an identifier in the context of FILE (like ghci's `:info')" infoCmd
, PluginCommand "type" "Get the type of the expression under (LINE,COL)" typeCmd

-- This one is registered in the vscode plugin, for some reason
, PluginCommand "casesplit" "Generate a pattern match for a binding under (LINE,COL)" Hie.splitCaseCmd
]
, pluginCodeActionProvider = Just codeActionProvider
Expand All @@ -86,39 +84,11 @@ checkCmd = CmdSync setTypecheckedModule

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

lintCmd :: CommandFunc Uri T.Text
lintCmd = CmdSync lintCmd'

lintCmd' :: Uri -> IdeGhcM (IdeResult T.Text)
lintCmd' uri =
pluginGetFile "lint: " uri $ \file ->
fmap T.pack <$> Hie.runGhcModCommand (GM.lint GM.defaultLintOpts file)

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

customOptions :: Options
customOptions = defaultOptions { fieldLabelModifier = camelTo2 '_' . drop 2}

data InfoParams =
IP { ipFile :: Uri
, ipExpr :: T.Text
} deriving (Eq,Show,Generic)

instance FromJSON InfoParams where
parseJSON = genericParseJSON customOptions
instance ToJSON InfoParams where
toJSON = genericToJSON customOptions

infoCmd :: CommandFunc InfoParams T.Text
infoCmd = CmdSync $ \(IP uri expr) ->
infoCmd' uri expr

infoCmd' :: Uri -> T.Text -> IdeGhcM (IdeResult T.Text)
infoCmd' uri expr =
pluginGetFile "info: " uri $ \file ->
fmap T.pack <$> Hie.runGhcModCommand (GM.info file (GM.Expression (T.unpack expr)))

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

data TypeParams =
TP { tpIncludeConstraints :: Bool
, tpFile :: Uri
Expand Down
5 changes: 3 additions & 2 deletions src/Haskell/Ide/Engine/Plugin/HaRe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import qualified Data.Text as T
import qualified Data.Text.IO as T
import Exception
import GHC.Generics (Generic)
import qualified GhcMod.Error as GM
import qualified GhcMod.Utils as GM

import qualified GhcModCore as GM (GhcModError(..),withMappedFile,GHandler(..),gcatches)

import Haskell.Ide.Engine.ArtifactMap
import Haskell.Ide.Engine.MonadFunctions
import Haskell.Ide.Engine.MonadTypes
Expand Down
3 changes: 1 addition & 2 deletions src/Haskell/Ide/Engine/Plugin/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import Data.Function
import Data.Maybe
import Data.List
import GHC
import qualified GhcMod.LightGhc as GM
import qualified GhcMod.Monad as GM
import qualified GhcModCore as GM ( LightGhc(..), runLightGhc )
import GhcMonad
import Haskell.Ide.Engine.MonadFunctions
import Haskell.Ide.Engine.MonadTypes
Expand Down
2 changes: 1 addition & 1 deletion src/Haskell/Ide/Engine/Plugin/HsImport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Data.Monoid ( (<>) )
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified GHC.Generics as Generics
import qualified GhcMod.Utils as GM
import qualified GhcModCore as GM ( mkRevRedirMapFunc, withMappedFile )
import HsImport
import Haskell.Ide.Engine.Config
import Haskell.Ide.Engine.MonadTypes
Expand Down
2 changes: 1 addition & 1 deletion src/Haskell/Ide/Engine/Plugin/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import System.FilePath
#endif
import Control.Monad.IO.Class
import System.Directory
import qualified GhcMod.Utils as GM
import qualified GhcModCore as GM ( mkRevRedirMapFunc )
import Distribution.Types.GenericPackageDescription
import Distribution.Types.CondTree
import qualified Distribution.PackageDescription.PrettyPrint as PP
Expand Down
4 changes: 2 additions & 2 deletions src/Haskell/Ide/Engine/Scheduler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import Control.Monad
import qualified Data.Set as Set
import qualified Data.Map as Map
import qualified Data.Text as T
import qualified GhcMod.Types as GM
import qualified Language.Haskell.LSP.Core as Core
import qualified Language.Haskell.LSP.Types as J

Expand Down Expand Up @@ -348,7 +347,8 @@ ghcDispatcher env@DispatcherEnv { docVersionTVar } errorHandler callbackHandler
-- | Runs the passed monad only if the request identified by the passed LspId
-- has not already been cancelled.
unlessCancelled
:: GM.MonadIO m => DispatcherEnv -> J.LspId -> ErrorHandler -> m () -> m ()
-- :: GM.MonadIO m => DispatcherEnv -> J.LspId -> ErrorHandler -> m () -> m ()
:: MonadIO m => DispatcherEnv -> J.LspId -> ErrorHandler -> m () -> m ()
unlessCancelled env lid errorHandler callback = do
cancelled <- liftIO $ STM.atomically isCancelled
if cancelled
Expand Down
9 changes: 4 additions & 5 deletions src/Haskell/Ide/Engine/Support/HieExtras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ import FastString
import Finder
import GHC hiding (getContext)
import GHC.Generics (Generic)
import qualified GhcMod.Error as GM
import qualified GhcMod.Exe.CaseSplit as GM
import qualified GhcMod.Gap as GM
import qualified GhcMod.LightGhc as GM
import qualified GhcMod.Utils as GM

import qualified GhcMod as GM (splits',SplitResult(..))
import qualified GhcModCore as GM (GhcModError(..), listVisibleModuleNames,runLightGhc, withMappedFile )

import Haskell.Ide.Engine.ArtifactMap
import Haskell.Ide.Engine.Config
import Haskell.Ide.Engine.Context
Expand Down
3 changes: 1 addition & 2 deletions src/Haskell/Ide/Engine/Transport/LspStdio.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import qualified Data.Set as S
import qualified Data.SortedList as SL
import qualified Data.Text as T
import Data.Text.Encoding
import qualified GhcMod.Monad.Types as GM
import qualified GhcModCore as GM
import qualified GhcModCore as GM ( loadMappedFileSource, getMMappedFiles )
import Haskell.Ide.Engine.Config
import qualified Haskell.Ide.Engine.Ghc as HIE
import Haskell.Ide.Engine.LSP.CodeActions
Expand Down
2 changes: 1 addition & 1 deletion submodules/cabal-helper
2 changes: 1 addition & 1 deletion submodules/ghc-mod
Submodule ghc-mod updated 49 files
+3 −87 GhcMod.hs
+0 −29 GhcMod/Exe/Boot.hs
+0 −170 GhcMod/Exe/Browse.hs
+11 −33 GhcMod/Exe/CaseSplit.hs
+0 −57 GhcMod/Exe/Check.hs
+0 −188 GhcMod/Exe/Debug.hs
+0 −654 GhcMod/Exe/FillSig.hs
+0 −219 GhcMod/Exe/Find.hs
+0 −9 GhcMod/Exe/Flag.hs
+0 −79 GhcMod/Exe/Info.hs
+0 −73 GhcMod/Exe/Internal.hs
+0 −10 GhcMod/Exe/Lang.hs
+0 −30 GhcMod/Exe/Lint.hs
+0 −27 GhcMod/Exe/Modules.hs
+0 −29 GhcMod/Exe/PkgDoc.hs
+0 −64 GhcMod/Exe/Test.hs
+13 −10 core/GhcMod/CabalHelper.hs
+4 −2 core/GhcMod/Caching.hs
+7 −1 core/GhcMod/Caching/Types.hs
+21 −48 core/GhcMod/Cradle.hs
+5 −26 core/GhcMod/DebugLogger.hs
+13 −16 core/GhcMod/Doc.hs
+21 −9 core/GhcMod/DynFlags.hs
+2 −1 core/GhcMod/DynFlagsTH.hs
+30 −28 core/GhcMod/Error.hs
+25 −25 core/GhcMod/FileMapping.hs
+0 −19 core/GhcMod/Gap.hs
+1 −0 core/GhcMod/HomeModuleGraph.hs
+9 −3 core/GhcMod/LightGhc.hs
+17 −39 core/GhcMod/Logging.hs
+5 −5 core/GhcMod/ModuleLoader.hs
+8 −12 core/GhcMod/Monad.hs
+0 −25 core/GhcMod/Monad/Compat.hs_h
+0 −2 core/GhcMod/Monad/Newtypes.hs
+0 −22 core/GhcMod/Monad/Orphans.hs
+12 −14 core/GhcMod/Monad/Types.hs
+1 −0 core/GhcMod/Options/Options.hs
+9 −15 core/GhcMod/Output.hs
+22 −9 core/GhcMod/PathsAndFiles.hs
+4 −1 core/GhcMod/Read.hs
+48 −40 core/GhcMod/SrcUtils.hs
+7 −1 core/GhcMod/Stack.hs
+45 −28 core/GhcMod/Target.hs
+44 −12 core/GhcMod/Types.hs
+15 −51 core/GhcMod/Utils.hs
+0 −55 core/GhcMod/World.hs
+68 −46 core/GhcModCore.hs
+0 −3 core/ghc-mod-core.cabal
+163 −180 ghc-mod.cabal
2 changes: 1 addition & 1 deletion test/dispatcher/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ funcSpec = describe "functional dispatch" $ do
-- And now we get the deferred response (once the module is loaded)
("req1",Right res) <- atomically $ readTChan logChan
let Just ds = fromDynJSON res :: Maybe [DocumentSymbol]
DocumentSymbol mainName _ mainKind _ mainRange _ _ = head ds
DocumentSymbol mainName _ mainKind _ mainRange _ _ = head ds
mainName `shouldBe` "main"
mainKind `shouldBe` SkFunction
mainRange `shouldBe` Range (Position 2 0) (Position 2 23)
Expand Down
Loading

0 comments on commit 6254c09

Please sign in to comment.