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

Conversation

expipiplus1
Copy link

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

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
@jneira
Copy link
Member

jneira commented Oct 28, 2020

I wonder if we could detect in some way the type is ambiguous, or if there is a bigger, fixed, threshold in that case.

@expipiplus1
Copy link
Author

The test which tests that show is suggested for the hole _ :: Int -> String fails, because too many holes suggestions are generated (hence none are reported).

The test is:

globalConvert :: Int -> String
globalConvert = undefined

globalInt :: Int
globalInt = 3

bar :: Int -> Int -> String
bar n parameterInt = _ (n + n + n)  where
  localConvert = (flip replicate) 'x'

foo :: () -> Int -> String
foo = undefined

And the suggested holes are:

7. replace _ with localConvert
8. replace _ with globalConvert
9. replace _ with prettyPrint
10. replace _ with mempty
11. replace _ with showGhc
12. replace _ with show
13. replace _ with discard
14. replace _ with bar _
15. replace _ with foo _
16. replace _ with ($) _
17. replace _ with pure _
18. replace _ with join _
19. replace _ with return _
20. replace _ with (!!) _
21. replace _ with unfoldr _
22. replace _ with id _
23. replace _ with head _

I really like the suggestion of filling a hole with id _ or ($) _! (reminds me of this: haskell/haskell-language-server#520)

I think that although this is a good example of why this is useful, it might not be good to use until holes are either suggested with a bit more restraint, or could be sorted by likely usefulness (and in that case only the top n holes could be reported)

@pepeiborra
Copy link
Collaborator

Ghc flags allow to set the max number of hole suggestions. The code is in D.I.GHC.Compat

-- 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"!!!

@pepeiborra
Copy link
Collaborator

I think the limit (be it 5 or 15) should be moved to the GHC flags that we set in GHC.Compat, and make sure we don't override a user value.

@expipiplus1
Copy link
Author

expipiplus1 commented Oct 30, 2020 via email

@pepeiborra
Copy link
Collaborator

GHC flags allow specifying the sorting algorithm too

@pepeiborra
Copy link
Collaborator

The ghcide Github project is becoming archived and merged into https://github.com/haskell/haskell-language-server

This PR will need to be reopened in the HLS repo. To do that, create a new branch from HLS HEAD in your HLS repo and do:

git remote add ghcide https://github.com/georgefst/ghcide.git
git fetch ghcide
git merge ghcide disable-warnings

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't suggest hole filling for ambiguous holes or when there are too many suggestions
3 participants