-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Omit more parens for wildcard type signature #2929
Conversation
This is a followup to haskell#2764.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for adding tests! Just a couple of doc comments.
bracket = ("(" `T.append`) . (`T.append` ")") | ||
msgSigPart = snd $ T.breakOnEnd "standing for " msg | ||
(sig, rest) = T.span (/='’') . T.dropWhile (=='‘') . T.dropWhile (/='‘') $ msgSigPart | ||
(prefix, rest') = T.breakOn "• In the type signature:" rest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment explaining what you explained in the PR description? Otherwise all that knowledge will get lost!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in a new commit after rebase.
(sig, rest) = T.span (/='’') . T.dropWhile (=='‘') . T.dropWhile (/='‘') $ msgSigPart | ||
(prefix, rest') = T.breakOn "• In the type signature:" rest | ||
-- If we're completing something like ‘foo :: _’ parens can be safely omitted. | ||
isToplevelSig = not (T.null prefix) && " :: _" `T.isSuffixOf` T.takeWhile (/= '\n') rest' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the prefix being empty here matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that breakOn
didn't return any prefix if its pattern was not found. So the check is that the error message really contained • In the type signature:
as a substring with the •
.
This is a followup to haskell#2764.
* Omit more parens for wildcard type signature (haskell#2929) This is a followup to haskell#2764. * Review suggestions
This is a followup to #2764
I noticed that for cases like
foo :: _
the GHC always prints• In the type signature:
, but when part of a subtype it will print a stack of contexts ending withIn the type signature:
but without•
. Also for the 'toplevel' case the type signature in theIn the type signature
bit will be normalized intofoo :: _\n
which can be checked for.For instance this is the message when hole is not 'toplevel' - there's a stack of where the hole was located ending with
In the type signature
And this is the error message for the 'toplevel' case - the line starting with
• In the type signature
also ends with:: _
which is easy to check and that's what this PR does.Still not a general-purpose solution and a somewhat fragile heuristic that may break with newer GHC releases (but could be solved when GHC introduces something like structured errors). Yet it addresses a, what appears to me, pretty common case and sems to be reasonably simple.