3 ms·
I'm not sure how LightTable works, but I can talk about how it works in Cursive. There's really not a lot of magic but there are a lot of tricky details. It see
by lemming 13y ago
I'm not sure how LightTable works, but I can talk about how it works in Cursive. There's really not a lot of magic but there are a lot of tricky details. It seems like you're mostly talking about object method calls there - you're right that in the most common case (start typing the method name without putting the object after it first) you really can't do much. Currently in that case we propose all methods for all available classes, which is everything in java.lang and everything that's imported - I think most Clojure solutions do this. However this still misses some cases like (warning: totally invented api):
(let [entry (.getEntry my-map)
key (.getK|
Here you can't easily tell that you want the key of your map entry here since the MapEntry class isn't imported. I'm planning some improvements where I'll walk up the AST from the completion point and get the types of all variables on the way and propose all methods from them, but that requires type inference which I don't have yet (although it's on the list). IntelliJ has also really shown how you can push the bar here with some lateral thinking, they propose chained method calls etc based on the type, so there's a lot of cleverness you can do with a little thought (and a good test suite).
Completion for functions etc is obviously easier although in the case of protocols the problem is similar - you'll get all the protocol methods suggested since they're just fancy functions, but you won't get proper context-sensitive completion unless you've put the object implementing the protocol after the symbol you're completing - the most you can hope for is some sort of error message later that what you've entered doesn't look consistent.
Edit: one thing I forgot to mention is that in the completion list for methods we show the full signature as well as the list of all classes that have a method with that signature, which helps a lot in choosing the right method.