Skip to content

Commit 7ab7989

Browse files
committed
Add support for the multi unit argument syntax introduced in GHC 9.4: https://downloads.haskell.org/ghc/9.4.4/docs/users_guide/using.html#multiple-home-units
We now support arguments of the form ``` -unit @unitA -unit @unitb ``` where the response files `unitA` and `unitB` contain the actual list of arguments for that unit: ``` -this-unit-id a-0.1.0.0 -i -isrc A1 A2 ``` Also refactor the session loader and simplify it. Also adds error messages on GHC 9.4 if the units are not closed (#3422).
1 parent ddc67b2 commit 7ab7989

File tree

13 files changed

+276
-118
lines changed

13 files changed

+276
-118
lines changed

ghcide/ghcide.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ library
165165
Development.IDE.Core.UseStale
166166
Development.IDE.GHC.Compat
167167
Development.IDE.GHC.Compat.Core
168+
Development.IDE.GHC.Compat.CmdLine
168169
Development.IDE.GHC.Compat.Env
169170
Development.IDE.GHC.Compat.Iface
170171
Development.IDE.GHC.Compat.Logger

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 173 additions & 115 deletions
Large diffs are not rendered by default.

ghcide/src/Development/IDE/GHC/Compat/Env.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module Development.IDE.GHC.Compat.Env (
5151
Backend,
5252
setBackend,
5353
Development.IDE.GHC.Compat.Env.platformDefaultBackend,
54+
workingDirectory
5455
) where
5556

5657
import GHC (setInteractiveDynFlags)
@@ -105,6 +106,11 @@ hsc_EPS :: HscEnv -> UnitEnv
105106
hsc_EPS = hsc_unit_env
106107
#endif
107108

109+
#if !MIN_VERSION_ghc(9,3,0)
110+
workingDirectory :: a -> Maybe b
111+
workingDirectory _ = Nothing
112+
#endif
113+
108114
#if !MIN_VERSION_ghc(9,2,0)
109115
type UnitEnv = ()
110116
newtype Logger = Logger { log_action :: LogAction }

ghcide/src/Development/IDE/GHC/Compat/Units.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
module Development.IDE.GHC.Compat.Units (
66
-- * UnitState
77
UnitState,
8-
#if MIN_VERSION_ghc(9,3,0)
98
initUnits,
10-
#endif
119
oldInitUnits,
1210
unitState,
1311
getUnitName,
@@ -179,8 +177,12 @@ initUnits unitDflags env = do
179177
, ue_eps = ue_eps (hsc_unit_env env)
180178
}
181179
pure $ hscSetFlags dflags1 $ hscSetUnitEnv unit_env env
180+
#else
181+
initUnits :: [DynFlags] -> HscEnv -> IO HscEnv
182+
initUnits _df env = pure env -- Can't do anything here, oldInitUnits should already be called
182183
#endif
183184

185+
184186
-- | oldInitUnits only needs to modify DynFlags for GHC <9.2
185187
-- For GHC >= 9.2, we need to set the hsc_unit_env also, that is
186188
-- done later by initUnits
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-this-package-name
2+
a
3+
-working-dir
4+
a
5+
-fbuilding-cabal-package
6+
-O0
7+
-i.
8+
-this-unit-id
9+
a-1.0.0-inplace
10+
-hide-all-packages
11+
-Wmissing-home-modules
12+
-no-user-package-db
13+
-package
14+
base
15+
-package
16+
text
17+
-XHaskell98
18+
A

ghcide/test/data/multi-unit/a/A.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module A(foo) where
2+
import Data.Text
3+
foo = ()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-this-package-name
2+
b
3+
-working-dir
4+
b
5+
-fbuilding-cabal-package
6+
-O0
7+
-i
8+
-i.
9+
-this-unit-id
10+
b-1.0.0-inplace
11+
-hide-all-packages
12+
-Wmissing-home-modules
13+
-no-user-package-db
14+
-package-id
15+
a-1.0.0-inplace
16+
-package
17+
base
18+
-XHaskell98
19+
B

ghcide/test/data/multi-unit/b/B.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module B(module B) where
2+
import A
3+
qux = foo
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-this-package-name
2+
c
3+
-working-dir
4+
c
5+
-fbuilding-cabal-package
6+
-O0
7+
-i
8+
-i.
9+
-this-unit-id
10+
c-1.0.0-inplace
11+
-hide-all-packages
12+
-Wmissing-home-modules
13+
-no-user-package-db
14+
-package-id
15+
a-1.0.0-inplace
16+
-package
17+
base
18+
-XHaskell98
19+
C

ghcide/test/data/multi-unit/c/C.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module C(module C) where
2+
import A
3+
cux = foo

0 commit comments

Comments
 (0)