@@ -451,6 +451,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
451
451
IdeOptions { optTesting = IdeTesting optTesting
452
452
, optCheckProject = getCheckProject
453
453
, optExtensions
454
+ , optHaddockParse
454
455
} <- getIdeOptions
455
456
456
457
-- populate the knownTargetsVar with all the
@@ -495,7 +496,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
495
496
packageSetup (hieYaml, cfp, opts, libDir) = do
496
497
-- Parse DynFlags for the newly discovered component
497
498
hscEnv <- emptyHscEnv ideNc libDir
498
- newTargetDfs <- evalGhcEnv hscEnv $ setOptions cfp opts (hsc_dflags hscEnv) rootDir
499
+ newTargetDfs <- evalGhcEnv hscEnv $ setOptions optHaddockParse cfp opts (hsc_dflags hscEnv) rootDir
499
500
let deps = componentDependencies opts ++ maybeToList hieYaml
500
501
dep_info <- getDependencyInfo deps
501
502
-- Now lookup to see whether we are combining with an existing HscEnv
@@ -1111,12 +1112,13 @@ addUnit unit_str = liftEwM $ do
1111
1112
1112
1113
-- | Throws if package flags are unsatisfiable
1113
1114
setOptions :: GhcMonad m
1114
- => NormalizedFilePath
1115
+ => OptHaddockParse
1116
+ -> NormalizedFilePath
1115
1117
-> ComponentOptions
1116
1118
-> DynFlags
1117
1119
-> FilePath -- ^ root dir, see Note [Root Directory]
1118
1120
-> m (NonEmpty (DynFlags , [GHC. Target ]))
1119
- setOptions cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
1121
+ setOptions haddockOpt cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
1120
1122
((theOpts',_errs,_warns),units) <- processCmdLineP unit_flags [] (map noLoc theOpts)
1121
1123
case NE. nonEmpty units of
1122
1124
Just us -> initMulti us
@@ -1177,6 +1179,7 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
1177
1179
dontWriteHieFiles $
1178
1180
setIgnoreInterfacePragmas $
1179
1181
setBytecodeLinkerOptions $
1182
+ enableOptHaddock haddockOpt $
1180
1183
disableOptimisation $
1181
1184
Compat. setUpTypedHoles $
1182
1185
makeDynFlagsAbsolute compRoot -- makeDynFlagsAbsolute already accounts for workingDirectory
@@ -1190,6 +1193,14 @@ setIgnoreInterfacePragmas df =
1190
1193
disableOptimisation :: DynFlags -> DynFlags
1191
1194
disableOptimisation df = updOptLevel 0 df
1192
1195
1196
+ -- | We always compile with '-haddock' unless explicitly disabled.
1197
+ --
1198
+ -- This avoids inconsistencies when doing recompilation checking which was
1199
+ -- observed in https://github.com/haskell/haskell-language-server/issues/4511
1200
+ enableOptHaddock :: OptHaddockParse -> DynFlags -> DynFlags
1201
+ enableOptHaddock HaddockParse d = gopt_set d Opt_Haddock
1202
+ enableOptHaddock NoHaddockParse d = d
1203
+
1193
1204
setHiDir :: FilePath -> DynFlags -> DynFlags
1194
1205
setHiDir f d =
1195
1206
-- override user settings to avoid conflicts leading to recompilation
0 commit comments