Fork me on GitHub
#cursive
<
2018-07-03
>
gfredericks16:07:12

I'm trying to wire up intellij/cursive such that I can have a custom clojure function reformat the code in a file with a single keybinding I'm running into a variety of small problems, and might be stuck

gfredericks16:07:47

I successfully used repl commands to get a clojure function to be called with the current filename as an arg, so I can successfully get the file on disk to be reformatted with a single keystroke

gfredericks16:07:08

the repl command also has an option to make sure the file is synchronized before making the call, so that's good

gfredericks16:07:35

however intellij doesn't reload the file immediately; it'll do it if you focus off and back on to the frame, or if you explicitly call synchronize

gfredericks16:07:13

so I looked into intellij macros, and successfully got a macro that first calls the repl command and then calls synchronize, but now the problem is that apparently the repl command is async and so the synchronization happens before the repl's gotten the chance to rewrite the file

gfredericks16:07:14

I don't know of a way to ask a macro to sleep (which would be hacky and racey anyhow), and I doubt that repl commands should support synchronous things does anybody know of a way to get frames to reload automatically even when focused, as long as they have no pending changes?

tony.kay16:07:39

Hm. I’m running a deftest via nREPL from the keyboard shortcut. The test is failing with a clojure spec failure, and IntelliJ hangs. Ideas?

tony.kay16:07:37

Ah…looks like it hangs at command line too. Must be a bug in my specs or in spce itself. Not a cursive issue. Might be nice if Cursive could somehow keep such hangs from making a IDE restart necessary.

cfleming22:07:32

@gfredericks Hmm, no, I don’t. External Tools (https://www.jetbrains.com/help/idea/settings-tools-external-tools.html) might be a better solution for this. You’ll be spinning up a new process to format each time, but IIRC there was a GraalVM image of cljfmt kicking around recently which started up pretty fast.

cfleming22:07:50

What’s the reformatting tool you’re using?

gfredericks22:07:31

cljfmt and how-to-ns mostly

cfleming22:07:59

Having the REPL commands sync the files when done is not a bad addition, though, although the macro still wouldn’t wait for it.

gfredericks22:07:32

No need for a macro at that point, right?

cfleming22:07:40

If you’re using External Tools, you mean?

cfleming22:07:05

No, you’re right, you wouldn’t.

cfleming22:07:18

Let me take a look at that.

gfredericks22:07:57

Oh boy oh boy oh boy

cfleming22:07:28

@gfredericks Ok, it’s slightly tricky but I think I’ll be able to do that as part of some REPL refactoring I’m planning shortly to support deps. I’ve filed this to track it: https://github.com/cursive-ide/cursive/issues/2006

cfleming22:07:35

@tony.kay If you have a small repro case of that (i.e. a small case which causes the hang in and out of IntelliJ) then I can have a go at fixing it - I’m not sure what would cause IntelliJ to hang there.