These are chat archives for ensime/ensime-atom

7th
Jan 2016
Richard Dallaway
@d6y
Jan 07 2016 12:11
Hello, hello. Is there a facility in Ensime for me to find out the values and their types in scope?
I have a bit of code and it doesn’t typecheck at the moment, but it would be helpful for me to know what values I have around to fix it.

For example:

object Explore {
  val x = 99
  def len(s: String): Int = ???
}

…at the ??? point I’d like to discover:

  • s : String
  • x: Int
(and I’m mentioning this here, because if there is, I’ll be on a mission to add it as a keybinding to Atom)
Viktor Hedefalk
@hedefalk
Jan 07 2016 14:02
Well, you have that as part of the autocomplete feature. Don’t know if there are any other more specific means… Not in ensime-atom anyhow…
But you didn’t like the autocomplete feature, do I remember that right? You know you can make it so it only pops up on command, like ctrl-space or something like that…
Dick Wall
@dickwall
Jan 07 2016 15:14
@d6y as @hedefalk says you can auto-complete on those names with a popup. Once s and x are in the code, at least in sublime, clicking on them gives you the type information in the status bar, and alt-click gives you the same (with hyperlinks to the code) in a pop-up. The type information also works for functions and methods, giving you lots of rich info all linked up. At least in sublime it doesn't know the actual value though unless you are running it in a debugger.
Richard Dallaway
@d6y
Jan 07 2016 15:15
Thanks - that is interesting. Because I don't want to autocomplete -- I want to just think about what I have around, so just names and types (don’t need values). But I may be able to get what I need by gathering whatever comes back via autocomplete. Nice clue gentlemen.
Dick Wall
@dickwall
Jan 07 2016 15:17
oh yes - definitely. Autocomplete let's you send out the request at the current point and then gives you back the list of completions. Filtering that somehow would allow you to do something like that.
If you do, let me know, cos I might add that into sublime once I have seen how it works
Richard Dallaway
@d6y
Jan 07 2016 15:18
OK!
Believe me, if I get it working, the world will know :-)
Dick Wall
@dickwall
Jan 07 2016 15:22
Screenshot from 2016-01-07 07:16:44.png
TooltipType.png
oops - meant to send the small one only
but that's our type tooltip (comes up with alt-click)
all the blue bits are hot links to those types in the code
it's very nice :-) - works for case classes and functions too (figures out to use the apply method for the signature)
Richard Dallaway
@d6y
Jan 07 2016 15:24
:+1: seems like all the info is around, now I just need to gather it into the neat bundle I want.
Dick Wall
@dickwall
Jan 07 2016 15:25
I am intrigued by the idea of knowing the value of a val though - don't think we can do that right now. Not sure if/what it would show for a non-simple (computed) val - just the line of code that produced it?
but that might be a nice feature too. Right now you can only get that in the debugger at run time
Dick Wall
@dickwall
Jan 07 2016 15:35
come to that, while we are discussing pie in the sky stuff. I have always wondered whether something that, when you reference a simple enough function (say (x: Int) => x + 1), we couldn't include the actual apply definition in the popup. fn: Int => Int is correct, but not as helpful as it might be (seems like low hanging fruit to maybe stick small definitions in there)
of course I imagine it would give up pretty quick with literals passed into functions, etc. so maybe it's not that useful
Richard Dallaway
@d6y
Jan 07 2016 15:36
oh, like popup fn: Int => Int = x + 1 ?
Dick Wall
@dickwall
Jan 07 2016 15:37
come to that, and stick this in the pile of "I wonder if that would actually be a good idea in practice", I have oft wondered when teaching (and the question comes up at times), why can't a function literal definition have it's own definition in its toString
so the toString, instead of Int => Int would show that kind of thing as well
of course, for long functions, that would probably suck
so maybe have a length cut off, but catch the short ones
then in the repl, when you typed fn.toString, it would be a lot more helpful :-)
Richard Dallaway
@d6y
Jan 07 2016 15:38
Might be nice to peek into an implementation some how. Like… some plugins let you click on a classname in HTML and jump to the CSS/Less/whatever source, but preview it inline first.
:pizza: :cloud: (can’t find a pie and sky emoticon; so pizza cloud it is)
Dick Wall
@dickwall
Jan 07 2016 15:41
nice :-)
see - it's one of the reasons I love teaching, staying grounded in this stuff
if you type
val x = 5
into the repl
it reports back
x: Int = 5
but if you type
val f = (x: Int) => x + 1
it reports back
val f: Int => Int = function1
that function1, could, with a little bit of extra work, show the x + 1 definition instead
Richard Dallaway
@d6y
Jan 07 2016 15:44
Yeah… presumably so. Or at least some bytecode!
Dick Wall
@dickwall
Jan 07 2016 15:45
nice thing about a toString is it would survive even being generalized into a Function1
i.e. at runtime, in debuggers and stuff, you would see the definition of the function, at least for simple defs
all idle thoughts. It can't be that important or helpful, or else someone would have done it by now
but the question comes up in about half the training sessions we do, when we show function literals
"why do they only show <function1> as their toString"
it's a decent question
Richard Dallaway
@d6y
Jan 07 2016 15:47
Would be nice to have a good answer to that question, even without any improvements in what the REPL does.
Dick Wall
@dickwall
Jan 07 2016 15:47
I do suspect that all those toStrings might slow the compiler down noticeably, so that might well be a good reason to not do it
I mean, it would have to make the toString from the AST for every function, right?
and include the parameters in order to make it make sense
just having it say x + 1 instead of x => x + 1 would not be useful
so you can't just dump the apply body in there
anyway - I am rambling because I have insufficient tea
must get back to real work
Richard Dallaway
@d6y
Jan 07 2016 15:49
What?! Fix that tea problem first. Top priority.
Dick Wall
@dickwall
Jan 07 2016 15:49
it's being fixed. Stupid hot liquid that I can't drink all at once :-)
each blissful hot sip moves me closer to humanity
Richard Dallaway
@d6y
Jan 07 2016 15:50
Yeah.. I need to go read some PDFs. Shame. Still faster I read it, the sooner I get back to noodling with Atom/Ensime.
Ghost
@ghost~540393fe163965c9bc2018ce
Jan 07 2016 15:54
We know the location of where the val was defined
Richard Dallaway
@d6y
Jan 07 2016 15:55
So we could peek-a-boo the source. Nice.
Ghost
@ghost~540393fe163965c9bc2018ce
Jan 07 2016 15:56
But probably it would be an improvement if the toString was the type name
Which is also known
Dick Wall
@dickwall
Jan 07 2016 15:59
that's true, enhancing functionN's toString to at least give the type information might be useful, and relatively low hanging fruit