Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Do not suggest any hole filling if there are too many suggestions #888

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

5 seems a bit low. I would go for something like 15. Can we make it user configurable?

Copy link
Author

Choose a reason for hiding this comment

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

If it can be configured by ghc flags, then perhaps this is better left to cabal.project.local or something.

Copy link
Member

Choose a reason for hiding this comment

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

But your limit, the one pepe asked for, is now different from the ghc flag, no?
You can set 100 in the flag but you will not show suggestions if they are greater than 5.

Copy link
Author

Choose a reason for hiding this comment

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

oh sure, it's slightly different; tbh I'd be happy with either

Copy link
Author

@expipiplus1 expipiplus1 Oct 29, 2020

Choose a reason for hiding this comment

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

I selected 5, because if the selection isn't instant, i.e. at a glance, then I'd be better off just typing what I want (I could certainly be blind to other's preferences or use-cases here!). Tbf I have absolutely no UX research behind this!

This site suggests that the "Total Number of words made out of [a] Glance = 50"!!!


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