@@ -451,6 +451,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
451451 IdeOptions { optTesting = IdeTesting optTesting
452452 , optCheckProject = getCheckProject
453453 , optExtensions
454+ , optHaddockParse
454455 } <- getIdeOptions
455456
456457 -- populate the knownTargetsVar with all the
@@ -495,7 +496,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
495496 packageSetup (hieYaml, cfp, opts, libDir) = do
496497 -- Parse DynFlags for the newly discovered component
497498 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
499500 let deps = componentDependencies opts ++ maybeToList hieYaml
500501 dep_info <- getDependencyInfo deps
501502 -- Now lookup to see whether we are combining with an existing HscEnv
@@ -1111,12 +1112,13 @@ addUnit unit_str = liftEwM $ do
11111112
11121113-- | Throws if package flags are unsatisfiable
11131114setOptions :: GhcMonad m
1114- => NormalizedFilePath
1115+ => OptHaddockParse
1116+ -> NormalizedFilePath
11151117 -> ComponentOptions
11161118 -> DynFlags
11171119 -> FilePath -- ^ root dir, see Note [Root Directory]
11181120 -> m (NonEmpty (DynFlags , [GHC. Target ]))
1119- setOptions cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
1121+ setOptions haddockOpt cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
11201122 ((theOpts',_errs,_warns),units) <- processCmdLineP unit_flags [] (map noLoc theOpts)
11211123 case NE. nonEmpty units of
11221124 Just us -> initMulti us
@@ -1177,6 +1179,7 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
11771179 dontWriteHieFiles $
11781180 setIgnoreInterfacePragmas $
11791181 setBytecodeLinkerOptions $
1182+ enableOptHaddock haddockOpt $
11801183 disableOptimisation $
11811184 Compat. setUpTypedHoles $
11821185 makeDynFlagsAbsolute compRoot -- makeDynFlagsAbsolute already accounts for workingDirectory
@@ -1190,6 +1193,14 @@ setIgnoreInterfacePragmas df =
11901193disableOptimisation :: DynFlags -> DynFlags
11911194disableOptimisation df = updOptLevel 0 df
11921195
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+
11931204setHiDir :: FilePath -> DynFlags -> DynFlags
11941205setHiDir f d =
11951206 -- override user settings to avoid conflicts leading to recompilation
0 commit comments