-
-
Notifications
You must be signed in to change notification settings - Fork 410
Add :info command in Eval plugin #1948
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
Conversation
pepeiborra
left a comment
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 Moises!
|
|
||
| import InfoUtil (Eq, Ord, Foo) | ||
|
|
||
| -- >>> :info Foo |
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.
I ended up changing these tests to work on a custom Foo (and Bar) datatype defined in InfoUtil, since using Bool meant way too many instances and potentially broken tests when new instances get added
| @@ -0,0 +1,3 @@ | |||
| packages: | |||
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.
I moved the test/testdata/cabal.project file one directory up, so I could define another library info-util. This was because :info prints the origin comment (-- defined in "...") using the full path to the file for modules in the same package, which wouldn't be portable.
| import Prelude (Eq, Ord) | ||
|
|
||
| data Foo = Foo1 | Foo2 | ||
| deriving (Eq, Ord) |
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.
I ended up dropping the Show instances since they would still come out in different orders sometimes. Thankfully Eq, Ord and Baz are enough to show the difference between :info and :info!
| mb_stuffs <- mapM (GHC.getInfo allInfo) names | ||
| let filtered = filterOutChildren (\(t,_f,_ci,_fi,_sd) -> t) | ||
| (catMaybes mb_stuffs) | ||
| return $ vcat (intersperse (text "") $ map pprInfo filtered) |
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.
You could always sort the filtered children before printing to ensure that the output is deterministic
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.
yeah, the problem is the [ClsInst] part of the tuple returned by GHC.getInfo. Sadly, ClsInst doesn't have an Ord instance, and I didn't want to impose any custom ordering
|
hmm, seems like |
|
mmm maybe different files for ghc version (I hope only will be two)? |
| , goldenWithEval "Variable 'it' works" "TIt" "hs" | ||
|
|
||
| , testGroup ":info command" | ||
| [ testCase ":info reports type, constructors and instances" $ do |
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.
As suggested by @jneira, these tests now only look for the relevant infix strings (or their absence)
maybe it worths open a ticket in ghc asking for make it public? |
|
@akrmn many thanks for this useful feature |
@akrmn i was about to open an issue in the ghc project but is not obvious for me what definitions from |
99% of the code is copied from
GHCi.UI.infoand the functions called from there. Ideally this would be exported fromGHCi.UIbut sadly that's not the case.Note that the tests commit is marked as [WIP] because, when running the tests on my machine, I keep getting the instances in different orders. I haven't been able to figure out the source of nondeterminism.
This should eventually close #402