Fork me on GitHub
#cursive
<
2018-04-29
>
jaen06:04:52

@simon I think that's related to what I asked above – as far as I understand it's a functionality that generates a file with minimal defs for files which generate symbols with macros, so that autocompletion for such namespaces can work. For example https://github.com/dm3/clojure.java-time/blob/master/src/java_time.clj re-exports symbols from namespaces with a macro and without stubs it confuses Cursive – it can't offer completion for this namespace. When the pop-up shows and you ask it to generate stubs, it will (partially) evaluate the macros, to produce a file it can use for completion. So if you value the use of completion, it will be generally a good idea to click that Generate now link. One downside I can see is that there seems to be no way to navigate from the stub to the macro that generated it, so if you want to read the implementation, it's less accessible.

4
jaen06:04:05

@cfleming is there a way to navigate from a stub to the code that generated it?

cfleming07:04:21

@jarppe So right now this is done statically from the source code, i.e. is has to be an (is (= a b)) form. That’s not extensible at the moment, I’ll look to see if I can do that.

cfleming07:04:32

@simon Yes, @jaen is correct on how this works.

4
cfleming07:04:05

@jaen No, in general I don’t think that’s possible, there’s generally no information in the generated code that will tie it back to the macro.

cfleming07:04:31

Actually, now that I think about that, I’m not so sure - I’ll see if I can do that.

jaen08:04:44

I mean, I don't presume to know how exactly you implemented it underneath, but considering it output just the stubs, it can't be regular macrcoexpansion, can it? Then you could probably thread location metadata through the code that does macroexpansion, I suppose? Depending on how exactly you have this implemented it it can be simple or annoying to do, but hopefully doable? Not a high priority though, you could even just add a navigation action for the whole stub file to it's source file – it's certainly way simpler and almost as useful as navigating per symbol.

jaen08:04:03

Also, re: usability of that tooltip – maybe it would be a good idea to put it in a bar that appears on top of the file (like for missing file associations or filetype plugin sugesstions)? It would be harder to miss and more discoverable then. Not sure if that's possible for plugins to do it though.

cfleming08:04:02

@jaen The implementation is actually pretty simple - I basically just start a process with the classpath of the module, that requires the namespace and then introspects it. So if those generated vars have any file/line metadata, I might be able to use that.

jaen08:04:27

Ah, so you just use macroexpansion and then simplify it, I see.

cfleming08:04:27

re: having it in the in-editor notification, it actually worked like that at the start, but the process was surprisingly difficult to make robust. The in-editor notification drove people nuts when the stub generation didn’t work since it was present constantly.

cfleming08:04:06

Well, I don’t macroexpand myself, but generally loading the ns will as a side-effect create vars via some technique or other.

cfleming08:04:35

Sometimes macroexpansion, but sometimes they’re table-driven (e.g. om.dom etc)

jaen08:04:16

That's a shame about the ticker tape though. Because I was quite confused why this didn't work until I restarted IntelliJ later and the tooltip popped up.

cfleming08:04:43

It will also not generate stubs for vars in the ns that Cursive knows about already via its own analysis, to try to reduce duplicates in completion etc.

cfleming08:04:50

Yes, I was worried that would happen.

cfleming08:04:35

I could possibly re-visit that and add a Dismiss option to it or something.

jaen08:04:03

Well, at least now I know where I look, but if it's possible to do it robustly with the ticker, it will probably help other people coming across this feature for the first time.

jaen08:04:22

Incidentally, is there any option to force stub generation even if you missed/dismissed that tooltip?

cfleming08:04:37

It will be re-checked when your project is synchronised - you can force that in the Leiningen toolwindow (View-&gt;Tool Windows-&gt;Leiningen-&gt;Refresh) or using the Refresh Leiningen Projects action

cfleming08:04:15

Ideally it would also be re-checked when the ns form in any file is updated, but that’s tricky unfortunately.

jaen08:04:15

Maybe some context menu item on the tab could work? But refreshing from the leiningen tab is a simple enough workaround.

jaen09:04:13

Incidentally, how are the plans for boot support? Just out of curiosity, really, because writing a task to output a lein project works well enough (except no completion in build.boot unfortunately)

cfleming09:04:05

@jaen I’m planning to start working on better build tool support soon. It’ll start with deps support, and then add boot support using deps for dependencies. I’m using those to investigate the IntelliJ infrastructure for build tools, which the lein integration pre-dates and needs to be moved to.

👍 16
cfleming09:04:22

I’ll also add shadow-cljs support once I figure out how the moving pieces work.

jaen09:04:23

Sounds nice, thanks for the info. I'll probably should look into deps.edn then, I've so far had my own simple edn format for that.