Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of valid hole fits to 10 #4288

Merged
merged 4 commits into from
Jun 9, 2024

Conversation

akshaymankar
Copy link
Contributor

@akshaymankar akshaymankar commented Jun 8, 2024

Fixes #4198
Supersedes #1914

@@ -449,7 +449,7 @@ setUpTypedHoles df
$ df
{ refLevelHoleFits = Just 1 -- becomes slow at higher levels
, maxRefHoleFits = Just 10 -- quantity does not impact speed
, maxValidHoleFits = Nothing -- quantity does not impact speed
, maxValidHoleFits = Just 10 -- quantity does not impact speed
Copy link
Collaborator

Choose a reason for hiding this comment

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

outdated comment also on the previous line

Can we have a comment explaining the choice of the magic number? "I made this up" is fine, it indicates we don't have a good reason for it, which is helpful information for the future

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the version we want? I don't really know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the comments.

@@ -69,7 +69,8 @@ processHoleSuggestions mm = (holeSuggestions, refSuggestions)
(mrAfter . (=~ t " *Valid (hole fits|substitutions) include"))
validHolesSection
let holeFit = T.strip $ T.takeWhile (/= ':') holeFitLine
guard (not $ T.null holeFit)
guard $ not $ holeFit =~ t "Some hole fits suppressed"
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's going on here? Why are we doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GHC prints this line where we expect a hole fit to be when the number of hole fits is limited. This line just ignores that. We do this in the refinement hole fits too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Write it down!

@@ -449,7 +449,7 @@ setUpTypedHoles df
$ df
{ refLevelHoleFits = Just 1 -- becomes slow at higher levels
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, I think these things are also user-configurable. Generally it's nice if we don't overwrite user settings if they've set them. So can we adjust these so that they use the value from df if it's not Nothing and otherwise use these values? I actually think that's what the old PR did?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now respecting previous values like the other PR.

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.
@michaelpj
Copy link
Collaborator

Genuine test failure in hls-refactor-plugin, it's looking for a hole-fit suggestion code action that presumably now gets filtered out. Not sure quite how we want to fix this - we could change the test to look for one that does get selected, or maybe we should just increase the number of fits to 20 or something.

@akshaymankar
Copy link
Contributor Author

Genuine test failure in hls-refactor-plugin, it's looking for a hole-fit suggestion code action that presumably now gets filtered out. Not sure quite how we want to fix this - we could change the test to look for one that does get selected, or maybe we should just increase the number of fits to 20 or something.

Just replaced the test with a type which has fewer hole-fits. For me getting 20 code suggestions for a hole feels a bit overwhelming (10 is already pushing it honestly), but its just a feeling.

Now that we limit number of hole fits recommended by GHC, the test that
hopes to find `+` being recommended for `Int -> Int -> Int` becomes
unpredictable because there are too many symbols which match that type
and the sorting has little control over which symbols get recommended.

There are way fewer matches for `(Int -> Maybe Int) -> Maybe Int ->
Maybe Int`, so it makes the test consistently succeed.
@michaelpj
Copy link
Collaborator

Great, happy to take your read on the UX.

@michaelpj michaelpj enabled auto-merge (squash) June 9, 2024 08:01
@michaelpj michaelpj merged commit 7b8e2e5 into haskell:master Jun 9, 2024
34 checks passed
@akshaymankar akshaymankar deleted the limit-hole-fits branch June 9, 2024 08:59
@Tritlo
Copy link

Tritlo commented Jun 11, 2024

Hmm. Does this then now not inform the users when there are hole-fits found but are suppressed by this setting? That seems confusing and counterintuitive, though I might be biased.

@michaelpj
Copy link
Collaborator

This doesn't change how the normal diagnostic from GHC is produced, I think.

@akshaymankar
Copy link
Contributor Author

We do get this info from GHC that some hole-fits are suppressed. I don't know what would be a good way to communicate this info.

@michaelpj
Copy link
Collaborator

If you mean e.g. in offering completions, I don't think we have a good way of conveying that information...

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

Successfully merging this pull request may close these issues.

Applying a code action to a _ hole produces too many suggestions
3 participants