Skip to content

Skip parsing without haddock for above GHC9.0 #2338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
71 changes: 38 additions & 33 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,38 +213,41 @@ getParsedModuleRule =
opt <- getIdeOptions
modify_dflags <- getModifyDynFlags dynFlagsModifyParser
let ms = ms' { ms_hspp_opts = modify_dflags $ ms_hspp_opts ms' }

let dflags = ms_hspp_opts ms
mainParse = getParsedModuleDefinition hsc opt file ms
reset_ms pm = pm { pm_mod_summary = ms' }

-- Parse again (if necessary) to capture Haddock parse errors
res@(_,pmod) <- if gopt Opt_Haddock dflags
then
liftIO $ (fmap.fmap.fmap) reset_ms mainParse
else do
let haddockParse = getParsedModuleDefinition hsc opt file (withOptHaddock ms)

-- parse twice, with and without Haddocks, concurrently
-- we cannot ignore Haddock parse errors because files of
-- non-interest are always parsed with Haddocks
-- If we can parse Haddocks, might as well use them
--
-- HLINT INTEGRATION: might need to save the other parsed module too
((diags,res),(diagsh,resh)) <- liftIO $ (fmap.fmap.fmap.fmap) reset_ms $ concurrently mainParse haddockParse

-- Merge haddock and regular diagnostics so we can always report haddock
-- parse errors
let diagsM = mergeParseErrorsHaddock diags diagsh
case resh of
Just _
| HaddockParse <- optHaddockParse opt
-> pure (diagsM, resh)
-- If we fail to parse haddocks, report the haddock diagnostics as well and
-- return the non-haddock parse.
-- This seems to be the correct behaviour because the Haddock flag is added
-- by us and not the user, so our IDE shouldn't stop working because of it.
_ -> pure (diagsM, res)
-- We still parse with Haddocks whether Opt_Haddock is True or False to collect information
-- but we no longer need to parse with and without Haddocks separately for above GHC90.
res@(_,pmod) <- if Compat.ghcVersion >= Compat.GHC90 then
liftIO $ (fmap.fmap.fmap) reset_ms $ getParsedModuleDefinition hsc opt file (withOptHaddock ms)
Comment on lines +220 to +221
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed my code to collect haddock information even if Opt_Haddock returns False.
It seems to do so for display haddock information in the hover as the failed test suites indicated.
(for question 1)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, with GHC >9.0 we want to parse with Opt_Haddock on always

else do
let dflags = ms_hspp_opts ms
mainParse = getParsedModuleDefinition hsc opt file ms

-- Parse again (if necessary) to capture Haddock parse errors
if gopt Opt_Haddock dflags
then
liftIO $ (fmap.fmap.fmap) reset_ms mainParse
else do
let haddockParse = getParsedModuleDefinition hsc opt file (withOptHaddock ms)

-- parse twice, with and without Haddocks, concurrently
-- we cannot ignore Haddock parse errors because files of
-- non-interest are always parsed with Haddocks
-- If we can parse Haddocks, might as well use them
((diags,res),(diagsh,resh)) <- liftIO $ (fmap.fmap.fmap.fmap) reset_ms $ concurrently mainParse haddockParse

-- Merge haddock and regular diagnostics so we can always report haddock
-- parse errors
let diagsM = mergeParseErrorsHaddock diags diagsh
case resh of
Just _
| HaddockParse <- optHaddockParse opt
-> pure (diagsM, resh)
-- If we fail to parse haddocks, report the haddock diagnostics as well and
-- return the non-haddock parse.
-- This seems to be the correct behaviour because the Haddock flag is added
-- by us and not the user, so our IDE shouldn't stop working because of it.
_ -> pure (diagsM, res)
-- Add dependencies on included files
_ <- uses GetModificationTime $ map toNormalizedFilePath' (maybe [] pm_extra_src_files pmod)
pure res
Expand Down Expand Up @@ -896,9 +899,11 @@ regenerateHiFile sess f ms compNeeded = do

-- Embed haddocks in the interface file
(diags, mb_pm) <- liftIO $ getParsedModuleDefinition hsc opt f (withOptHaddock ms)
(diags, mb_pm) <- case mb_pm of
Just _ -> return (diags, mb_pm)
Nothing -> do
(diags, mb_pm) <-
-- We no longer need to parse again if GHC version is above 9.0. https://github.com/haskell/haskell-language-server/issues/1892
if Compat.ghcVersion >= Compat.GHC90 || isJust mb_pm then do
return (diags, mb_pm)
else do
-- if parsing fails, try parsing again with Haddock turned off
(diagsNoHaddock, mb_pm) <- liftIO $ getParsedModuleDefinition hsc opt f ms
return (mergeParseErrorsHaddock diagsNoHaddock diags, mb_pm)
Expand Down