Skip to content

Commit 990428f

Browse files
committed
ghcide: Pass -fmax-valid-hole-fits=10 to GHC
In cases where GHC doesn't know anything about the type of a hole, it suggests every available symbol as a hole fit, which can cause editors to crash or at least be very slow. 10 seems to be a fair number to limit hole fits to.
1 parent 7563439 commit 990428f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ghcide/src/Development/IDE/GHC/Compat.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ import Compat.HieTypes hiding
133133
(nodeAnnotations)
134134
import qualified Compat.HieTypes as GHC (nodeAnnotations)
135135
import Compat.HieUtils
136+
import Control.Applicative ((<|>))
136137
import qualified Data.ByteString as BS
137138
import Data.Coerce (coerce)
138139
import Data.List (foldl')
@@ -434,7 +435,7 @@ setHieDir _f d = d { hieDir = Just _f}
434435
dontWriteHieFiles :: DynFlags -> DynFlags
435436
dontWriteHieFiles d = gopt_unset d Opt_WriteHie
436437

437-
setUpTypedHoles ::DynFlags -> DynFlags
438+
setUpTypedHoles :: DynFlags -> DynFlags
438439
setUpTypedHoles df
439440
= flip gopt_unset Opt_AbstractRefHoleFits -- too spammy
440441
$ flip gopt_unset Opt_ShowDocsOfHoleFits -- not used
@@ -447,9 +448,13 @@ setUpTypedHoles df
447448
$ flip gopt_unset Opt_SortValidHoleFits
448449
$ flip gopt_unset Opt_UnclutterValidHoleFits
449450
$ df
450-
{ refLevelHoleFits = Just 1 -- becomes slow at higher levels
451-
, maxRefHoleFits = Just 10 -- quantity does not impact speed
452-
, maxValidHoleFits = Nothing -- quantity does not impact speed
451+
{ refLevelHoleFits = refLevelHoleFits df <|> Just 1 -- becomes slow at higher levels
452+
453+
-- Sometimes GHC can emit a lot of hole fits, this causes editors to be slow
454+
-- or just crash, we limit the hole fits to 10. The number was chosen
455+
-- arbirtarily by the author.
456+
, maxRefHoleFits = maxRefHoleFits df <|> Just 10
457+
, maxValidHoleFits = maxValidHoleFits df <|> Just 10
453458
}
454459

455460

0 commit comments

Comments
 (0)