Hi !
I'm working on a plugin for Light Table (
https://github.com/rundis/LightTable-Groovy)
. One thing Light Table tries to address is providing developers with more value than current editors do. One particular area is reducing the need for log/printlns for debugging purposes. One of the ways to address that is to try and devise clever ways to show results inline alongside code, where possible even how values flow through the code/methods/functions/statements. The clojure plugin for Light Table manages to do some pretty funky stuff, and I'm curious about what would be possible to do with some groovy magic :-)
So far I've done some really basic stuff using GroovyShell to get a return value, whatever is printed to std out and retrieve and binding variables set. Its a start, but certainly not kicking butt quite yet.
1) Would it be possible to intercept each statement of a groovy script to extract information about:
- assignments (name and value set)
- method-calls/function-calls with param names, values and returnvalue
- ... with reference to line number (and line col where applicable) from the originating script-file/text
2) Which avenue would quickly get me further than I am, and which avenue would take me to new heights in the long term : (interceptors? mop funkyness ? ast ?)
3) Any suggestions on where I can find inspiration in terms of implementation ? OpenSource projects, the groovy console code ?
Let me provide a fairly simple but still interesting example:
1: def myDouble(x) { it * 2}
2: x = 4
3: y = 6
4: z = x + y
5: a = myDouble([x, y, z].sum())
6: if(new Date()[Calendar.MONTH] % 2 == 0) {
7: a = a + 1
8: }
- Step 1: Show value of assignments. This alone would be great and a huge step forward for me !
1: def myDouble(x) { it * 2}
2: x = 4 // -> 4
3: y = 6 // -> 6
4: z = x + y // -> 10
5: a = myDouble([x, y, z].sum()) // -> 40
6: if(new Date()[Calendar.MONTH] % 2 == 0) {
7: a = a + 1 // -> 41
8: }
- Step 2: Show values of variables used in expressions: lines 4, 5 and 6
- Step 3: Show input param(s) and return value for last invocation of function defined on line 1. (this example happily only calls function once so it would be possible to display values without a doubt, obviously more tricky to display anything sensible if invoked several times
- Step 4. Being able to evaluate this as you type (Instarepl is the term used in Light Table)
Not completely related sample from clojure plugin:
any help / ideas would be greatly appreciated
cheers
Magnus