Skip to content

Commit fcd0ef7

Browse files
committed
WIP: THIS SHOLUD NOT BE MERGED
This work is based on these two commits which should either be merged before this is merged, or it should be rebased.
2 parents 8afa778 + 2606976 commit fcd0ef7

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

ghcide-test/exe/FindDefinitionAndHoverTests.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ tests = let
187187
holeL65 = Position 65 8 ; hleInfo2 = [ExpectHoverText ["_ :: a -> Maybe a"]]
188188
cccL17 = Position 17 16 ; docLink = [ExpectHoverTextRegex "\\*Defined in 'GHC.Types'\\* \\*\\(ghc-prim-[0-9.]+\\)\\*\n\n"]
189189
imported = Position 56 13 ; importedSig = getDocUri "Foo.hs" >>= \foo -> return [ExpectHoverText ["foo", "Foo", "Haddock"], mkL foo 5 0 5 3]
190-
reexported = Position 55 14 ; reexportedSig = getDocUri "Bar.hs" >>= \bar -> return [ExpectHoverText ["Bar", "Bar", "Haddock"], if ghcVersion >= GHC94 && ghcVersion < GHC910 then mkL bar 3 5 3 8 else mkL bar 3 0 3 14]
190+
reexported = Position 55 14
191+
reexportedSig = getDocUri "Bar.hs" >>= \bar -> return [ExpectHoverText ["Bar", "Bar", "Haddock"], if ghcVersion >= GHC94 && ghcVersion < GHC910 || not isWindows then mkL bar 3 5 3 8 else mkL bar 3 0 3 14]
191192
thLocL57 = Position 59 10 ; thLoc = [ExpectHoverText ["Identity"]]
192193
cmtL68 = Position 67 0 ; lackOfdEq = [ExpectHoverExcludeText ["$dEq"]]
193194
import310 = Position 3 10; pkgTxt = [ExpectHoverText ["Data.Text\n\ntext-"]]
@@ -237,9 +238,9 @@ tests = let
237238
, testM yes yes imported importedSig "Imported symbol"
238239
, if isWindows then
239240
-- Flaky on Windows: https://github.com/haskell/haskell-language-server/issues/2997
240-
testM no yes reexported reexportedSig "Imported symbol (reexported)"
241+
testM no yes reexported reexportedSig "Imported symbol reexported"
241242
else
242-
testM yes yes reexported reexportedSig "Imported symbol (reexported)"
243+
testM yes yes reexported reexportedSig "Imported symbol reexported"
243244
, test no yes thLocL57 thLoc "TH Splice Hover"
244245
, test yes yes import310 pkgTxt "show package name and its version"
245246
]

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
11131114
setOptions :: 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 =
11901193
disableOptimisation :: DynFlags -> DynFlags
11911194
disableOptimisation 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+
11931204
setHiDir :: FilePath -> DynFlags -> DynFlags
11941205
setHiDir f d =
11951206
-- override user settings to avoid conflicts leading to recompilation

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ import System.Info.Extra (isWindows)
174174
import qualified Data.IntMap as IM
175175
import GHC.Fingerprint
176176

177-
import GHC.Driver.Env (hsc_all_home_unit_ids)
178-
179177
data Log
180178
= LogShake Shake.Log
181179
| LogReindexingHieFile !NormalizedFilePath
@@ -262,12 +260,10 @@ getParsedModuleRule recorder =
262260
let ms = ms' { ms_hspp_opts = modify_dflags $ ms_hspp_opts ms' }
263261
reset_ms pm = pm { pm_mod_summary = ms' }
264262

265-
-- We still parse with Haddocks whether Opt_Haddock is True or False to collect information
266-
-- but we no longer need to parse with and without Haddocks separately for above GHC90.
267-
liftIO $ (fmap.fmap.fmap) reset_ms $ getParsedModuleDefinition hsc opt file (withOptHaddock ms)
263+
liftIO $ (fmap.fmap.fmap) reset_ms $ getParsedModuleDefinition hsc opt file ms
268264

269-
withOptHaddock :: ModSummary -> ModSummary
270-
withOptHaddock = withOption Opt_Haddock
265+
withoutOptHaddock :: ModSummary -> ModSummary
266+
withoutOptHaddock = withoutOption Opt_Haddock
271267

272268
withOption :: GeneralFlag -> ModSummary -> ModSummary
273269
withOption opt ms = ms{ms_hspp_opts= gopt_set (ms_hspp_opts ms) opt}
@@ -286,7 +282,7 @@ getParsedModuleWithCommentsRule recorder =
286282
ModSummaryResult{msrModSummary = ms, msrHscEnv = hsc} <- use_ GetModSummary file
287283
opt <- getIdeOptions
288284

289-
let ms' = withoutOption Opt_Haddock $ withOption Opt_KeepRawTokenStream ms
285+
let ms' = withoutOptHaddock $ withOption Opt_KeepRawTokenStream ms
290286
modify_dflags <- getModifyDynFlags dynFlagsModifyParser
291287
let ms'' = ms' { ms_hspp_opts = modify_dflags $ ms_hspp_opts ms' }
292288
reset_ms pm = pm { pm_mod_summary = ms' }
@@ -981,7 +977,7 @@ regenerateHiFile sess f ms compNeeded = do
981977
opt <- getIdeOptions
982978

983979
-- Embed haddocks in the interface file
984-
(diags, mb_pm) <- liftIO $ getParsedModuleDefinition hsc opt f (withOptHaddock ms)
980+
(diags, mb_pm) <- liftIO $ getParsedModuleDefinition hsc opt f ms
985981
case mb_pm of
986982
Nothing -> return (diags, Nothing)
987983
Just pm -> do

ghcide/src/Development/IDE/Types/Options.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ data IdeOptions = IdeOptions
6969
-- ^ When to typecheck reverse dependencies of a file
7070
, optHaddockParse :: OptHaddockParse
7171
-- ^ Whether to return result of parsing module with Opt_Haddock.
72-
-- Otherwise, return the result of parsing without Opt_Haddock, so
73-
-- that the parsed module contains the result of Opt_KeepRawTokenStream,
74-
-- which might be necessary for hlint.
72+
-- Otherwise, return the result of parsing without Opt_Haddock.
7573
, optModifyDynFlags :: Config -> DynFlagsModifications
7674
-- ^ Will be called right after setting up a new cradle,
7775
-- allowing to customize the Ghc options used

0 commit comments

Comments
 (0)