Fork me on GitHub
#cursive
<
2017-09-07
>
tomas03:09:02

Is it possible to resolve symbols as fn or letfn in cursive? I have problem with this macro:

(defcmd :command/login
        (cofx [cmd ctx]
              ...cofx-code...)
        (fx [cmd cofx]
              ...fx-code...))
which expands to something like this:
{:cmd-id :command/login
 :cofx (fn [cmd ctx]
         ...cofx-code...)
 :fx (fn [cmd cofx]
       ...fx-code...)}
cofx and fx are converted to anonymous function definition. But cursive marks possible function parameters as “cannot be resolved”. I think that marking symbols cofx and fx to be resolved as fn would solve the problem. What do you think?

Oliver George10:09:45

Quick thought in passing. I'd like to know which of my functions have a (s/fdef ...) spec associated with them so that I'm encouraged to add ones which are missing.

Oliver George10:09:23

A simple visual indication would be enough to be useful.

Oliver George10:09:40

Cursive Spec MVP FTW!

cfleming10:09:31

@olivergeorge Good idea, could you file an issue for that one please?

potetm14:09:18

@cfleming Are there any plans to support tools.deps.alpha? That would be pretty snazzy.

kenny19:09:21

@cfleming Per our conversion earlier about formatting: I made the CLI that wraps cljfmt https://github.com/ComputeSoftware/cljfmt-cli. It is working well so far. Although not incredibly important, the one place this breaks is in the REPL. I don't believe there is any way to get the REPL content as a string or file and reformat with an external tool.

kenny19:09:19

The REPL content would need to be available as an external tool macro.

kenny19:09:55

I suppose I could select all the REPL text, use the SelectedText macro, and then format that. Though it's not clear what is done with the output. Does it replace the selected text with the output of the external tool? Anyway, its not the cleanest solution anyway because you have to select all of the text.

cfleming21:09:54

@narek I’m actually working on the test integration right now, I’ll see if I can reproduce that.

narek18:09:15

Good to hear, thanks!

cfleming21:09:43

@tomas Unfortunately I don’t think you can use that in your case. The issue is that cofx and fx don’t resolve to anything, they’re special to the macro.

tomas04:09:25

You’re right, but I can create var so cursive will see it and macro will shadow it for execution. Then I can mark fx/`cofx` to be resolved as fn

(defmacro defcmd [& args])
(defmacro cofx [& args])
(defmacro fx [& args])
(defcmd :solved.cmd/login
         (cofx  [cmd ctx])
         (fx [cmd cofx]))
It’s kind of hack, but can solve the problem for now…

cfleming04:09:30

Very true. I’m planning to add arbitrary “Resolve as…” support but haven’t done so yet. There’s a hack described here though: https://github.com/cursive-ide/cursive/issues/1440#issuecomment-232776904

tomas13:09:40

Thanks a lot, that works!

cfleming21:09:11

Sadly there’s probably no good way to support that until I get better general macro support into Cursive.

cfleming21:09:11

@potetm Yes, I’ll probably support that soon. It currently doesn’t support everything that Cursive needs (e.g. source roots) so those will have to be manually set up.

cfleming21:09:37

@kenny Hmm, I’ll have to look at the External Tools part to see if there’s anything I can do about that.

cfleming21:09:21

If they don’t have something like a “Text content of current editor” macro then it might be difficult.

kenny21:09:51

Yeah nothing like that exists right now. Upon further inspection, the "Macro preview" for SelectedText does not show text as being selected when it is selected in the REPL. It only shows selected text when text is selected in the editor.

cfleming21:09:15

Yeah, the REPL editor is special, some things may not work. I can imagine the External Tools functionality being built around editors editing files, since it has to be able to pass them to external tools somehow.

cfleming21:09:27

I’m surprised it doesn’t support directly piping text better, though.