Skip to content

Commit a05d1c6

Browse files
yoshitsugupepeiborraalexnaspojneira
committed
Skip parsing without haddock for above GHC9.0 (#2338)
* Skip parsing without haddock for above GHC9.0 * Use runtime ghc version check * Need parse twice in getParsedModuleRule * Include sortText in completions and improve suggestions (#2332) * sort completions * add an example * Include fuzzy scores in completions sort text * hlints * Extend completion documentation to inform whether an identifier is alreaady imported * Ditch alphabetical ordering - it's incompatible with qualified completions * Fix bugs in completion help text This fixes the ugly "Imported from 'Just B'" and other inconsistencies * added tests for qualified completions * Fix redundant import * Inline Fuzzy.match to apply [1] and to be case-sensitive on first match [1] - joom/fuzzy#4 * fixup! Fix bugs in completion help text * Sort qualified completions first * Filter out global suggestions that overlap with local For example, don't suggest GHC.Exts.fromList when Data.Map.fromList is in scope alraedy * Sort completions alphabetically * Show provenance in detail text * Sort local/in-scope completions first * Fix build with GHC 9 * Ignore func symbol tests Co-authored-by: Alex Naspo <[email protected]> Co-authored-by: Javier Neira <[email protected]> * Give unique names to post-jobs (#2337) * Restore comment * Parse only with Haddock above GHC90 * Remove obsolete comment Co-authored-by: Pepe Iborra <[email protected]> Co-authored-by: Alex Naspo <[email protected]> Co-authored-by: Javier Neira <[email protected]>
1 parent 2de4bed commit a05d1c6

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

Diff for: ghcide/src/Development/IDE/Core/Rules.hs

+38-33
Original file line numberDiff line numberDiff line change
@@ -213,38 +213,41 @@ getParsedModuleRule =
213213
opt <- getIdeOptions
214214
modify_dflags <- getModifyDynFlags dynFlagsModifyParser
215215
let ms = ms' { ms_hspp_opts = modify_dflags $ ms_hspp_opts ms' }
216-
217-
let dflags = ms_hspp_opts ms
218-
mainParse = getParsedModuleDefinition hsc opt file ms
219216
reset_ms pm = pm { pm_mod_summary = ms' }
220217

221-
-- Parse again (if necessary) to capture Haddock parse errors
222-
res@(_,pmod) <- if gopt Opt_Haddock dflags
223-
then
224-
liftIO $ (fmap.fmap.fmap) reset_ms mainParse
225-
else do
226-
let haddockParse = getParsedModuleDefinition hsc opt file (withOptHaddock ms)
227-
228-
-- parse twice, with and without Haddocks, concurrently
229-
-- we cannot ignore Haddock parse errors because files of
230-
-- non-interest are always parsed with Haddocks
231-
-- If we can parse Haddocks, might as well use them
232-
--
233-
-- HLINT INTEGRATION: might need to save the other parsed module too
234-
((diags,res),(diagsh,resh)) <- liftIO $ (fmap.fmap.fmap.fmap) reset_ms $ concurrently mainParse haddockParse
235-
236-
-- Merge haddock and regular diagnostics so we can always report haddock
237-
-- parse errors
238-
let diagsM = mergeParseErrorsHaddock diags diagsh
239-
case resh of
240-
Just _
241-
| HaddockParse <- optHaddockParse opt
242-
-> pure (diagsM, resh)
243-
-- If we fail to parse haddocks, report the haddock diagnostics as well and
244-
-- return the non-haddock parse.
245-
-- This seems to be the correct behaviour because the Haddock flag is added
246-
-- by us and not the user, so our IDE shouldn't stop working because of it.
247-
_ -> pure (diagsM, res)
218+
-- We still parse with Haddocks whether Opt_Haddock is True or False to collect information
219+
-- but we no longer need to parse with and without Haddocks separately for above GHC90.
220+
res@(_,pmod) <- if Compat.ghcVersion >= Compat.GHC90 then
221+
liftIO $ (fmap.fmap.fmap) reset_ms $ getParsedModuleDefinition hsc opt file (withOptHaddock ms)
222+
else do
223+
let dflags = ms_hspp_opts ms
224+
mainParse = getParsedModuleDefinition hsc opt file ms
225+
226+
-- Parse again (if necessary) to capture Haddock parse errors
227+
if gopt Opt_Haddock dflags
228+
then
229+
liftIO $ (fmap.fmap.fmap) reset_ms mainParse
230+
else do
231+
let haddockParse = getParsedModuleDefinition hsc opt file (withOptHaddock ms)
232+
233+
-- parse twice, with and without Haddocks, concurrently
234+
-- we cannot ignore Haddock parse errors because files of
235+
-- non-interest are always parsed with Haddocks
236+
-- If we can parse Haddocks, might as well use them
237+
((diags,res),(diagsh,resh)) <- liftIO $ (fmap.fmap.fmap.fmap) reset_ms $ concurrently mainParse haddockParse
238+
239+
-- Merge haddock and regular diagnostics so we can always report haddock
240+
-- parse errors
241+
let diagsM = mergeParseErrorsHaddock diags diagsh
242+
case resh of
243+
Just _
244+
| HaddockParse <- optHaddockParse opt
245+
-> pure (diagsM, resh)
246+
-- If we fail to parse haddocks, report the haddock diagnostics as well and
247+
-- return the non-haddock parse.
248+
-- This seems to be the correct behaviour because the Haddock flag is added
249+
-- by us and not the user, so our IDE shouldn't stop working because of it.
250+
_ -> pure (diagsM, res)
248251
-- Add dependencies on included files
249252
_ <- uses GetModificationTime $ map toNormalizedFilePath' (maybe [] pm_extra_src_files pmod)
250253
pure res
@@ -896,9 +899,11 @@ regenerateHiFile sess f ms compNeeded = do
896899

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

0 commit comments

Comments
 (0)