on master help sign in
Further cleanups to hie-core (#1819)
f46fff9Neil Mitchell
hie-core.cabal+19−19
@@ -76,33 +76,33 @@ library
76 src
76 src
77 ../../libs-haskell/prettyprinter-syntax/src
77 ../../libs-haskell/prettyprinter-syntax/src
78 exposed-modules:
78 exposed-modules:
79− Development.IDE.Logger
79+ Development.IDE.Types.Logger
80− Development.IDE.UtilGHC
80+ Development.IDE.GHC.Util
81− Development.IDE.Functions.AtPoint
81+ Development.IDE.Spans.AtPoint
82− Development.IDE.Functions.Compile
82+ Development.IDE.Core.Compile
83− Development.IDE.Functions.CPP
83+ Development.IDE.GHC.CPP
84− Development.IDE.Orphans
84+ Development.IDE.GHC.Orphans
85− Development.IDE.Functions.DependencyInformation
85+ Development.IDE.Import.DependencyInformation
86− Development.IDE.Functions.Documentation
86+ Development.IDE.Spans.Documentation
87− Development.IDE.Functions.FindImports
87+ Development.IDE.Import.FindImports
88− Development.IDE.Functions.GHCError
88+ Development.IDE.GHC.Error
89− Development.IDE.Functions.SpanInfo
89+ Development.IDE.Spans.Calculate
90− Development.IDE.Functions.Warnings
90+ Development.IDE.GHC.Warnings
91− Development.IDE.State.FileStore
91+ Development.IDE.Core.FileStore
92− Development.IDE.State.Rules
92+ Development.IDE.Core.Rules
93− Development.IDE.Compat
93+ Development.IDE.GHC.Compat
94 Development.IDE.LSP.LanguageServer
94 Development.IDE.LSP.LanguageServer
95 Development.IDE.LSP.Definition
95 Development.IDE.LSP.Definition
96 Development.IDE.LSP.Hover
96 Development.IDE.LSP.Hover
97 Development.IDE.LSP.Protocol
97 Development.IDE.LSP.Protocol
98 Development.IDE.LSP.Server
98 Development.IDE.LSP.Server
99 Development.IDE.Types.Options
99 Development.IDE.Types.Options
100− Development.IDE.State.RuleTypes
100+ Development.IDE.Core.RuleTypes
101− Development.IDE.State.Service
101+ Development.IDE.Core.Service
102− Development.IDE.State.Shake
102+ Development.IDE.Core.Shake
103 Development.IDE.Types.Diagnostics
103 Development.IDE.Types.Diagnostics
104 Development.IDE.Types.Location
104 Development.IDE.Types.Location
105− Development.IDE.Types.SpanInfo
105+ Development.IDE.Spans.Type
106 other-modules:
106 other-modules:
107 Data.Text.Prettyprint.Doc.Syntax
107 Data.Text.Prettyprint.Doc.Syntax
108
108
src/Development/IDE/Functions/Compile.hs → src/Development/IDE/Core/Compile.hsrenamed+18−18
@@ -7,7 +7,7 @@
7
7
8-- | Based on https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/API.
8-- | Based on https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/API.
9-- Given a list of paths to find libraries, and a file to compile, produce a list of 'CoreModule' values.
9-- 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
11 ( GhcModule(..)
11 ( GhcModule(..)
12 , TcModuleResult(..)
12 , TcModuleResult(..)
13 , LoadPackageResult(..)
13 , LoadPackageResult(..)
@@ -20,21 +20,21 @@ module Development.IDE.Functions.Compile
20 , computePackageDeps
20 , computePackageDeps
21 ) where
21 ) where
22
22
23−import Development.IDE.Functions.Warnings
23+import Development.IDE.GHC.Warnings
24−import Development.IDE.Functions.CPP
24+import Development.IDE.GHC.CPP
25import Development.IDE.Types.Diagnostics
25import Development.IDE.Types.Diagnostics
26−import qualified Development.IDE.Functions.FindImports as FindImports
26+import qualified Development.IDE.Import.FindImports as FindImports
27−import Development.IDE.Functions.GHCError
27+import Development.IDE.GHC.Error
28−import Development.IDE.Functions.SpanInfo
28+import Development.IDE.Spans.Calculate
29−import Development.IDE.UtilGHC
29+import Development.IDE.GHC.Util
30−import Development.IDE.Compat
30+import Development.IDE.GHC.Compat
31import Development.IDE.Types.Options
31import Development.IDE.Types.Options
32import Development.IDE.Types.Location
32import Development.IDE.Types.Location
33
33
34import GHC hiding (parseModule, typecheckModule)
34import GHC hiding (parseModule, typecheckModule)
35import qualified Parser
35import qualified Parser
36import Lexer
36import Lexer
37−import Bag
37+import ErrUtils
38
38
39import qualified GHC
39import qualified GHC
40import Panic
40import Panic
@@ -56,7 +56,7 @@ import Data.List.Extra
56import Data.Maybe
56import Data.Maybe
57import Data.Tuple.Extra
57import Data.Tuple.Extra
58import qualified Data.Map.Strict as Map
58import qualified Data.Map.Strict as Map
59−import Development.IDE.Types.SpanInfo
59+import Development.IDE.Spans.Type
60import GHC.Generics (Generic)
60import GHC.Generics (Generic)
61import System.FilePath
61import System.FilePath
62import System.Directory
62import System.Directory
@@ -143,7 +143,7 @@ typecheckModule opt packageState deps pm =
143 runGhcSessionExcept opt (Just pm) packageState $
143 runGhcSessionExcept opt (Just pm) packageState $
144 catchSrcErrors $ do
144 catchSrcErrors $ do
145 setupEnv deps
145 setupEnv deps
146− (warnings, tcm) <- withWarnings "Typechecker" $ \tweak ->
146+ (warnings, tcm) <- withWarnings $ \tweak ->
147 GHC.typecheckModule pm{pm_mod_summary = tweak $ pm_mod_summary pm}
147 GHC.typecheckModule pm{pm_mod_summary = tweak $ pm_mod_summary pm}
148 tcm2 <- mkTcModuleResult (WriteInterface $ optWriteIface opt) tcm
148 tcm2 <- mkTcModuleResult (WriteInterface $ optWriteIface opt) tcm
149 return (warnings, tcm2)
149 return (warnings, tcm2)
@@ -182,7 +182,7 @@ compileModule opt mod packageState deps tmr =
182
182
183 let tm = tmrModule tmr
183 let tm = tmrModule tmr
184 session <- getSession
184 session <- getSession
185− (warnings,desugar) <- withWarnings "Desugarer" $ \tweak -> do
185+ (warnings,desugar) <- withWarnings $ \tweak -> do
186 let pm = tm_parsed_module tm
186 let pm = tm_parsed_module tm
187 let pm' = pm{pm_mod_summary = tweak $ pm_mod_summary pm}
187 let pm' = pm{pm_mod_summary = tweak $ pm_mod_summary pm}
188 let tm' = tm{tm_parsed_module = pm'}
188 let tm' = tm{tm_parsed_module = pm'}
@@ -395,7 +395,7 @@ parseFileContents preprocessor filename contents = do
395
395
396 case unP Parser.parseModule (mkPState dflags contents loc) of
396 case unP Parser.parseModule (mkPState dflags contents loc) of
397 PFailed _ locErr msgErr ->
397 PFailed _ locErr msgErr ->
398− Ex.throwE $ mkErrorDoc dflags locErr msgErr
398+ Ex.throwE $ diagFromErrMsg dflags $ mkPlainErrMsg dflags locErr msgErr
399 POk pst rdr_module ->
399 POk pst rdr_module ->
400 let hpm_annotations =
400 let hpm_annotations =
401 (Map.fromListWith (++) $ annotations pst,
401 (Map.fromListWith (++) $ annotations pst,
@@ -414,11 +414,11 @@ parseFileContents preprocessor filename contents = do
414 -- errors are those from which a parse tree just can't
414 -- errors are those from which a parse tree just can't
415 -- be produced.
415 -- be produced.
416 unless (null errs) $
416 unless (null errs) $
417− Ex.throwE $ toDiagnostics dflags $ snd $ getMessages pst dflags
417+ Ex.throwE $ diagFromErrMsgs dflags $ snd $ getMessages pst dflags
418
418
419 -- Ok, we got here. It's safe to continue.
419 -- Ok, we got here. It's safe to continue.
420 let (errs, parsed) = preprocessor rdr_module
420 let (errs, parsed) = preprocessor rdr_module
421− unless (null errs) $ Ex.throwE $ mkErrors dflags errs
421+ unless (null errs) $ Ex.throwE $ diagFromStrings errs
422 ms <- getModSummaryFromBuffer filename contents dflags parsed
422 ms <- getModSummaryFromBuffer filename contents dflags parsed
423 let pm =
423 let pm =
424 ParsedModule {
424 ParsedModule {
@@ -427,7 +427,7 @@ parseFileContents preprocessor filename contents = do
427 , pm_extra_src_files=[] -- src imports not allowed
427 , pm_extra_src_files=[] -- src imports not allowed
428 , pm_annotations = hpm_annotations
428 , pm_annotations = hpm_annotations
429 }
429 }
430− warnings = mapMaybe (mkDiag dflags "Parser") $ bagToList warns
430+ warnings = diagFromErrMsgs dflags warns
431 pure (warnings, pm)
431 pure (warnings, pm)
432
432
433
433
@@ -453,5 +453,5 @@ catchSrcErrors ghcM = do
453 handleSourceError (sourceErrorToDiagnostics dflags) $
453 handleSourceError (sourceErrorToDiagnostics dflags) $
454 Right <$> ghcM
454 Right <$> ghcM
455 where
455 where
456− ghcExceptionToDiagnostics dflags = return . Left . mkErrorsGhcException dflags
456+ ghcExceptionToDiagnostics dflags = return . Left . diagFromGhcException dflags
457− sourceErrorToDiagnostics dflags = return . Left . toDiagnostics dflags . srcErrorMessages
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 @@
3
3
4{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE TypeFamilies #-}
5
5
6−module Development.IDE.State.FileStore(
6+module Development.IDE.Core.FileStore(
7 getFileExists, getFileContents,
7 getFileExists, getFileContents,
8 setBufferModified,
8 setBufferModified,
9 fileStoreRules,
9 fileStoreRules,
@@ -13,7 +13,7 @@ module Development.IDE.State.FileStore(
13 ) where
13 ) where
14
14
15import StringBuffer
15import StringBuffer
16−import Development.IDE.Orphans()
16+import Development.IDE.GHC.Orphans()
17
17
18import Control.Concurrent.Extra
18import Control.Concurrent.Extra
19import qualified Data.Map.Strict as Map
19import qualified Data.Map.Strict as Map
@@ -24,7 +24,7 @@ import Control.Monad.Extra
24import qualified System.Directory as Dir
24import qualified System.Directory as Dir
25import Development.Shake
25import Development.Shake
26import Development.Shake.Classes
26import Development.Shake.Classes
27−import Development.IDE.State.Shake
27+import Development.IDE.Core.Shake
28import Control.Exception
28import Control.Exception
29import GHC.Generics
29import GHC.Generics
30import Data.Either.Extra
30import Data.Either.Extra
src/Development/IDE/State/RuleTypes.hs → src/Development/IDE/Core/RuleTypes.hsrenamed+8−8
@@ -8,15 +8,15 @@
8-- | A Shake implementation of the compiler service, built
8-- | A Shake implementation of the compiler service, built
9-- using the "Shaker" abstraction layer for in-memory use.
9-- using the "Shaker" abstraction layer for in-memory use.
10--
10--
11−module Development.IDE.State.RuleTypes(
11+module Development.IDE.Core.RuleTypes(
12− module Development.IDE.State.RuleTypes
12+ module Development.IDE.Core.RuleTypes
13 ) where
13 ) where
14
14
15import Control.DeepSeq
15import Control.DeepSeq
16−import Development.IDE.Functions.Compile (TcModuleResult, GhcModule, LoadPackageResult(..))
16+import Development.IDE.Core.Compile (TcModuleResult, GhcModule, LoadPackageResult(..))
17−import qualified Development.IDE.Functions.Compile as Compile
17+import qualified Development.IDE.Core.Compile as Compile
18−import Development.IDE.Functions.FindImports (Import(..))
18+import Development.IDE.Import.FindImports (Import(..))
19−import Development.IDE.Functions.DependencyInformation
19+import Development.IDE.Import.DependencyInformation
20import Data.Hashable
20import Data.Hashable
21import Data.Typeable
21import Data.Typeable
22import Development.IDE.Types.Location
22import Development.IDE.Types.Location
@@ -25,10 +25,10 @@ import Development.Shake hiding (Env, newCache)
25import GHC.Generics (Generic)
25import GHC.Generics (Generic)
26
26
27import GHC
27import GHC
28−import Development.IDE.Compat
28+import Development.IDE.GHC.Compat
29import Module
29import Module
30
30
31−import Development.IDE.Types.SpanInfo
31+import Development.IDE.Spans.Type
32
32
33
33
34-- NOTATION
34-- NOTATION
src/Development/IDE/State/Rules.hs → src/Development/IDE/Core/Rules.hsrenamed+13−12
@@ -9,7 +9,7 @@
9-- | A Shake implementation of the compiler service, built
9-- | A Shake implementation of the compiler service, built
10-- using the "Shaker" abstraction layer for in-memory use.
10-- using the "Shaker" abstraction layer for in-memory use.
11--
11--
12−module Development.IDE.State.Rules(
12+module Development.IDE.Core.Rules(
13 IdeState, GetDependencies(..), GetParsedModule(..), TransitiveDependencies(..),
13 IdeState, GetDependencies(..), GetParsedModule(..), TransitiveDependencies(..),
14 Priority(..),
14 Priority(..),
15 runAction, runActions, useE, usesE,
15 runAction, runActions, useE, usesE,
@@ -25,11 +25,11 @@ module Development.IDE.State.Rules(
25
25
26import Control.Monad.Except
26import Control.Monad.Except
27import Control.Monad.Trans.Maybe
27import Control.Monad.Trans.Maybe
28−import qualified Development.IDE.Functions.Compile as Compile
28+import qualified Development.IDE.Core.Compile as Compile
29import qualified Development.IDE.Types.Options as Compile
29import qualified Development.IDE.Types.Options as Compile
30−import Development.IDE.Functions.DependencyInformation
30+import Development.IDE.Import.DependencyInformation
31−import Development.IDE.Functions.FindImports
31+import Development.IDE.Import.FindImports
32−import Development.IDE.State.FileStore
32+import Development.IDE.Core.FileStore
33import Development.IDE.Types.Diagnostics as Base
33import Development.IDE.Types.Diagnostics as Base
34import Development.IDE.Types.Location
34import Development.IDE.Types.Location
35import qualified Data.ByteString.UTF8 as BS
35import qualified Data.ByteString.UTF8 as BS
@@ -42,18 +42,18 @@ import Data.Foldable
42import qualified Data.Map.Strict as Map
42import qualified Data.Map.Strict as Map
43import qualified Data.Set as Set
43import qualified Data.Set as Set
44import qualified Data.Text as T
44import qualified Data.Text as T
45−import Development.IDE.Functions.GHCError
45+import Development.IDE.GHC.Error
46import Development.Shake hiding (Diagnostic, Env, newCache)
46import Development.Shake hiding (Diagnostic, Env, newCache)
47−import Development.IDE.State.RuleTypes
47+import Development.IDE.Core.RuleTypes
48
48
49import GHC
49import GHC
50−import Development.IDE.Compat
50+import Development.IDE.GHC.Compat
51import UniqSupply
51import UniqSupply
52import NameCache
52import NameCache
53
53
54−import qualified Development.IDE.Functions.AtPoint as AtPoint
54+import qualified Development.IDE.Spans.AtPoint as AtPoint
55−import Development.IDE.State.Service
55+import Development.IDE.Core.Service
56−import Development.IDE.State.Shake
56+import Development.IDE.Core.Shake
57
57
58-- | This is useful for rules to convert rules that can only produce errors or
58-- | This is useful for rules to convert rules that can only produce errors or
59-- a result into the more general IdeResult type that supports producing
59-- a result into the more general IdeResult type that supports producing
@@ -117,7 +117,8 @@ getDefinition file pos = fmap join $ runMaybeT $ do
117 spans <- useE GetSpanInfo file
117 spans <- useE GetSpanInfo file
118 pkgState <- useE GhcSession ""
118 pkgState <- useE GhcSession ""
119 opts <- lift getOpts
119 opts <- lift getOpts
120+ let getHieFile x = use (GetHieFile x) ""
120− lift $ AtPoint.gotoDefinition opts pkgState spans pos
121+ lift $ AtPoint.gotoDefinition getHieFile opts pkgState spans pos
121
122
122-- | Parse the contents of a daml file.
123-- | Parse the contents of a daml file.
123getParsedModule :: NormalizedFilePath -> Action (Maybe ParsedModule)
124getParsedModule :: NormalizedFilePath -> Action (Maybe ParsedModule)
src/Development/IDE/State/Service.hs → src/Development/IDE/Core/Service.hsrenamed+5−5
@@ -8,7 +8,7 @@
8-- | A Shake implementation of the compiler service, built
8-- | A Shake implementation of the compiler service, built
9-- using the "Shaker" abstraction layer for in-memory use.
9-- using the "Shaker" abstraction layer for in-memory use.
10--
10--
11−module Development.IDE.State.Service(
11+module Development.IDE.Core.Service(
12 Env(..),
12 Env(..),
13 getServiceEnv,
13 getServiceEnv,
14 IdeState, initialise, shutdown,
14 IdeState, initialise, shutdown,
@@ -23,20 +23,20 @@ module Development.IDE.State.Service(
23import Control.Concurrent.Extra
23import Control.Concurrent.Extra
24import Control.Monad.Except
24import Control.Monad.Except
25import Development.IDE.Types.Options (IdeOptions(..))
25import Development.IDE.Types.Options (IdeOptions(..))
26−import Development.IDE.State.FileStore
26+import Development.IDE.Core.FileStore
27−import qualified Development.IDE.Logger as Logger
27+import qualified Development.IDE.Types.Logger as Logger
28import Data.Set (Set)
28import Data.Set (Set)
29import qualified Data.Set as Set
29import qualified Data.Set as Set
30import qualified Data.Text as T
30import qualified Data.Text as T
31import Data.Tuple.Extra
31import Data.Tuple.Extra
32−import Development.IDE.Functions.GHCError
32+import Development.IDE.Types.Diagnostics(FileDiagnostic)
33import Development.IDE.Types.Location (NormalizedFilePath)
33import Development.IDE.Types.Location (NormalizedFilePath)
34import Development.Shake hiding (Diagnostic, Env, newCache)
34import Development.Shake hiding (Diagnostic, Env, newCache)
35import qualified Language.Haskell.LSP.Messages as LSP
35import qualified Language.Haskell.LSP.Messages as LSP
36
36
37import UniqSupply
37import UniqSupply
38
38
39−import Development.IDE.State.Shake
39+import Development.IDE.Core.Shake
40
40
41
41
42-- | Environment threaded through the Shake actions.
42-- | Environment threaded through the Shake actions.
src/Development/IDE/State/Shake.hs → src/Development/IDE/Core/Shake.hsrenamed+5−6
@@ -4,7 +4,6 @@
4{-# LANGUAGE ExistentialQuantification #-}
4{-# LANGUAGE ExistentialQuantification #-}
5{-# LANGUAGE TypeFamilies #-}
5{-# LANGUAGE TypeFamilies #-}
6{-# LANGUAGE ConstraintKinds #-}
6{-# LANGUAGE ConstraintKinds #-}
7−{-# LANGUAGE DuplicateRecordFields #-}
8{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE OverloadedStrings #-}
9
8
10-- | A Shake implementation of the compiler service.
9-- | A Shake implementation of the compiler service.
@@ -22,7 +21,7 @@
22-- between runs. To deserialise a Shake value, we just consult Values.
21-- between runs. To deserialise a Shake value, we just consult Values.
23-- Additionally, Values can be used in an inconsistent way, for example
22-- Additionally, Values can be used in an inconsistent way, for example
24-- useStale.
23-- useStale.
25−module Development.IDE.State.Shake(
24+module Development.IDE.Core.Shake(
26 IdeState,
25 IdeState,
27 IdeRule, IdeResult, GetModificationTime(..),
26 IdeRule, IdeResult, GetModificationTime(..),
28 shakeOpen, shakeShut,
27 shakeOpen, shakeShut,
@@ -38,8 +37,8 @@ module Development.IDE.State.Shake(
38 garbageCollect,
37 garbageCollect,
39 setPriority,
38 setPriority,
40 sendEvent,
39 sendEvent,
41− Development.IDE.State.Shake.logDebug,
40+ Development.IDE.Core.Shake.logDebug,
42− Development.IDE.State.Shake.logSeriousError,
41+ Development.IDE.Core.Shake.logSeriousError,
43 FileVersion(..),
42 FileVersion(..),
44 vfsVersion
43 vfsVersion
45 ) where
44 ) where
@@ -55,7 +54,7 @@ import Data.Maybe
55import Data.Either.Extra
54import Data.Either.Extra
56import Data.List.Extra
55import Data.List.Extra
57import qualified Data.Text as T
56import qualified Data.Text as T
58−import Development.IDE.Logger as Logger
57+import Development.IDE.Types.Logger as Logger
59import Development.IDE.Types.Diagnostics hiding (getAllDiagnostics)
58import Development.IDE.Types.Diagnostics hiding (getAllDiagnostics)
60import qualified Development.IDE.Types.Diagnostics as D
59import qualified Development.IDE.Types.Diagnostics as D
61import Development.IDE.Types.Location
60import Development.IDE.Types.Location
@@ -338,7 +337,7 @@ newtype Q k = Q (k, NormalizedFilePath)
338-- Using Database we don't need Binary instances for keys
337-- Using Database we don't need Binary instances for keys
339instance Binary (Q k) where
338instance Binary (Q k) where
340 put _ = return ()
339 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"
342
341
343instance Show k => Show (Q k) where
342instance Show k => Show (Q k) where
344 show (Q (k, file)) = show k ++ "; " ++ fromNormalizedFilePath file
343 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 @@
16--
16--
17-----------------------------------------------------------------------------
17-----------------------------------------------------------------------------
18
18
19−module Development.IDE.Functions.CPP(doCpp) where
19+module Development.IDE.GHC.CPP(doCpp) where
20
20
21import Packages
21import Packages
22import SysTools
22import SysTools
src/Development/IDE/Compat.hs → src/Development/IDE/GHC/Compat.hsrenamed+1−1
@@ -4,7 +4,7 @@
4{-# LANGUAGE CPP #-}
4{-# LANGUAGE CPP #-}
5
5
6-- | Attempt at hiding the GHC version differences we can.
6-- | Attempt at hiding the GHC version differences we can.
7−module Development.IDE.Compat(
7+module Development.IDE.GHC.Compat(
8 HieFile(..),
8 HieFile(..),
9 mkHieFile,
9 mkHieFile,
10 writeHieFile,
10 writeHieFile,
src/Development/IDE/Functions/GHCError.hs → src/Development/IDE/GHC/Error.hsrenamed+37−49
@@ -1,28 +1,18 @@
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
2-- SPDX-License-Identifier: Apache-2.0
3−{-# LANGUAGE DuplicateRecordFields #-}
3+{-# LANGUAGE OverloadedStrings #-}
4−module Development.IDE.Functions.GHCError
4+module Development.IDE.GHC.Error
5− ( mkDiag
5+ (
6− , toDiagnostics
6+ -- * Producing Diagnostic values
7+ diagFromErrMsgs
8+ , diagFromErrMsg
9+ , diagFromString
10+ , diagFromStrings
11+ , diagFromGhcException
12+
13+ -- * utilities working with spans
7 , srcSpanToLocation
14 , srcSpanToLocation
8 , srcSpanToFilename
15 , 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'
26 , zeroSpan
16 , zeroSpan
27 , realSpan
17 , realSpan
28 , noSpan
18 , noSpan
@@ -31,35 +21,37 @@ module Development.IDE.Functions.GHCError
31import Development.IDE.Types.Diagnostics as D
21import Development.IDE.Types.Diagnostics as D
32import qualified Data.Text as T
22import qualified Data.Text as T
33import Development.IDE.Types.Location
23import Development.IDE.Types.Location
34−import Development.IDE.Orphans()
24+import Development.IDE.GHC.Orphans()
35import qualified FastString as FS
25import qualified FastString as FS
36import GHC
26import GHC
37import Bag
27import Bag
38−import Data.Maybe
39import ErrUtils
28import ErrUtils
40import SrcLoc
29import SrcLoc
41import qualified Outputable as Out
30import qualified Outputable as Out
42
31
43
32
44
33
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.
45−toDiagnostics :: DynFlags -> ErrorMessages -> [FileDiagnostic]
46+diagFromErrMsg :: DynFlags -> ErrMsg -> [FileDiagnostic]
46−toDiagnostics dflags = mapMaybe (mkDiag dflags $ T.pack "Compiler") . bagToList
47+diagFromErrMsg dflags e =
48+ [ diagFromText sev (errMsgSpan e) $ T.pack $ Out.showSDoc dflags $ ErrUtils.pprLocErrMsg e
49+ | Just sev <- [toDSeverity $ errMsgSeverity e]]
50+
47
51
52+diagFromErrMsgs :: DynFlags -> Bag ErrMsg -> [FileDiagnostic]
53+diagFromErrMsgs dflags = concatMap (diagFromErrMsg dflags) . bagToList
48
54
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− }
63
55
64-- | Convert a GHC SrcSpan to a DAML compiler Range
56-- | Convert a GHC SrcSpan to a DAML compiler Range
65srcSpanToRange :: SrcSpan -> Range
57srcSpanToRange :: SrcSpan -> Range
@@ -95,16 +87,12 @@ toDSeverity SevFatal = Just DsError
95
87
96-- | Produce a bag of GHC-style errors (@ErrorMessages@) from the given
88-- | Produce a bag of GHC-style errors (@ErrorMessages@) from the given
97-- (optional) locations and message strings.
89-- (optional) locations and message strings.
98−mkErrors :: DynFlags -> [(SrcSpan, String)] -> [FileDiagnostic]
90+diagFromStrings :: [(SrcSpan, String)] -> [FileDiagnostic]
99−mkErrors dflags = concatMap (uncurry $ mkError dflags)
91+diagFromStrings = concatMap (uncurry diagFromString)
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
104
92
105-- | Produce a GHC-style error from a source span and a message.
93-- | Produce a GHC-style error from a source span and a message.
106−mkErrorDoc :: DynFlags -> SrcSpan -> Out.SDoc -> [FileDiagnostic]
94+diagFromString :: SrcSpan -> String -> [FileDiagnostic]
107−mkErrorDoc dflags sp = toDiagnostics dflags . Bag.listToBag . pure . mkPlainErrMsg dflags sp
95+diagFromString sp x = [diagFromText DsError sp $ T.pack x]
108
96
109
97
110-- | Produces an "unhelpful" source span with the given string.
98-- | Produces an "unhelpful" source span with the given string.
@@ -124,8 +112,8 @@ realSpan = \case
124 UnhelpfulSpan _ -> Nothing
112 UnhelpfulSpan _ -> Nothing
125
113
126
114
127−mkErrorsGhcException :: DynFlags -> GhcException -> [FileDiagnostic]
115+diagFromGhcException :: DynFlags -> GhcException -> [FileDiagnostic]
128−mkErrorsGhcException dflags exc = mkErrors dflags [(noSpan "<Internal>", showGHCE dflags exc)]
116+diagFromGhcException dflags exc = diagFromString (noSpan "<Internal>") (showGHCE dflags exc)
129
117
130showGHCE :: DynFlags -> GhcException -> String
118showGHCE :: DynFlags -> GhcException -> String
131showGHCE dflags exc = case exc of
119showGHCE dflags exc = case exc of
src/Development/IDE/Orphans.hs → src/Development/IDE/GHC/Orphans.hsrenamed+2−2
@@ -6,13 +6,13 @@
6
6
7-- | Orphan instances for GHC.
7-- | Orphan instances for GHC.
8-- Note that the 'NFData' instances may not be law abiding.
8-- Note that the 'NFData' instances may not be law abiding.
9−module Development.IDE.Orphans() where
9+module Development.IDE.GHC.Orphans() where
10
10
11import GHC hiding (convertLit)
11import GHC hiding (convertLit)
12import GhcPlugins as GHC hiding (fst3, (<>))
12import GhcPlugins as GHC hiding (fst3, (<>))
13import qualified StringBuffer as SB
13import qualified StringBuffer as SB
14import Control.DeepSeq
14import Control.DeepSeq
15−import Development.IDE.UtilGHC
15+import Development.IDE.GHC.Util
16
16
17
17
18-- Orphan instances for types from the GHC API.
18-- 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 @@
8-- * Call runGhc, use runGhcFast instead. It's faster and doesn't require config we don't have.
8-- * Call runGhc, use runGhcFast instead. It's faster and doesn't require config we don't have.
9--
9--
10-- * Call setSessionDynFlags, use modifyDynFlags instead. It's faster and avoids loading packages.
10-- * Call setSessionDynFlags, use modifyDynFlags instead. It's faster and avoids loading packages.
11−module Development.IDE.UtilGHC(
11+module Development.IDE.GHC.Util(
12 lookupPackageConfig,
12 lookupPackageConfig,
13 modifyDynFlags,
13 modifyDynFlags,
14 fakeDynFlags,
14 fakeDynFlags,
src/Development/IDE/Functions/Warnings.hs → src/Development/IDE/GHC/Warnings.hsrenamed+8−10
@@ -1,20 +1,18 @@
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
2-- SPDX-License-Identifier: Apache-2.0
3
3
4−module Development.IDE.Functions.Warnings(withWarnings) where
4+module Development.IDE.GHC.Warnings(withWarnings) where
5
5
6−import ErrUtils
7import GhcMonad
6import GhcMonad
7+import ErrUtils
8import GhcPlugins as GHC hiding (Var)
8import GhcPlugins as GHC hiding (Var)
9
9
10−import qualified Data.Text as T
11−import Data.Maybe
12import Control.Concurrent.Extra
10import Control.Concurrent.Extra
13import Control.Monad.Extra
11import Control.Monad.Extra
14
12
15import Development.IDE.Types.Diagnostics
13import Development.IDE.Types.Diagnostics
16−import Development.IDE.UtilGHC
14+import Development.IDE.GHC.Util
17−import Development.IDE.Functions.GHCError
15+import Development.IDE.GHC.Error
18
16
19
17
20-- | Take a GHC monadic action (e.g. @typecheckModule pm@ for some
18-- | Take a GHC monadic action (e.g. @typecheckModule pm@ for some
@@ -26,18 +24,18 @@ import Development.IDE.Functions.GHCError
26-- https://github.com/ghc/ghc/blob/5f1d949ab9e09b8d95319633854b7959df06eb58/compiler/main/GHC.hs#L623-L640
24-- https://github.com/ghc/ghc/blob/5f1d949ab9e09b8d95319633854b7959df06eb58/compiler/main/GHC.hs#L623-L640
27-- which basically says that log_action is taken from the ModSummary when GHC feels like it.
25-- which basically says that log_action is taken from the ModSummary when GHC feels like it.
28-- The given argument lets you refresh a ModSummary log_action
26-- The given argument lets you refresh a ModSummary log_action
29−withWarnings :: GhcMonad m => T.Text -> ((ModSummary -> ModSummary) -> m a) -> m ([FileDiagnostic], a)
27+withWarnings :: GhcMonad m => ((ModSummary -> ModSummary) -> m a) -> m ([FileDiagnostic], a)
30−withWarnings phase action = do
28+withWarnings action = do
31 warnings <- liftIO $ newVar []
29 warnings <- liftIO $ newVar []
32 oldFlags <- getDynFlags
30 oldFlags <- getDynFlags
33 let newAction dynFlags _ _ loc _ msg = do
31 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
35 modifyVar_ warnings $ return . (d:)
33 modifyVar_ warnings $ return . (d:)
36 setLogAction newAction
34 setLogAction newAction
37 res <- action $ \x -> x{ms_hspp_opts = (ms_hspp_opts x){log_action = newAction}}
35 res <- action $ \x -> x{ms_hspp_opts = (ms_hspp_opts x){log_action = newAction}}
38 setLogAction $ log_action oldFlags
36 setLogAction $ log_action oldFlags
39 warns <- liftIO $ readVar warnings
37 warns <- liftIO $ readVar warnings
40− return (reverse $ catMaybes warns, res)
38+ return (reverse $ concat warns, res)
41
39
42setLogAction :: GhcMonad m => LogAction -> m ()
40setLogAction :: GhcMonad m => LogAction -> m ()
43setLogAction act = void $ modifyDynFlags $ \dyn -> dyn{log_action = act}
41setLogAction 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 @@
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
2-- SPDX-License-Identifier: Apache-2.0
3
3
4−module Development.IDE.Functions.DependencyInformation
4+module Development.IDE.Import.DependencyInformation
5 ( DependencyInformation(..)
5 ( DependencyInformation(..)
6 , RawDependencyInformation(..)
6 , RawDependencyInformation(..)
7 , NodeError(..)
7 , NodeError(..)
@@ -13,7 +13,7 @@ module Development.IDE.Functions.DependencyInformation
13
13
14import Control.DeepSeq
14import Control.DeepSeq
15import Data.Bifunctor
15import Data.Bifunctor
16−import Development.IDE.Orphans()
16+import Development.IDE.GHC.Orphans()
17import Data.Either
17import Data.Either
18import Data.Foldable
18import Data.Foldable
19import Data.Graph
19import Data.Graph
@@ -30,7 +30,6 @@ import GHC.Generics (Generic)
30
30
31import Development.IDE.Types.Diagnostics
31import Development.IDE.Types.Diagnostics
32import Development.IDE.Types.Location
32import Development.IDE.Types.Location
33−import Development.IDE.UtilGHC ()
34
33
35import GHC
34import GHC
36import Module
35import Module
src/Development/IDE/Functions/FindImports.hs → src/Development/IDE/Import/FindImports.hsrenamed+6−5
@@ -3,14 +3,15 @@
3
3
4{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
5
5
6−module Development.IDE.Functions.FindImports
6+module Development.IDE.Import.FindImports
7 ( getImportsParsed
7 ( getImportsParsed
8 , locateModule
8 , locateModule
9 , Import(..)
9 , Import(..)
10 ) where
10 ) where
11
11
12−import Development.IDE.Functions.GHCError as ErrUtils
12+import Development.IDE.GHC.Error as ErrUtils
13−import Development.IDE.Orphans()
13+import Development.IDE.GHC.Orphans()
14+import Development.IDE.Types.Diagnostics
14import Development.IDE.Types.Location
15import Development.IDE.Types.Location
15-- GHC imports
16-- GHC imports
16import BasicTypes (StringLiteral(..))
17import BasicTypes (StringLiteral(..))
@@ -49,7 +50,7 @@ getImportsParsed dflags (L loc parsed) = do
49 let srcImports = filter (ideclSource . GHC.unLoc) $ GHC.hsmodImports parsed
50 let srcImports = filter (ideclSource . GHC.unLoc) $ GHC.hsmodImports parsed
50 when (not $ null srcImports) $ Ex.throwE $
51 when (not $ null srcImports) $ Ex.throwE $
51 concat
52 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))
53 | L mloc i <- srcImports ]
54 | L mloc i <- srcImports ]
54
55
55 -- most of these corner cases are also present in https://hackage.haskell.org/package/ghc-8.6.1/docs/src/HeaderInfo.html#getImports
56 -- 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
107notFoundErr dfs modName reason =
108notFoundErr dfs modName reason =
108 mkError' $ ppr' $ cannotFindModule dfs modName0 $ lookupToFindResult reason
109 mkError' $ ppr' $ cannotFindModule dfs modName0 $ lookupToFindResult reason
109 where
110 where
110− mkError' = mkError dfs (getLoc modName)
111+ mkError' = diagFromString (getLoc modName)
111 modName0 = unLoc modName
112 modName0 = unLoc modName
112 ppr' = showSDoc dfs
113 ppr' = showSDoc dfs
113 -- We convert the lookup result to a find result to reuse GHC's cannotFindMoudle pretty printer.
114 -- 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
11import Development.IDE.LSP.Protocol
11import Development.IDE.LSP.Protocol
12import Development.IDE.Types.Location
12import Development.IDE.Types.Location
13
13
14−import qualified Development.IDE.Logger as Logger
14+import qualified Development.IDE.Types.Logger as Logger
15−import Development.IDE.State.Rules
15+import Development.IDE.Core.Rules
16
16
17import qualified Data.Text as T
17import qualified Data.Text as T
18import Data.Text.Prettyprint.Doc
18import Data.Text.Prettyprint.Doc
src/Development/IDE/LSP/Hover.hs+2−2
@@ -12,13 +12,13 @@ import Development.IDE.LSP.Protocol hiding (Hover)
12import Language.Haskell.LSP.Types (Hover(..))
12import Language.Haskell.LSP.Types (Hover(..))
13import Development.IDE.Types.Location
13import Development.IDE.Types.Location
14
14
15−import qualified Development.IDE.Logger as Logger
15+import qualified Development.IDE.Types.Logger as Logger
16
16
17import qualified Data.Text as T
17import qualified Data.Text as T
18import Data.Text.Prettyprint.Doc
18import Data.Text.Prettyprint.Doc
19import Data.Text.Prettyprint.Doc.Render.Text
19import Data.Text.Prettyprint.Doc.Render.Text
20
20
21−import Development.IDE.State.Rules
21+import Development.IDE.Core.Rules
22
22
23-- | Display information on hover.
23-- | Display information on hover.
24handle
24handle
src/Development/IDE/LSP/LanguageServer.hs+3−3
@@ -17,8 +17,8 @@ import Development.IDE.LSP.Server
17import Control.Monad.IO.Class
17import Control.Monad.IO.Class
18import qualified Development.IDE.LSP.Definition as LS.Definition
18import qualified Development.IDE.LSP.Definition as LS.Definition
19import qualified Development.IDE.LSP.Hover as LS.Hover
19import qualified Development.IDE.LSP.Hover as LS.Hover
20−import qualified Development.IDE.Logger as Logger
20+import qualified Development.IDE.Types.Logger as Logger
21−import Development.IDE.State.Service
21+import Development.IDE.Core.Service
22import Development.IDE.Types.Location
22import Development.IDE.Types.Location
23
23
24import qualified Data.Aeson as Aeson
24import qualified Data.Aeson as Aeson
@@ -26,7 +26,7 @@ import qualified Data.Rope.UTF16 as Rope
26import qualified Data.Set as S
26import qualified Data.Set as S
27import qualified Data.Text as T
27import qualified Data.Text as T
28
28
29−import Development.IDE.State.FileStore
29+import Development.IDE.Core.FileStore
30
30
31import qualified Network.URI as URI
31import qualified Network.URI as URI
32
32
src/Development/IDE/LSP/Server.hs+1−1
@@ -19,7 +19,7 @@ import Control.Concurrent.STM
19import Data.Default
19import Data.Default
20
20
21import Development.IDE.LSP.Protocol
21import Development.IDE.LSP.Protocol
22−import qualified Development.IDE.Logger as Logger
22+import qualified Development.IDE.Types.Logger as Logger
23
23
24import qualified Data.Aeson as Aeson
24import qualified Data.Aeson as Aeson
25import qualified Data.Aeson.Text as Aeson
25import qualified Data.Aeson.Text as Aeson
src/Development/IDE/Functions/AtPoint.hs → src/Development/IDE/Spans/AtPoint.hsrenamed+20−20
@@ -4,24 +4,22 @@
4{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
5-- | Gives information about symbols at a given point in DAML files.
5-- | Gives information about symbols at a given point in DAML files.
6-- These are all pure functions that should execute quickly.
6-- These are all pure functions that should execute quickly.
7−module Development.IDE.Functions.AtPoint (
7+module Development.IDE.Spans.AtPoint (
8 atPoint
8 atPoint
9 , gotoDefinition
9 , gotoDefinition
10 ) where
10 ) where
11
11
12−import Development.IDE.Functions.Documentation
12+import Development.IDE.Spans.Documentation
13−import Development.IDE.Functions.GHCError
13+import Development.IDE.GHC.Error
14−import Development.IDE.Orphans()
14+import Development.IDE.GHC.Orphans()
15import Development.IDE.Types.Location
15import Development.IDE.Types.Location
16
16
17-- DAML compiler and infrastructure
17-- DAML compiler and infrastructure
18import Development.Shake
18import Development.Shake
19−import Development.IDE.UtilGHC
19+import Development.IDE.GHC.Util
20−import Development.IDE.Compat
20+import Development.IDE.GHC.Compat
21−import Development.IDE.State.Shake
22−import Development.IDE.State.RuleTypes
23import Development.IDE.Types.Options
21import Development.IDE.Types.Options
24−import Development.IDE.Types.SpanInfo as SpanInfo
22+import Development.IDE.Spans.Type as SpanInfo
25
23
26-- GHC API imports
24-- GHC API imports
27import Avail
25import Avail
@@ -33,19 +31,22 @@ import Outputable hiding ((<>))
33
31
34import Control.Monad.Extra
32import Control.Monad.Extra
35import Control.Monad.Trans.Maybe
33import Control.Monad.Trans.Maybe
34+import Control.Monad.IO.Class
36import Data.Maybe
35import Data.Maybe
37import Data.List
36import Data.List
38import qualified Data.Text as T
37import qualified Data.Text as T
39
38
40-- | Locate the definition of the name at a given position.
39-- | Locate the definition of the name at a given position.
41gotoDefinition
40gotoDefinition
41+ :: MonadIO m
42+ => (FilePath -> m (Maybe HieFile))
42− :: IdeOptions
43+ -> IdeOptions
43 -> HscEnv
44 -> HscEnv
44 -> [SpanInfo]
45 -> [SpanInfo]
45 -> Position
46 -> Position
46− -> Action (Maybe Location)
47+ -> m (Maybe Location)
47−gotoDefinition ideOpts pkgState srcSpans pos =
48+gotoDefinition getHieFile ideOpts pkgState srcSpans pos =
48− listToMaybe <$> locationsAtPoint ideOpts pkgState pos srcSpans
49+ listToMaybe <$> locationsAtPoint getHieFile ideOpts pkgState pos srcSpans
49
50
50-- | Synopsis for the name at a given position.
51-- | Synopsis for the name at a given position.
51atPoint
52atPoint
@@ -59,8 +60,7 @@ atPoint IdeOptions{..} tcs srcSpans pos = do
59 ty <- spaninfoType
60 ty <- spaninfoType
60 let mbName = getNameM spaninfoSource
61 let mbName = getNameM spaninfoSource
61 mbDefinedAt = fmap (\name -> "**Defined " <> T.pack (showSDocUnsafe $ pprNameDefnLoc name) <> "**\n") mbName
62 mbDefinedAt = fmap (\name -> "**Defined " <> T.pack (showSDocUnsafe $ pprNameDefnLoc name) <> "**\n") mbName
62− mbDocs = fmap (\name -> getDocumentation name tcs) mbName
63+ docInfo = maybe [] (\name -> getDocumentation name tcs) mbName
63− docInfo = maybe [] docHeaders mbDocs
64 range = Range
64 range = Range
65 (Position spaninfoStartLine spaninfoStartCol)
65 (Position spaninfoStartLine spaninfoStartCol)
66 (Position spaninfoEndLine spaninfoEndCol)
66 (Position spaninfoEndLine spaninfoEndCol)
@@ -88,14 +88,14 @@ atPoint IdeOptions{..} tcs srcSpans pos = do
88 Just name -> any (`isInfixOf` show name) ["==", "showsPrec"]
88 Just name -> any (`isInfixOf` show name) ["==", "showsPrec"]
89 Nothing -> False
89 Nothing -> False
90
90
91−locationsAtPoint :: IdeOptions -> HscEnv -> Position -> [SpanInfo] -> Action [Location]
91+locationsAtPoint :: forall m . MonadIO m => (FilePath -> m (Maybe HieFile)) -> IdeOptions -> HscEnv -> Position -> [SpanInfo] -> m [Location]
92−locationsAtPoint IdeOptions{..} pkgState pos =
92+locationsAtPoint getHieFile IdeOptions{..} pkgState pos =
93 fmap (map srcSpanToLocation) .
93 fmap (map srcSpanToLocation) .
94 mapMaybeM (getSpan . spaninfoSource) .
94 mapMaybeM (getSpan . spaninfoSource) .
95 spansAtPoint pos
95 spansAtPoint pos
96− where getSpan :: SpanSource -> Action (Maybe SrcSpan)
96+ where getSpan :: SpanSource -> m (Maybe SrcSpan)
97 getSpan NoSource = pure Nothing
97 getSpan NoSource = pure Nothing
98− getSpan (Span sp) = pure $ Just sp
98+ getSpan (SpanS sp) = pure $ Just sp
99 getSpan (Named name) = case nameSrcSpan name of
99 getSpan (Named name) = case nameSrcSpan name of
100 sp@(RealSrcSpan _) -> pure $ Just sp
100 sp@(RealSrcSpan _) -> pure $ Just sp
101 UnhelpfulSpan _ -> runMaybeT $ do
101 UnhelpfulSpan _ -> runMaybeT $ do
@@ -106,7 +106,7 @@ locationsAtPoint IdeOptions{..} pkgState pos =
106 let unitId = moduleUnitId mod
106 let unitId = moduleUnitId mod
107 pkgConfig <- MaybeT $ pure $ lookupPackageConfig unitId pkgState
107 pkgConfig <- MaybeT $ pure $ lookupPackageConfig unitId pkgState
108 hiePath <- MaybeT $ liftIO $ optLocateHieFile optPkgLocationOpts pkgConfig mod
108 hiePath <- MaybeT $ liftIO $ optLocateHieFile optPkgLocationOpts pkgConfig mod
109− hieFile <- MaybeT $ use (GetHieFile hiePath) ""
109+ hieFile <- MaybeT $ getHieFile hiePath
110 avail <- MaybeT $ pure $ listToMaybe (filterAvails (eqName name) $ hie_exports hieFile)
110 avail <- MaybeT $ pure $ listToMaybe (filterAvails (eqName name) $ hie_exports hieFile)
111 srcPath <- MaybeT $ liftIO $ optLocateSrcFile optPkgLocationOpts pkgConfig mod
111 srcPath <- MaybeT $ liftIO $ optLocateSrcFile optPkgLocationOpts pkgConfig mod
112 -- The location will point to the source file used during compilation.
112 -- 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 @@
7
7
8-- | Get information on modules, identifiers, etc.
8-- | Get information on modules, identifiers, etc.
9
9
10−module Development.IDE.Functions.SpanInfo(getSpanInfo,listifyAllSpans) where
10+module Development.IDE.Spans.Calculate(getSpanInfo,listifyAllSpans) where
11
11
12import ConLike
12import ConLike
13import Control.Monad
13import Control.Monad
@@ -22,8 +22,8 @@ import GHC
22import GhcMonad
22import GhcMonad
23import FastString (mkFastString)
23import FastString (mkFastString)
24import Development.IDE.Types.Location
24import Development.IDE.Types.Location
25−import Development.IDE.Types.SpanInfo
25+import Development.IDE.Spans.Type
26−import Development.IDE.Functions.GHCError (zeroSpan)
26+import Development.IDE.GHC.Error (zeroSpan)
27import Prelude hiding (mod)
27import Prelude hiding (mod)
28import TcHsSyn
28import TcHsSyn
29import Var
29import Var
@@ -123,7 +123,7 @@ importInfo = mapMaybe (uncurry wrk) where
123
123
124 -- TODO make this point to the module name
124 -- TODO make this point to the module name
125 fpToSpanSource :: FilePath -> SpanSource
125 fpToSpanSource :: FilePath -> SpanSource
126− fpToSpanSource fp = Span $ RealSrcSpan $ zeroSpan $ mkFastString fp
126+ fpToSpanSource fp = SpanS $ RealSrcSpan $ zeroSpan $ mkFastString fp
127
127
128-- | Get ALL source spans in the source.
128-- | Get ALL source spans in the source.
129listifyAllSpans :: Typeable a
129listifyAllSpans :: Typeable a
src/Development/IDE/Functions/Documentation.hs → src/Development/IDE/Spans/Documentation.hsrenamed+5−5
@@ -1,9 +1,8 @@
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
2-- SPDX-License-Identifier: Apache-2.0
3
3
4−module Development.IDE.Functions.Documentation (
4+module Development.IDE.Spans.Documentation (
5 getDocumentation
5 getDocumentation
6− , docHeaders
7 ) where
6 ) where
8
7
9import Control.Monad
8import Control.Monad
@@ -11,8 +10,8 @@ import Data.List.Extra
11import qualified Data.Map as M
10import qualified Data.Map as M
12import Data.Maybe
11import Data.Maybe
13import qualified Data.Text as T
12import qualified Data.Text as T
14−import Development.IDE.Functions.GHCError
13+import Development.IDE.GHC.Error
15−import Development.IDE.Functions.SpanInfo
14+import Development.IDE.Spans.Calculate
16import FastString
15import FastString
17import GHC
16import GHC
18import SrcLoc
17import SrcLoc
@@ -21,7 +20,7 @@ import SrcLoc
21getDocumentation
20getDocumentation
22 :: Name -- ^ The name you want documentation for.
21 :: Name -- ^ The name you want documentation for.
23 -> [TypecheckedModule] -- ^ All of the possible modules it could be defined in.
22 -> [TypecheckedModule] -- ^ All of the possible modules it could be defined in.
24− -> [RealLocated AnnotationComment]
23+ -> [T.Text]
25-- This finds any documentation between the name you want
24-- This finds any documentation between the name you want
26-- documentation for and the one before it. This is only an
25-- documentation for and the one before it. This is only an
27-- approximately correct algorithm and there are easily constructed
26-- approximately correct algorithm and there are easily constructed
@@ -52,6 +51,7 @@ getDocumentation targetName tcs = fromMaybe [] $ do
52 -- Annoyingly "-- |" documentation isn't annotated with a location,
51 -- Annoyingly "-- |" documentation isn't annotated with a location,
53 -- so you have to pull it out from the elements.
52 -- so you have to pull it out from the elements.
54 pure
53 pure
54+ $ docHeaders
55 $ filter (\(L target _) -> isBetween target prevNameSpan targetNameSpan)
55 $ filter (\(L target _) -> isBetween target prevNameSpan targetNameSpan)
56 $ mapMaybe (\(L l v) -> L <$> realSpan l <*> pure v)
56 $ mapMaybe (\(L l v) -> L <$> realSpan l <*> pure v)
57 $ join
57 $ join
src/Development/IDE/Types/SpanInfo.hs → src/Development/IDE/Spans/Type.hsrenamed+3−3
@@ -5,7 +5,7 @@
5
5
6-- | Types used separate to GHCi vanilla.
6-- | Types used separate to GHCi vanilla.
7
7
8−module Development.IDE.Types.SpanInfo(
8+module Development.IDE.Spans.Type(
9 SpanInfo(..)
9 SpanInfo(..)
10 , SpanSource(..)
10 , SpanSource(..)
11 , getNameM
11 , getNameM
@@ -40,14 +40,14 @@ instance Show SpanInfo where
40
40
41-- we don't always get a name out so sometimes manually annotating source is more appropriate
41-- we don't always get a name out so sometimes manually annotating source is more appropriate
42data SpanSource = Named Name
42data SpanSource = Named Name
43− | Span SrcSpan
43+ | SpanS SrcSpan
44 | NoSource
44 | NoSource
45 deriving (Eq)
45 deriving (Eq)
46
46
47instance Show SpanSource where
47instance Show SpanSource where
48 show = \case
48 show = \case
49 Named n -> "Named " ++ occNameString (occName n)
49 Named n -> "Named " ++ occNameString (occName n)
50− Span sp -> "Span " ++ show sp
50+ SpanS sp -> "Span " ++ show sp
51 NoSource -> "NoSource"
51 NoSource -> "NoSource"
52
52
53getNameM :: SpanSource -> Maybe Name
53getNameM :: SpanSource -> Maybe Name
src/Development/IDE/Types/Diagnostics.hs+1−3
@@ -1,10 +1,8 @@
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
2-- SPDX-License-Identifier: Apache-2.0
3
3
4−{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
6−{-# LANGUAGE DuplicateRecordFields #-}
5+
7−{-# LANGUAGE BlockArguments #-}
8module Development.IDE.Types.Diagnostics (
6module Development.IDE.Types.Diagnostics (
9 LSP.Diagnostic(..),
7 LSP.Diagnostic(..),
10 FileDiagnostic,
8 FileDiagnostic,
src/Development/IDE/Logger.hs → src/Development/IDE/Types/Logger.hsrenamed+1−1
@@ -5,7 +5,7 @@
5-- | This is a compatibility module that abstracts over the
5-- | This is a compatibility module that abstracts over the
6-- concrete choice of logging framework so users can plug in whatever
6-- concrete choice of logging framework so users can plug in whatever
7-- framework they want to.
7-- framework they want to.
8−module Development.IDE.Logger
8+module Development.IDE.Types.Logger
9 ( Handle(..)
9 ( Handle(..)
10 , makeOneHandle
10 , makeOneHandle
11 , makeNopHandle
11 , makeNopHandle
test/Demo.hs+6−6
@@ -7,17 +7,17 @@ import Data.Maybe
7import Control.Concurrent.Extra
7import Control.Concurrent.Extra
8import Control.Monad
8import Control.Monad
9import System.Time.Extra
9import System.Time.Extra
10−import Development.IDE.State.FileStore
10+import Development.IDE.Core.FileStore
11−import Development.IDE.State.Service
11+import Development.IDE.Core.Service
12−import Development.IDE.State.Rules
12+import Development.IDE.Core.Rules
13−import Development.IDE.State.Shake
13+import Development.IDE.Core.Shake
14−import Development.IDE.State.RuleTypes
14+import Development.IDE.Core.RuleTypes
15import Development.IDE.LSP.Protocol
15import Development.IDE.LSP.Protocol
16import Development.IDE.Types.Location
16import Development.IDE.Types.Location
17import Data.String
17import Data.String
18import Development.IDE.Types.Diagnostics
18import Development.IDE.Types.Diagnostics
19import Development.IDE.Types.Options
19import Development.IDE.Types.Options
20−import Development.IDE.Logger
20+import Development.IDE.Types.Logger
21import qualified Data.Text.IO as T
21import qualified Data.Text.IO as T
22import Language.Haskell.LSP.Messages
22import Language.Haskell.LSP.Messages
23import Development.IDE.LSP.LanguageServer
23import Development.IDE.LSP.LanguageServer