vim

For discussion on all things (neo)vim.
b-ryan 2020-06-11T02:36:46.162100Z

@olical does Conjure expose a way to execute nrepl commands from another plugin? I am trying to get this plugin working https://github.com/clojure-vim/clj-refactor.nvim that relies on fireplace, but is broken. I have gotten through the code enough to see that this is where it calls fireplace https://github.com/clojure-vim/clj-refactor.nvim/blob/master/src/clj_refactor/repl.cljs#L39 but I think fireplace must have switched at some point from synchronous execution to async of some sort. I figured that since I am using conjure most of the time lately I may as well try to get it working there anyway. I think I need to do sort of what this ns is doing https://github.com/Olical/conjure/blob/master/fnl/conjure/client/clojure/nrepl/action.fnl

Olical 2020-06-11T10:00:44.162200Z

Hey, good question! There are ways to execute Clojure (or any Conjure supported language) programatically. All evals are assumed to be async within Conjure’s clients since they’re usually over some sort of socket and we don’t want to block the UI. That means there’s a callback framework in place for when you need the result for something other than just printing to the user. https://github.com/Olical/conjure/blob/5cb5e37913fa6fe410ee150f5cd8c75e34b060c4/fnl/conjure/client/clojure/nrepl/action.fnl#L53-L74 So you’ll want to set the cb opt for eval-str. That will be called with each nREPL message pertaining to the evaluation. So if there’s some stdout or an error, you’ll get those as separate calls. You can use server.with-all-msgs-fn to batch up all of the nREPL messages into one call so you can just assume the last one is the result of the eval (there may only be one message in a lot of cases, the eval result). At some point I’ll be adding a plugin interface that’s well documented and hopefully stable, but for now this should work well. I’m not planning on changing this at all right now.

Olical 2020-06-11T10:04:07.162500Z

Then you can use the result of clj-refactor to update something in the buffer. If you want to refactor the current form you can use the conjure.extract module to extract the form content and it’s range. You may want to base some things on the replace-form code https://github.com/Olical/conjure/blob/5cb5e37913fa6fe410ee150f5cd8c75e34b060c4/fnl/conjure/eval.fnl#L82-L102 Which I would use if / when I implement formatting of forms, for example. It shows all the tools you need to find and extract a form, perform an eval, capture the result and replace the original form range with it.

Olical 2020-06-11T11:53:08.163Z

Feel free to continue or share your finished awesome results over in #conjure, I’m sure everyone would love a refactoring plugin! It’ll be the first external plugin in the Conjure ecosystem (if you don’t count the autocompletion plugins)

b-ryan 2020-06-11T13:15:02.163200Z

Thanks for the info! I will give this a shot soon.

Olical 2020-06-11T10:00:44.162200Z

Hey, good question! There are ways to execute Clojure (or any Conjure supported language) programatically. All evals are assumed to be async within Conjure’s clients since they’re usually over some sort of socket and we don’t want to block the UI. That means there’s a callback framework in place for when you need the result for something other than just printing to the user. https://github.com/Olical/conjure/blob/5cb5e37913fa6fe410ee150f5cd8c75e34b060c4/fnl/conjure/client/clojure/nrepl/action.fnl#L53-L74 So you’ll want to set the cb opt for eval-str. That will be called with each nREPL message pertaining to the evaluation. So if there’s some stdout or an error, you’ll get those as separate calls. You can use server.with-all-msgs-fn to batch up all of the nREPL messages into one call so you can just assume the last one is the result of the eval (there may only be one message in a lot of cases, the eval result). At some point I’ll be adding a plugin interface that’s well documented and hopefully stable, but for now this should work well. I’m not planning on changing this at all right now.

Olical 2020-06-11T10:04:07.162500Z

Then you can use the result of clj-refactor to update something in the buffer. If you want to refactor the current form you can use the conjure.extract module to extract the form content and it’s range. You may want to base some things on the replace-form code https://github.com/Olical/conjure/blob/5cb5e37913fa6fe410ee150f5cd8c75e34b060c4/fnl/conjure/eval.fnl#L82-L102 Which I would use if / when I implement formatting of forms, for example. It shows all the tools you need to find and extract a form, perform an eval, capture the result and replace the original form range with it.

Olical 2020-06-11T11:53:08.163Z

Feel free to continue or share your finished awesome results over in #conjure, I’m sure everyone would love a refactoring plugin! It’ll be the first external plugin in the Conjure ecosystem (if you don’t count the autocompletion plugins)

b-ryan 2020-06-11T13:15:02.163200Z

Thanks for the info! I will give this a shot soon.