on master help sign in
Further cleanups to hie-core (#1819)

* Move the span related functionality to one place * Fuse docHeaders away * Decouple AtPoint from the rest of the rule database, simplifying the dependencies * Move the import related functionality to one place * Move all the closely tied to GHC modules together * Rename the Logger module * Push the other module renames through the code base * Rename Development.IDE.State to Development.IDE.Core * Rename Functions.Compile to Core.Compile * Fix up some module names * Cut down on non-sensicle exports * Don't worry about setting source - no one uses it * Reorder the module header * Give more sensible names to the diagnostic creating functions * Use more appropriate diagnostic functions * Simplify the internal diagnostic creations * Rewrite the diagnostics to go direct, not via GHC error types * Remove redundant dflags from some functions * Make sure the warning vs error distinction remains * Remove unnecessary extensions

commitf46fff9b0a4ec32f449a79a66238165027caa95e authorNeil Mitchell <35463327+neil-da@users.noreply.github.com> dateSat 22 Jun 2019, 09:21 (7 years ago) parent6270442
26 files changed+177−193
hie-core.cabal+19−19 src/Development/IDE/Functions/Compile.hs → src/Development/IDE/Core/Compile.hs+18−18 src/Development/IDE/State/FileStore.hs → src/Development/IDE/Core/FileStore.hs+3−3 src/Development/IDE/State/RuleTypes.hs → src/Development/IDE/Core/RuleTypes.hs+8−8 src/Development/IDE/State/Rules.hs → src/Development/IDE/Core/Rules.hs+13−12 src/Development/IDE/State/Service.hs → src/Development/IDE/Core/Service.hs+5−5 src/Development/IDE/State/Shake.hs → src/Development/IDE/Core/Shake.hs+5−6 src/Development/IDE/Functions/CPP.hs → src/Development/IDE/GHC/CPP.hs+1−1 src/Development/IDE/Compat.hs → src/Development/IDE/GHC/Compat.hs+1−1 src/Development/IDE/Functions/GHCError.hs → src/Development/IDE/GHC/Error.hs+37−49 src/Development/IDE/Orphans.hs → src/Development/IDE/GHC/Orphans.hs+2−2 src/Development/IDE/UtilGHC.hs → src/Development/IDE/GHC/Util.hs+1−1 src/Development/IDE/Functions/Warnings.hs → src/Development/IDE/GHC/Warnings.hs+8−10 src/Development/IDE/Functions/DependencyInformation.hs → src/Development/IDE/Import/DependencyInformation.hs+2−3 src/Development/IDE/Functions/FindImports.hs → src/Development/IDE/Import/FindImports.hs+6−5 src/Development/IDE/LSP/Definition.hs+2−2 src/Development/IDE/LSP/Hover.hs+2−2 src/Development/IDE/LSP/LanguageServer.hs+3−3 src/Development/IDE/LSP/Server.hs+1−1 src/Development/IDE/Functions/AtPoint.hs → src/Development/IDE/Spans/AtPoint.hs+20−20 src/Development/IDE/Functions/SpanInfo.hs → src/Development/IDE/Spans/Calculate.hs+4−4 src/Development/IDE/Functions/Documentation.hs → src/Development/IDE/Spans/Documentation.hs+5−5 src/Development/IDE/Types/SpanInfo.hs → src/Development/IDE/Spans/Type.hs+3−3 src/Development/IDE/Types/Diagnostics.hs+1−3 src/Development/IDE/Logger.hs → src/Development/IDE/Types/Logger.hs+1−1 test/Demo.hs+6−6
hie-core.cabal+19−19
@@ -76,33 +76,33 @@ library
7676 src
7777 ../../libs-haskell/prettyprinter-syntax/src
7878 exposed-modules:
79− Development.IDE.Logger
80− Development.IDE.UtilGHC
81− Development.IDE.Functions.AtPoint
82− Development.IDE.Functions.Compile
83− Development.IDE.Functions.CPP
84− Development.IDE.Orphans
85− Development.IDE.Functions.DependencyInformation
86− Development.IDE.Functions.Documentation
87− Development.IDE.Functions.FindImports
88− Development.IDE.Functions.GHCError
89− Development.IDE.Functions.SpanInfo
90− Development.IDE.Functions.Warnings
91− Development.IDE.State.FileStore
92− Development.IDE.State.Rules
93− Development.IDE.Compat
79+ Development.IDE.Types.Logger
80+ Development.IDE.GHC.Util
81+ Development.IDE.Spans.AtPoint
82+ Development.IDE.Core.Compile
83+ Development.IDE.GHC.CPP
84+ Development.IDE.GHC.Orphans
85+ Development.IDE.Import.DependencyInformation
86+ Development.IDE.Spans.Documentation
87+ Development.IDE.Import.FindImports
88+ Development.IDE.GHC.Error
89+ Development.IDE.Spans.Calculate
90+ Development.IDE.GHC.Warnings
91+ Development.IDE.Core.FileStore
92+ Development.IDE.Core.Rules
93+ Development.IDE.GHC.Compat
9494 Development.IDE.LSP.LanguageServer
9595 Development.IDE.LSP.Definition
9696 Development.IDE.LSP.Hover
9797 Development.IDE.LSP.Protocol
9898 Development.IDE.LSP.Server
9999 Development.IDE.Types.Options
100− Development.IDE.State.RuleTypes
101− Development.IDE.State.Service
102− Development.IDE.State.Shake
100+ Development.IDE.Core.RuleTypes
101+ Development.IDE.Core.Service
102+ Development.IDE.Core.Shake
103103 Development.IDE.Types.Diagnostics
104104 Development.IDE.Types.Location
105− Development.IDE.Types.SpanInfo
105+ Development.IDE.Spans.Type
106106 other-modules:
107107 Data.Text.Prettyprint.Doc.Syntax
108108
src/Development/IDE/Functions/Compile.hs → src/Development/IDE/Core/Compile.hsrenamed+18−18
@@ -7,7 +7,7 @@
77
88-- | Based on https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/API.
99-- Given a list of paths to find libraries, and a file to compile, produce a list of 'CoreModule' values.
10−module Development.IDE.Functions.Compile
10+module Development.IDE.Core.Compile
1111 ( GhcModule(..)
1212 , TcModuleResult(..)
1313 , LoadPackageResult(..)
@@ -20,21 +20,21 @@ module Development.IDE.Functions.Compile
2020 , computePackageDeps
2121 ) where
2222
23−import Development.IDE.Functions.Warnings
24−import Development.IDE.Functions.CPP
23+import Development.IDE.GHC.Warnings
24+import Development.IDE.GHC.CPP
2525import Development.IDE.Types.Diagnostics
26−import qualified Development.IDE.Functions.FindImports as FindImports
27−import Development.IDE.Functions.GHCError
28−import Development.IDE.Functions.SpanInfo
29−import Development.IDE.UtilGHC
30−import Development.IDE.Compat
26+import qualified Development.IDE.Import.FindImports as FindImports
27+import Development.IDE.GHC.Error
28+import Development.IDE.Spans.Calculate
29+import Development.IDE.GHC.Util
30+import Development.IDE.GHC.Compat
3131import Development.IDE.Types.Options
3232import Development.IDE.Types.Location
3333
3434import GHC hiding (parseModule, typecheckModule)
3535import qualified Parser
3636import Lexer
37−import Bag
37+import ErrUtils
3838
3939import qualified GHC
4040import Panic
@@ -56,7 +56,7 @@ import Data.List.Extra
5656import Data.Maybe
5757import Data.Tuple.Extra
5858import qualified Data.Map.Strict as Map
59−import Development.IDE.Types.SpanInfo
59+import Development.IDE.Spans.Type
6060import GHC.Generics (Generic)
6161import System.FilePath
6262import System.Directory
@@ -143,7 +143,7 @@ typecheckModule opt packageState deps pm =
143143 runGhcSessionExcept opt (Just pm) packageState $
144144 catchSrcErrors $ do
145145 setupEnv deps
146− (warnings, tcm) <- withWarnings "Typechecker" $ \tweak ->
146+ (warnings, tcm) <- withWarnings $ \tweak ->
147147 GHC.typecheckModule pm{pm_mod_summary = tweak $ pm_mod_summary pm}
148148 tcm2 <- mkTcModuleResult (WriteInterface $ optWriteIface opt) tcm
149149 return (warnings, tcm2)
@@ -182,7 +182,7 @@ compileModule opt mod packageState deps tmr =
182182
183183 let tm = tmrModule tmr
184184 session <- getSession
185− (warnings,desugar) <- withWarnings "Desugarer" $ \tweak -> do
185+ (warnings,desugar) <- withWarnings $ \tweak -> do
186186 let pm = tm_parsed_module tm
187187 let pm' = pm{pm_mod_summary = tweak $ pm_mod_summary pm}
188188 let tm' = tm{tm_parsed_module = pm'}
@@ -395,7 +395,7 @@ parseFileContents preprocessor filename contents = do
395395
396396 case unP Parser.parseModule (mkPState dflags contents loc) of
397397 PFailed _ locErr msgErr ->
398− Ex.throwE $ mkErrorDoc dflags locErr msgErr
398+ Ex.throwE $ diagFromErrMsg dflags $ mkPlainErrMsg dflags locErr msgErr
399399 POk pst rdr_module ->
400400 let hpm_annotations =
401401 (Map.fromListWith (++) $ annotations pst,
@@ -414,11 +414,11 @@ parseFileContents preprocessor filename contents = do
414414 -- errors are those from which a parse tree just can't
415415 -- be produced.
416416 unless (null errs) $
417− Ex.throwE $ toDiagnostics dflags $ snd $ getMessages pst dflags
417+ Ex.throwE $ diagFromErrMsgs dflags $ snd $ getMessages pst dflags
418418
419419 -- Ok, we got here. It's safe to continue.
420420 let (errs, parsed) = preprocessor rdr_module
421− unless (null errs) $ Ex.throwE $ mkErrors dflags errs
421+ unless (null errs) $ Ex.throwE $ diagFromStrings errs
422422 ms <- getModSummaryFromBuffer filename contents dflags parsed
423423 let pm =
424424 ParsedModule {
@@ -427,7 +427,7 @@ parseFileContents preprocessor filename contents = do
427427 , pm_extra_src_files=[] -- src imports not allowed
428428 , pm_annotations = hpm_annotations
429429 }
430− warnings = mapMaybe (mkDiag dflags "Parser") $ bagToList warns
430+ warnings = diagFromErrMsgs dflags warns
431431 pure (warnings, pm)
432432
433433
@@ -453,5 +453,5 @@ catchSrcErrors ghcM = do
453453 handleSourceError (sourceErrorToDiagnostics dflags) $
454454 Right <$> ghcM
455455 where
456− ghcExceptionToDiagnostics dflags = return . Left . mkErrorsGhcException dflags
457− sourceErrorToDiagnostics dflags = return . Left . toDiagnostics dflags . srcErrorMessages
456+ ghcExceptionToDiagnostics dflags = return . Left . diagFromGhcException dflags
457+ sourceErrorToDiagnostics dflags = return . Left . diagFromErrMsgs dflags . srcErrorMessages
src/Development/IDE/State/FileStore.hs → src/Development/IDE/Core/FileStore.hsrenamed+3−3
@@ -3,7 +3,7 @@
33
44{-# LANGUAGE TypeFamilies #-}
55
6−module Development.IDE.State.FileStore(
6+module Development.IDE.Core.FileStore(
77 getFileExists, getFileContents,
88 setBufferModified,
99 fileStoreRules,
@@ -13,7 +13,7 @@ module Development.IDE.State.FileStore(
1313 ) where
1414
1515import StringBuffer
16−import Development.IDE.Orphans()
16+import Development.IDE.GHC.Orphans()
1717
1818import Control.Concurrent.Extra
1919import qualified Data.Map.Strict as Map
@@ -24,7 +24,7 @@ import Control.Monad.Extra
2424import qualified System.Directory as Dir
2525import Development.Shake
2626import Development.Shake.Classes
27−import Development.IDE.State.Shake
27+import Development.IDE.Core.Shake
2828import Control.Exception
2929import GHC.Generics
3030import Data.Either.Extra
src/Development/IDE/State/RuleTypes.hs → src/Development/IDE/Core/RuleTypes.hsrenamed+8−8
@@ -8,15 +8,15 @@
88-- | A Shake implementation of the compiler service, built
99-- using the "Shaker" abstraction layer for in-memory use.
1010--
11−module Development.IDE.State.RuleTypes(
12− module Development.IDE.State.RuleTypes
11+module Development.IDE.Core.RuleTypes(
12+ module Development.IDE.Core.RuleTypes
1313 ) where
1414
1515import Control.DeepSeq
16−import Development.IDE.Functions.Compile (TcModuleResult, GhcModule, LoadPackageResult(..))
17−import qualified Development.IDE.Functions.Compile as Compile
18−import Development.IDE.Functions.FindImports (Import(..))
19−import Development.IDE.Functions.DependencyInformation
16+import Development.IDE.Core.Compile (TcModuleResult, GhcModule, LoadPackageResult(..))
17+import qualified Development.IDE.Core.Compile as Compile
18+import Development.IDE.Import.FindImports (Import(..))
19+import Development.IDE.Import.DependencyInformation
2020import Data.Hashable
2121import Data.Typeable
2222import Development.IDE.Types.Location
@@ -25,10 +25,10 @@ import Development.Shake hiding (Env, newCache)
2525import GHC.Generics (Generic)
2626
2727import GHC
28−import Development.IDE.Compat
28+import Development.IDE.GHC.Compat
2929import Module
3030
31−import Development.IDE.Types.SpanInfo
31+import Development.IDE.Spans.Type
3232
3333
3434-- NOTATION
src/Development/IDE/State/Rules.hs → src/Development/IDE/Core/Rules.hsrenamed+13−12
@@ -9,7 +9,7 @@
99-- | A Shake implementation of the compiler service, built
1010-- using the "Shaker" abstraction layer for in-memory use.
1111--
12−module Development.IDE.State.Rules(
12+module Development.IDE.Core.Rules(
1313 IdeState, GetDependencies(..), GetParsedModule(..), TransitiveDependencies(..),
1414 Priority(..),
1515 runAction, runActions, useE, usesE,
@@ -25,11 +25,11 @@ module Development.IDE.State.Rules(
2525
2626import Control.Monad.Except
2727import Control.Monad.Trans.Maybe
28−import qualified Development.IDE.Functions.Compile as Compile
28+import qualified Development.IDE.Core.Compile as Compile
2929import qualified Development.IDE.Types.Options as Compile
30−import Development.IDE.Functions.DependencyInformation
31−import Development.IDE.Functions.FindImports
32−import Development.IDE.State.FileStore
30+import Development.IDE.Import.DependencyInformation
31+import Development.IDE.Import.FindImports
32+import Development.IDE.Core.FileStore
3333import Development.IDE.Types.Diagnostics as Base
3434import Development.IDE.Types.Location
3535import qualified Data.ByteString.UTF8 as BS
@@ -42,18 +42,18 @@ import Data.Foldable
4242import qualified Data.Map.Strict as Map
4343import qualified Data.Set as Set
4444import qualified Data.Text as T
45−import Development.IDE.Functions.GHCError
45+import Development.IDE.GHC.Error
4646import Development.Shake hiding (Diagnostic, Env, newCache)
47−import Development.IDE.State.RuleTypes
47+import Development.IDE.Core.RuleTypes
4848
4949import GHC
50−import Development.IDE.Compat
50+import Development.IDE.GHC.Compat
5151import UniqSupply
5252import NameCache
5353
54−import qualified Development.IDE.Functions.AtPoint as AtPoint
55−import Development.IDE.State.Service
56−import Development.IDE.State.Shake
54+import qualified Development.IDE.Spans.AtPoint as AtPoint
55+import Development.IDE.Core.Service
56+import Development.IDE.Core.Shake
5757
5858-- | This is useful for rules to convert rules that can only produce errors or
5959-- a result into the more general IdeResult type that supports producing
@@ -117,7 +117,8 @@ getDefinition file pos = fmap join $ runMaybeT $ do
117117 spans <- useE GetSpanInfo file
118118 pkgState <- useE GhcSession ""
119119 opts <- lift getOpts
120− lift $ AtPoint.gotoDefinition opts pkgState spans pos
120+ let getHieFile x = use (GetHieFile x) ""
121+ lift $ AtPoint.gotoDefinition getHieFile opts pkgState spans pos
121122
122123-- | Parse the contents of a daml file.
123124getParsedModule :: NormalizedFilePath -> Action (Maybe ParsedModule)
src/Development/IDE/State/Service.hs → src/Development/IDE/Core/Service.hsrenamed+5−5
@@ -8,7 +8,7 @@
88-- | A Shake implementation of the compiler service, built
99-- using the "Shaker" abstraction layer for in-memory use.
1010--
11−module Development.IDE.State.Service(
11+module Development.IDE.Core.Service(
1212 Env(..),
1313 getServiceEnv,
1414 IdeState, initialise, shutdown,
@@ -23,20 +23,20 @@ module Development.IDE.State.Service(
2323import Control.Concurrent.Extra
2424import Control.Monad.Except
2525import Development.IDE.Types.Options (IdeOptions(..))
26−import Development.IDE.State.FileStore
27−import qualified Development.IDE.Logger as Logger
26+import Development.IDE.Core.FileStore
27+import qualified Development.IDE.Types.Logger as Logger
2828import Data.Set (Set)
2929import qualified Data.Set as Set
3030import qualified Data.Text as T
3131import Data.Tuple.Extra
32−import Development.IDE.Functions.GHCError
32+import Development.IDE.Types.Diagnostics(FileDiagnostic)
3333import Development.IDE.Types.Location (NormalizedFilePath)
3434import Development.Shake hiding (Diagnostic, Env, newCache)
3535import qualified Language.Haskell.LSP.Messages as LSP
3636
3737import UniqSupply
3838
39−import Development.IDE.State.Shake
39+import Development.IDE.Core.Shake
4040
4141
4242-- | Environment threaded through the Shake actions.
src/Development/IDE/State/Shake.hs → src/Development/IDE/Core/Shake.hsrenamed+5−6
@@ -4,7 +4,6 @@
44{-# LANGUAGE ExistentialQuantification #-}
55{-# LANGUAGE TypeFamilies #-}
66{-# LANGUAGE ConstraintKinds #-}
7−{-# LANGUAGE DuplicateRecordFields #-}
87{-# LANGUAGE OverloadedStrings #-}
98
109-- | A Shake implementation of the compiler service.
@@ -22,7 +21,7 @@
2221-- between runs. To deserialise a Shake value, we just consult Values.
2322-- Additionally, Values can be used in an inconsistent way, for example
2423-- useStale.
25−module Development.IDE.State.Shake(
24+module Development.IDE.Core.Shake(
2625 IdeState,
2726 IdeRule, IdeResult, GetModificationTime(..),
2827 shakeOpen, shakeShut,
@@ -38,8 +37,8 @@ module Development.IDE.State.Shake(
3837 garbageCollect,
3938 setPriority,
4039 sendEvent,
41− Development.IDE.State.Shake.logDebug,
42− Development.IDE.State.Shake.logSeriousError,
40+ Development.IDE.Core.Shake.logDebug,
41+ Development.IDE.Core.Shake.logSeriousError,
4342 FileVersion(..),
4443 vfsVersion
4544 ) where
@@ -55,7 +54,7 @@ import Data.Maybe
5554import Data.Either.Extra
5655import Data.List.Extra
5756import qualified Data.Text as T
58−import Development.IDE.Logger as Logger
57+import Development.IDE.Types.Logger as Logger
5958import Development.IDE.Types.Diagnostics hiding (getAllDiagnostics)
6059import qualified Development.IDE.Types.Diagnostics as D
6160import Development.IDE.Types.Location
@@ -338,7 +337,7 @@ newtype Q k = Q (k, NormalizedFilePath)
338337-- Using Database we don't need Binary instances for keys
339338instance Binary (Q k) where
340339 put _ = return ()
341− get = fail "Binary.get not defined for type Development.IDE.State.Shake.Q"
340+ get = fail "Binary.get not defined for type Development.IDE.Core.Shake.Q"
342341
343342instance Show k => Show (Q k) where
344343 show (Q (k, file)) = show k ++ "; " ++ fromNormalizedFilePath file
src/Development/IDE/Functions/CPP.hs → src/Development/IDE/GHC/CPP.hsrenamed+1−1
@@ -16,7 +16,7 @@
1616--
1717-----------------------------------------------------------------------------
1818
19−module Development.IDE.Functions.CPP(doCpp) where
19+module Development.IDE.GHC.CPP(doCpp) where
2020
2121import Packages
2222import SysTools
src/Development/IDE/Compat.hs → src/Development/IDE/GHC/Compat.hsrenamed+1−1
@@ -4,7 +4,7 @@
44{-# LANGUAGE CPP #-}
55
66-- | Attempt at hiding the GHC version differences we can.
7−module Development.IDE.Compat(
7+module Development.IDE.GHC.Compat(
88 HieFile(..),
99 mkHieFile,
1010 writeHieFile,
src/Development/IDE/Functions/GHCError.hs → src/Development/IDE/GHC/Error.hsrenamed+37−49
@@ -1,28 +1,18 @@
11-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
22-- SPDX-License-Identifier: Apache-2.0
3−{-# LANGUAGE DuplicateRecordFields #-}
4−module Development.IDE.Functions.GHCError
5− ( mkDiag
6− , toDiagnostics
3+{-# LANGUAGE OverloadedStrings #-}
4+module Development.IDE.GHC.Error
5+ (
6+ -- * Producing Diagnostic values
7+ diagFromErrMsgs
8+ , diagFromErrMsg
9+ , diagFromString
10+ , diagFromStrings
11+ , diagFromGhcException
12+
13+ -- * utilities working with spans
714 , srcSpanToLocation
815 , srcSpanToFilename
9−
10− -- * Producing GHC ErrorMessages
11− , mkErrors
12− , mkError
13− , mkErrorDoc
14− , mkErrorsGhcException
15−
16− -- * Handling errors in the GHC monad (SourceError, ErrorMessages)
17− , Diagnostic
18− , FileDiagnostic
19− , ErrorMessages -- included in module export below
20− , ErrMsg
21− , errMsgSpan
22− , errMsgSeverity
23− , mkPlainErrMsg
24−
25− -- * utilities working with 'ErrMsg' and 'ErrorMessages'
2616 , zeroSpan
2717 , realSpan
2818 , noSpan
@@ -31,35 +21,37 @@ module Development.IDE.Functions.GHCError
3121import Development.IDE.Types.Diagnostics as D
3222import qualified Data.Text as T
3323import Development.IDE.Types.Location
34−import Development.IDE.Orphans()
24+import Development.IDE.GHC.Orphans()
3525import qualified FastString as FS
3626import GHC
3727import Bag
38−import Data.Maybe
3928import ErrUtils
4029import SrcLoc
4130import qualified Outputable as Out
4231
4332
4433
45−toDiagnostics :: DynFlags -> ErrorMessages -> [FileDiagnostic]
46−toDiagnostics dflags = mapMaybe (mkDiag dflags $ T.pack "Compiler") . bagToList
34+diagFromText :: D.DiagnosticSeverity -> SrcSpan -> T.Text -> FileDiagnostic
35+diagFromText sev loc msg = (toNormalizedFilePath $ srcSpanToFilename loc,)
36+ Diagnostic
37+ { _range = srcSpanToRange loc
38+ , _severity = Just sev
39+ , _source = Just "compiler" -- should really be 'daml' or 'haskell', but not shown in the IDE so who cares
40+ , _message = msg
41+ , _code = Nothing
42+ , _relatedInformation = Nothing
43+ }
44+
45+-- | Produce a GHC-style error from a source span and a message.
46+diagFromErrMsg :: DynFlags -> ErrMsg -> [FileDiagnostic]
47+diagFromErrMsg dflags e =
48+ [ diagFromText sev (errMsgSpan e) $ T.pack $ Out.showSDoc dflags $ ErrUtils.pprLocErrMsg e
49+ | Just sev <- [toDSeverity $ errMsgSeverity e]]
50+
4751
52+diagFromErrMsgs :: DynFlags -> Bag ErrMsg -> [FileDiagnostic]
53+diagFromErrMsgs dflags = concatMap (diagFromErrMsg dflags) . bagToList
4854
49−mkDiag :: DynFlags -> T.Text -> ErrMsg -> Maybe FileDiagnostic
50−mkDiag dflags src e =
51− case toDSeverity $ errMsgSeverity e of
52− Nothing -> Nothing
53− Just bSeverity ->
54− Just $ (toNormalizedFilePath $ srcSpanToFilename (errMsgSpan e),)
55− Diagnostic
56− { _range = srcSpanToRange $ errMsgSpan e
57− , _severity = Just bSeverity
58− , _source = Just src
59− , _message = T.pack $ Out.showSDoc dflags (ErrUtils.pprLocErrMsg e)
60− , _code = Nothing
61− , _relatedInformation = Nothing
62− }
6355
6456-- | Convert a GHC SrcSpan to a DAML compiler Range
6557srcSpanToRange :: SrcSpan -> Range
@@ -95,16 +87,12 @@ toDSeverity SevFatal = Just DsError
9587
9688-- | Produce a bag of GHC-style errors (@ErrorMessages@) from the given
9789-- (optional) locations and message strings.
98−mkErrors :: DynFlags -> [(SrcSpan, String)] -> [FileDiagnostic]
99−mkErrors dflags = concatMap (uncurry $ mkError dflags)
100−
101−-- | Produce a GHC-style error from a source span and a message.
102−mkError :: DynFlags -> SrcSpan -> String -> [FileDiagnostic]
103−mkError dflags sp = toDiagnostics dflags . Bag.listToBag . pure . mkPlainErrMsg dflags sp . Out.text
90+diagFromStrings :: [(SrcSpan, String)] -> [FileDiagnostic]
91+diagFromStrings = concatMap (uncurry diagFromString)
10492
10593-- | Produce a GHC-style error from a source span and a message.
106−mkErrorDoc :: DynFlags -> SrcSpan -> Out.SDoc -> [FileDiagnostic]
107−mkErrorDoc dflags sp = toDiagnostics dflags . Bag.listToBag . pure . mkPlainErrMsg dflags sp
94+diagFromString :: SrcSpan -> String -> [FileDiagnostic]
95+diagFromString sp x = [diagFromText DsError sp $ T.pack x]
10896
10997
11098-- | Produces an "unhelpful" source span with the given string.
@@ -124,8 +112,8 @@ realSpan = \case
124112 UnhelpfulSpan _ -> Nothing
125113
126114
127−mkErrorsGhcException :: DynFlags -> GhcException -> [FileDiagnostic]
128−mkErrorsGhcException dflags exc = mkErrors dflags [(noSpan "<Internal>", showGHCE dflags exc)]
115+diagFromGhcException :: DynFlags -> GhcException -> [FileDiagnostic]
116+diagFromGhcException dflags exc = diagFromString (noSpan "<Internal>") (showGHCE dflags exc)
129117
130118showGHCE :: DynFlags -> GhcException -> String
131119showGHCE dflags exc = case exc of
src/Development/IDE/Orphans.hs → src/Development/IDE/GHC/Orphans.hsrenamed+2−2
@@ -6,13 +6,13 @@
66
77-- | Orphan instances for GHC.
88-- Note that the 'NFData' instances may not be law abiding.
9−module Development.IDE.Orphans() where
9+module Development.IDE.GHC.Orphans() where
1010
1111import GHC hiding (convertLit)
1212import GhcPlugins as GHC hiding (fst3, (<>))
1313import qualified StringBuffer as SB
1414import Control.DeepSeq
15−import Development.IDE.UtilGHC
15+import Development.IDE.GHC.Util
1616
1717
1818-- Orphan instances for types from the GHC API.
src/Development/IDE/UtilGHC.hs → src/Development/IDE/GHC/Util.hsrenamed+1−1
@@ -8,7 +8,7 @@
88-- * Call runGhc, use runGhcFast instead. It's faster and doesn't require config we don't have.
99--
1010-- * Call setSessionDynFlags, use modifyDynFlags instead. It's faster and avoids loading packages.
11−module Development.IDE.UtilGHC(
11+module Development.IDE.GHC.Util(
1212 lookupPackageConfig,
1313 modifyDynFlags,
1414 fakeDynFlags,
src/Development/IDE/Functions/Warnings.hs → src/Development/IDE/GHC/Warnings.hsrenamed+8−10
@@ -1,20 +1,18 @@
11-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
22-- SPDX-License-Identifier: Apache-2.0
33
4−module Development.IDE.Functions.Warnings(withWarnings) where
4+module Development.IDE.GHC.Warnings(withWarnings) where
55
6−import ErrUtils
76import GhcMonad
7+import ErrUtils
88import GhcPlugins as GHC hiding (Var)
99
10−import qualified Data.Text as T
11−import Data.Maybe
1210import Control.Concurrent.Extra
1311import Control.Monad.Extra
1412
1513import Development.IDE.Types.Diagnostics
16−import Development.IDE.UtilGHC
17−import Development.IDE.Functions.GHCError
14+import Development.IDE.GHC.Util
15+import Development.IDE.GHC.Error
1816
1917
2018-- | Take a GHC monadic action (e.g. @typecheckModule pm@ for some
@@ -26,18 +24,18 @@ import Development.IDE.Functions.GHCError
2624-- https://github.com/ghc/ghc/blob/5f1d949ab9e09b8d95319633854b7959df06eb58/compiler/main/GHC.hs#L623-L640
2725-- which basically says that log_action is taken from the ModSummary when GHC feels like it.
2826-- The given argument lets you refresh a ModSummary log_action
29−withWarnings :: GhcMonad m => T.Text -> ((ModSummary -> ModSummary) -> m a) -> m ([FileDiagnostic], a)
30−withWarnings phase action = do
27+withWarnings :: GhcMonad m => ((ModSummary -> ModSummary) -> m a) -> m ([FileDiagnostic], a)
28+withWarnings action = do
3129 warnings <- liftIO $ newVar []
3230 oldFlags <- getDynFlags
3331 let newAction dynFlags _ _ loc _ msg = do
34− let d = mkDiag dynFlags phase $ mkPlainWarnMsg dynFlags loc msg
32+ let d = diagFromErrMsg dynFlags $ mkPlainWarnMsg dynFlags loc msg
3533 modifyVar_ warnings $ return . (d:)
3634 setLogAction newAction
3735 res <- action $ \x -> x{ms_hspp_opts = (ms_hspp_opts x){log_action = newAction}}
3836 setLogAction $ log_action oldFlags
3937 warns <- liftIO $ readVar warnings
40− return (reverse $ catMaybes warns, res)
38+ return (reverse $ concat warns, res)
4139
4240setLogAction :: GhcMonad m => LogAction -> m ()
4341setLogAction act = void $ modifyDynFlags $ \dyn -> dyn{log_action = act}
src/Development/IDE/Functions/DependencyInformation.hs → src/Development/IDE/Import/DependencyInformation.hsrenamed+2−3
@@ -1,7 +1,7 @@
11-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
22-- SPDX-License-Identifier: Apache-2.0
33
4−module Development.IDE.Functions.DependencyInformation
4+module Development.IDE.Import.DependencyInformation
55 ( DependencyInformation(..)
66 , RawDependencyInformation(..)
77 , NodeError(..)
@@ -13,7 +13,7 @@ module Development.IDE.Functions.DependencyInformation
1313
1414import Control.DeepSeq
1515import Data.Bifunctor
16−import Development.IDE.Orphans()
16+import Development.IDE.GHC.Orphans()
1717import Data.Either
1818import Data.Foldable
1919import Data.Graph
@@ -30,7 +30,6 @@ import GHC.Generics (Generic)
3030
3131import Development.IDE.Types.Diagnostics
3232import Development.IDE.Types.Location
33−import Development.IDE.UtilGHC ()
3433
3534import GHC
3635import Module
src/Development/IDE/Functions/FindImports.hs → src/Development/IDE/Import/FindImports.hsrenamed+6−5
@@ -3,14 +3,15 @@
33
44{-# LANGUAGE OverloadedStrings #-}
55
6−module Development.IDE.Functions.FindImports
6+module Development.IDE.Import.FindImports
77 ( getImportsParsed
88 , locateModule
99 , Import(..)
1010 ) where
1111
12−import Development.IDE.Functions.GHCError as ErrUtils
13−import Development.IDE.Orphans()
12+import Development.IDE.GHC.Error as ErrUtils
13+import Development.IDE.GHC.Orphans()
14+import Development.IDE.Types.Diagnostics
1415import Development.IDE.Types.Location
1516-- GHC imports
1617import BasicTypes (StringLiteral(..))
@@ -49,7 +50,7 @@ getImportsParsed dflags (L loc parsed) = do
4950 let srcImports = filter (ideclSource . GHC.unLoc) $ GHC.hsmodImports parsed
5051 when (not $ null srcImports) $ Ex.throwE $
5152 concat
52− [ mkErrors dflags [(mloc, "Illegal source import of " <> GHC.moduleNameString (GHC.unLoc $ GHC.ideclName i))]
53+ [ diagFromString mloc ("Illegal source import of " <> GHC.moduleNameString (GHC.unLoc $ GHC.ideclName i))
5354 | L mloc i <- srcImports ]
5455
5556 -- most of these corner cases are also present in https://hackage.haskell.org/package/ghc-8.6.1/docs/src/HeaderInfo.html#getImports
@@ -107,7 +108,7 @@ notFoundErr :: DynFlags -> Located M.ModuleName -> LookupResult -> [FileDiagnost
107108notFoundErr dfs modName reason =
108109 mkError' $ ppr' $ cannotFindModule dfs modName0 $ lookupToFindResult reason
109110 where
110− mkError' = mkError dfs (getLoc modName)
111+ mkError' = diagFromString (getLoc modName)
111112 modName0 = unLoc modName
112113 ppr' = showSDoc dfs
113114 -- We convert the lookup result to a find result to reuse GHC's cannotFindMoudle pretty printer.
src/Development/IDE/LSP/Definition.hs+2−2
@@ -11,8 +11,8 @@ module Development.IDE.LSP.Definition
1111import Development.IDE.LSP.Protocol
1212import Development.IDE.Types.Location
1313
14−import qualified Development.IDE.Logger as Logger
15−import Development.IDE.State.Rules
14+import qualified Development.IDE.Types.Logger as Logger
15+import Development.IDE.Core.Rules
1616
1717import qualified Data.Text as T
1818import Data.Text.Prettyprint.Doc
src/Development/IDE/LSP/Hover.hs+2−2
@@ -12,13 +12,13 @@ import Development.IDE.LSP.Protocol hiding (Hover)
1212import Language.Haskell.LSP.Types (Hover(..))
1313import Development.IDE.Types.Location
1414
15−import qualified Development.IDE.Logger as Logger
15+import qualified Development.IDE.Types.Logger as Logger
1616
1717import qualified Data.Text as T
1818import Data.Text.Prettyprint.Doc
1919import Data.Text.Prettyprint.Doc.Render.Text
2020
21−import Development.IDE.State.Rules
21+import Development.IDE.Core.Rules
2222
2323-- | Display information on hover.
2424handle
src/Development/IDE/LSP/LanguageServer.hs+3−3
@@ -17,8 +17,8 @@ import Development.IDE.LSP.Server
1717import Control.Monad.IO.Class
1818import qualified Development.IDE.LSP.Definition as LS.Definition
1919import qualified Development.IDE.LSP.Hover as LS.Hover
20−import qualified Development.IDE.Logger as Logger
21−import Development.IDE.State.Service
20+import qualified Development.IDE.Types.Logger as Logger
21+import Development.IDE.Core.Service
2222import Development.IDE.Types.Location
2323
2424import qualified Data.Aeson as Aeson
@@ -26,7 +26,7 @@ import qualified Data.Rope.UTF16 as Rope
2626import qualified Data.Set as S
2727import qualified Data.Text as T
2828
29−import Development.IDE.State.FileStore
29+import Development.IDE.Core.FileStore
3030
3131import qualified Network.URI as URI
3232
src/Development/IDE/LSP/Server.hs+1−1
@@ -19,7 +19,7 @@ import Control.Concurrent.STM
1919import Data.Default
2020
2121import Development.IDE.LSP.Protocol
22−import qualified Development.IDE.Logger as Logger
22+import qualified Development.IDE.Types.Logger as Logger
2323
2424import qualified Data.Aeson as Aeson
2525import qualified Data.Aeson.Text as Aeson
src/Development/IDE/Functions/AtPoint.hs → src/Development/IDE/Spans/AtPoint.hsrenamed+20−20
@@ -4,24 +4,22 @@
44{-# LANGUAGE OverloadedStrings #-}
55-- | Gives information about symbols at a given point in DAML files.
66-- These are all pure functions that should execute quickly.
7−module Development.IDE.Functions.AtPoint (
7+module Development.IDE.Spans.AtPoint (
88 atPoint
99 , gotoDefinition
1010 ) where
1111
12−import Development.IDE.Functions.Documentation
13−import Development.IDE.Functions.GHCError
14−import Development.IDE.Orphans()
12+import Development.IDE.Spans.Documentation
13+import Development.IDE.GHC.Error
14+import Development.IDE.GHC.Orphans()
1515import Development.IDE.Types.Location
1616
1717-- DAML compiler and infrastructure
1818import Development.Shake
19−import Development.IDE.UtilGHC
20−import Development.IDE.Compat
21−import Development.IDE.State.Shake
22−import Development.IDE.State.RuleTypes
19+import Development.IDE.GHC.Util
20+import Development.IDE.GHC.Compat
2321import Development.IDE.Types.Options
24−import Development.IDE.Types.SpanInfo as SpanInfo
22+import Development.IDE.Spans.Type as SpanInfo
2523
2624-- GHC API imports
2725import Avail
@@ -33,19 +31,22 @@ import Outputable hiding ((<>))
3331
3432import Control.Monad.Extra
3533import Control.Monad.Trans.Maybe
34+import Control.Monad.IO.Class
3635import Data.Maybe
3736import Data.List
3837import qualified Data.Text as T
3938
4039-- | Locate the definition of the name at a given position.
4140gotoDefinition
42− :: IdeOptions
41+ :: MonadIO m
42+ => (FilePath -> m (Maybe HieFile))
43+ -> IdeOptions
4344 -> HscEnv
4445 -> [SpanInfo]
4546 -> Position
46− -> Action (Maybe Location)
47−gotoDefinition ideOpts pkgState srcSpans pos =
48− listToMaybe <$> locationsAtPoint ideOpts pkgState pos srcSpans
47+ -> m (Maybe Location)
48+gotoDefinition getHieFile ideOpts pkgState srcSpans pos =
49+ listToMaybe <$> locationsAtPoint getHieFile ideOpts pkgState pos srcSpans
4950
5051-- | Synopsis for the name at a given position.
5152atPoint
@@ -59,8 +60,7 @@ atPoint IdeOptions{..} tcs srcSpans pos = do
5960 ty <- spaninfoType
6061 let mbName = getNameM spaninfoSource
6162 mbDefinedAt = fmap (\name -> "**Defined " <> T.pack (showSDocUnsafe $ pprNameDefnLoc name) <> "**\n") mbName
62− mbDocs = fmap (\name -> getDocumentation name tcs) mbName
63− docInfo = maybe [] docHeaders mbDocs
63+ docInfo = maybe [] (\name -> getDocumentation name tcs) mbName
6464 range = Range
6565 (Position spaninfoStartLine spaninfoStartCol)
6666 (Position spaninfoEndLine spaninfoEndCol)
@@ -88,14 +88,14 @@ atPoint IdeOptions{..} tcs srcSpans pos = do
8888 Just name -> any (`isInfixOf` show name) ["==", "showsPrec"]
8989 Nothing -> False
9090
91−locationsAtPoint :: IdeOptions -> HscEnv -> Position -> [SpanInfo] -> Action [Location]
92−locationsAtPoint IdeOptions{..} pkgState pos =
91+locationsAtPoint :: forall m . MonadIO m => (FilePath -> m (Maybe HieFile)) -> IdeOptions -> HscEnv -> Position -> [SpanInfo] -> m [Location]
92+locationsAtPoint getHieFile IdeOptions{..} pkgState pos =
9393 fmap (map srcSpanToLocation) .
9494 mapMaybeM (getSpan . spaninfoSource) .
9595 spansAtPoint pos
96− where getSpan :: SpanSource -> Action (Maybe SrcSpan)
96+ where getSpan :: SpanSource -> m (Maybe SrcSpan)
9797 getSpan NoSource = pure Nothing
98− getSpan (Span sp) = pure $ Just sp
98+ getSpan (SpanS sp) = pure $ Just sp
9999 getSpan (Named name) = case nameSrcSpan name of
100100 sp@(RealSrcSpan _) -> pure $ Just sp
101101 UnhelpfulSpan _ -> runMaybeT $ do
@@ -106,7 +106,7 @@ locationsAtPoint IdeOptions{..} pkgState pos =
106106 let unitId = moduleUnitId mod
107107 pkgConfig <- MaybeT $ pure $ lookupPackageConfig unitId pkgState
108108 hiePath <- MaybeT $ liftIO $ optLocateHieFile optPkgLocationOpts pkgConfig mod
109− hieFile <- MaybeT $ use (GetHieFile hiePath) ""
109+ hieFile <- MaybeT $ getHieFile hiePath
110110 avail <- MaybeT $ pure $ listToMaybe (filterAvails (eqName name) $ hie_exports hieFile)
111111 srcPath <- MaybeT $ liftIO $ optLocateSrcFile optPkgLocationOpts pkgConfig mod
112112 -- The location will point to the source file used during compilation.
src/Development/IDE/Functions/SpanInfo.hs → src/Development/IDE/Spans/Calculate.hsrenamed+4−4
@@ -7,7 +7,7 @@
77
88-- | Get information on modules, identifiers, etc.
99
10−module Development.IDE.Functions.SpanInfo(getSpanInfo,listifyAllSpans) where
10+module Development.IDE.Spans.Calculate(getSpanInfo,listifyAllSpans) where
1111
1212import ConLike
1313import Control.Monad
@@ -22,8 +22,8 @@ import GHC
2222import GhcMonad
2323import FastString (mkFastString)
2424import Development.IDE.Types.Location
25−import Development.IDE.Types.SpanInfo
26−import Development.IDE.Functions.GHCError (zeroSpan)
25+import Development.IDE.Spans.Type
26+import Development.IDE.GHC.Error (zeroSpan)
2727import Prelude hiding (mod)
2828import TcHsSyn
2929import Var
@@ -123,7 +123,7 @@ importInfo = mapMaybe (uncurry wrk) where
123123
124124 -- TODO make this point to the module name
125125 fpToSpanSource :: FilePath -> SpanSource
126− fpToSpanSource fp = Span $ RealSrcSpan $ zeroSpan $ mkFastString fp
126+ fpToSpanSource fp = SpanS $ RealSrcSpan $ zeroSpan $ mkFastString fp
127127
128128-- | Get ALL source spans in the source.
129129listifyAllSpans :: Typeable a
src/Development/IDE/Functions/Documentation.hs → src/Development/IDE/Spans/Documentation.hsrenamed+5−5
@@ -1,9 +1,8 @@
11-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
22-- SPDX-License-Identifier: Apache-2.0
33
4−module Development.IDE.Functions.Documentation (
4+module Development.IDE.Spans.Documentation (
55 getDocumentation
6− , docHeaders
76 ) where
87
98import Control.Monad
@@ -11,8 +10,8 @@ import Data.List.Extra
1110import qualified Data.Map as M
1211import Data.Maybe
1312import qualified Data.Text as T
14−import Development.IDE.Functions.GHCError
15−import Development.IDE.Functions.SpanInfo
13+import Development.IDE.GHC.Error
14+import Development.IDE.Spans.Calculate
1615import FastString
1716import GHC
1817import SrcLoc
@@ -21,7 +20,7 @@ import SrcLoc
2120getDocumentation
2221 :: Name -- ^ The name you want documentation for.
2322 -> [TypecheckedModule] -- ^ All of the possible modules it could be defined in.
24− -> [RealLocated AnnotationComment]
23+ -> [T.Text]
2524-- This finds any documentation between the name you want
2625-- documentation for and the one before it. This is only an
2726-- approximately correct algorithm and there are easily constructed
@@ -52,6 +51,7 @@ getDocumentation targetName tcs = fromMaybe [] $ do
5251 -- Annoyingly "-- |" documentation isn't annotated with a location,
5352 -- so you have to pull it out from the elements.
5453 pure
54+ $ docHeaders
5555 $ filter (\(L target _) -> isBetween target prevNameSpan targetNameSpan)
5656 $ mapMaybe (\(L l v) -> L <$> realSpan l <*> pure v)
5757 $ join
src/Development/IDE/Types/SpanInfo.hs → src/Development/IDE/Spans/Type.hsrenamed+3−3
@@ -5,7 +5,7 @@
55
66-- | Types used separate to GHCi vanilla.
77
8−module Development.IDE.Types.SpanInfo(
8+module Development.IDE.Spans.Type(
99 SpanInfo(..)
1010 , SpanSource(..)
1111 , getNameM
@@ -40,14 +40,14 @@ instance Show SpanInfo where
4040
4141-- we don't always get a name out so sometimes manually annotating source is more appropriate
4242data SpanSource = Named Name
43− | Span SrcSpan
43+ | SpanS SrcSpan
4444 | NoSource
4545 deriving (Eq)
4646
4747instance Show SpanSource where
4848 show = \case
4949 Named n -> "Named " ++ occNameString (occName n)
50− Span sp -> "Span " ++ show sp
50+ SpanS sp -> "Span " ++ show sp
5151 NoSource -> "NoSource"
5252
5353getNameM :: SpanSource -> Maybe Name
src/Development/IDE/Types/Diagnostics.hs+1−3
@@ -1,10 +1,8 @@
11-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
22-- SPDX-License-Identifier: Apache-2.0
33
4−{-# LANGUAGE FlexibleInstances #-}
54{-# LANGUAGE OverloadedStrings #-}
6−{-# LANGUAGE DuplicateRecordFields #-}
7−{-# LANGUAGE BlockArguments #-}
5+
86module Development.IDE.Types.Diagnostics (
97 LSP.Diagnostic(..),
108 FileDiagnostic,
src/Development/IDE/Logger.hs → src/Development/IDE/Types/Logger.hsrenamed+1−1
@@ -5,7 +5,7 @@
55-- | This is a compatibility module that abstracts over the
66-- concrete choice of logging framework so users can plug in whatever
77-- framework they want to.
8−module Development.IDE.Logger
8+module Development.IDE.Types.Logger
99 ( Handle(..)
1010 , makeOneHandle
1111 , makeNopHandle
test/Demo.hs+6−6
@@ -7,17 +7,17 @@ import Data.Maybe
77import Control.Concurrent.Extra
88import Control.Monad
99import System.Time.Extra
10−import Development.IDE.State.FileStore
11−import Development.IDE.State.Service
12−import Development.IDE.State.Rules
13−import Development.IDE.State.Shake
14−import Development.IDE.State.RuleTypes
10+import Development.IDE.Core.FileStore
11+import Development.IDE.Core.Service
12+import Development.IDE.Core.Rules
13+import Development.IDE.Core.Shake
14+import Development.IDE.Core.RuleTypes
1515import Development.IDE.LSP.Protocol
1616import Development.IDE.Types.Location
1717import Data.String
1818import Development.IDE.Types.Diagnostics
1919import Development.IDE.Types.Options
20−import Development.IDE.Logger
20+import Development.IDE.Types.Logger
2121import qualified Data.Text.IO as T
2222import Language.Haskell.LSP.Messages
2323import Development.IDE.LSP.LanguageServer