Skip to content

Commit

Permalink
Do not suggest any hole filling if there are too many suggestions
Browse files Browse the repository at this point in the history
Perhaps it would be possible to use the type of the hole to make a
better limiter here, but this is better than the current situation I
think.

Closes haskell/haskell-language-server#532
  • Loading branch information
expipiplus1 committed Oct 28, 2020
1 parent 933c0c9 commit 907c455
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Development/IDE/Plugin/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,23 @@ suggestFillHole :: Diagnostic -> [(T.Text, [TextEdit])]
suggestFillHole Diagnostic{_range=_range,..}
| Just holeName <- extractHoleName _message
, (holeFits, refFits) <- processHoleSuggestions (T.lines _message)
= map (proposeHoleFit holeName False) holeFits
++ map (proposeHoleFit holeName True) refFits
= let candidates = map (proposeHoleFit holeName False) holeFits
++ map (proposeHoleFit holeName True) refFits
in if length candidates > numberOfHolesLimit
then []
else candidates
| otherwise = []
where
extractHoleName = fmap head . flip matchRegexUnifySpaces "Found hole: ([^ ]*)"
proposeHoleFit holeName parenthise name =
( "replace " <> holeName <> " with " <> name
, [TextEdit _range $ if parenthise then parens name else name])
parens x = "(" <> x <> ")"
-- If there are more than this many holes, don't return any as they're
-- not likely to be specific enought to be useful
-- See https://github.com/haskell/haskell-language-server/issues/532
-- 5 chosen arbitrarily
numberOfHolesLimit = 5

processHoleSuggestions :: [T.Text] -> ([T.Text], [T.Text])
processHoleSuggestions mm = (holeSuggestions, refSuggestions)
Expand Down

0 comments on commit 907c455

Please sign in to comment.