Skip to content

Commit

Permalink
Skip parsing without haddock for above GHC9.0 (#2338)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Nov 15, 2021
1 parent 1eb133f commit 4e2a99e
Showing 1 changed file with 38 additions and 33 deletions.
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)
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

0 comments on commit 4e2a99e

Please sign in to comment.