Fork me on GitHub
#vim
<
2018-07-10
>
Hukka06:07:13

Gah. clj-refactor is just giving me "Cannot read from non-string object", when I try to rename symbols

Hukka06:07:32

I'm pondering if I should set up a debugging environment for the plugin...

dominicm06:07:07

That is odd. Can't explain it. Debugging environment is probably useful.

dominicm06:07:27

Is it possible your code is invalid anywhere in the document? It relies on tools.analyzer.

Hukka06:07:35

Shouldn't be, no. I tried changing a function name first, from within the defn. That didn't work, so I just entered two top level foos, and changing them had the same result

Hukka06:07:56

I tried setting NEOVIM_JS_DEBUG, but nothing is written

Hukka06:07:14

I'm now testing whether any repl command works. crrf also just opens an empty buffer without making any changes anywhere

Hukka06:07:57

Extract function does kinda make a new function, but it doesn't see that it needs to add parameters

Hukka06:07:49

Clean namespace doesn't remove a [foobar] :require 😞

Hukka06:07:07

Seems like I can't get much mileage out of this. Cycling collections does work...

dominicm06:07:01

Those things should work

dominicm06:07:08

You definitely have refactor-nrepl installed right?

Hukka06:07:57

It's in my lein-profile, yes

Hukka06:07:16

And I'm pretty sure I saw lein install stuff the first time after that

Hukka07:07:33

I do have newer cider-nrepl than what the refactor-nrepl docs show, though

Hukka07:07:26

Hmh. Everything is the same, if I remove it from the profile, though

Hukka07:07:45

I had one lein repl open, and closed that. After that I'm getting different results – mostly the commands don't give errors anymore, but neither do they do anything

Hukka07:07:08

Hm, except clean namespace now gives "Error: Unable to get results{...", :prune-ns-form "true"}=>nil"

Hukka07:07:23

Quite many things give similar error, Unable to get results

Hukka07:07:38

It's very undeterministic. I'm trying to change whether the definition is in user profile or project, and the now the errors disappeared, while the commands still don't work

dominicm07:07:06

@tomi.hukkalainen_slac just to check, which versions of cider & refactor are you using?

Hukka07:07:16

I've tried [refactor-nrepl "2.3.1"] [cider/cider-nrepl "0.14.0"] and 0.17.0

dominicm07:07:49

17 is incompatible with 2.3.1, you have to use 2.4.0-snapshot to have them work together. But 0.14.0 should work, but it's old and I'm not too familiar with any issues it might have.

Hukka07:07:35

Ok. Trying the snapshot

Hukka07:07:26

Still nothing, at least from user profile

Hukka07:07:00

Hmh. Launching lein repl, it's only now trying to install the snapshot

Hukka07:07:11

So simply launching nvim with fireplace doesn't

Hukka07:07:23

Am I completely mistaken how I should even launch this?

dominicm07:07:38

Hmph, so. {:op "rename-file-or-dir" :old-path current-file :new-path new-file}, should be roughly equivalent to :echo fireplace#message({'op': "rename-file-or-dir", 'old-path': expand('%:p'), 'new-path': expand('%:p:h').'foo.clj'}) which might give us some more useful debugging info.

Hukka07:07:10

I noticed that I get different behaviour whether I have lein repl running or not

Hukka07:07:16

If I don't, rename symbol does nothing

Hukka07:07:27

If I do, I get that "Cannot read from non-string object"

dominicm07:07:59

lein repl should be running, rename file requires a repl

dominicm07:07:10

it may not fail gracefully in the lack of a repl

Hukka07:07:26

That fireplace command does the rename

Hukka07:07:57

At first I thought nothing happened, since the buffer didn't change, but quitting and diffing showed the rename and also changed all the ns calls

Hukka07:07:37

Urgh, ok. I missed that I need to run a repl...

dominicm07:07:32

fireplace command works means that there's a bug in how refactor.nvim, and not in refactor-nrepl.

dominicm07:07:14

I don't know why it's broken however, and I'm not sure why it works for some and not you. I imagine it could be node version, but I'm not certain.

Hukka07:07:42

I tried the shortcut now, and I get "Error: Error during fireplace#message: Can't find src dir prefix for path /home/hukka/repos/reititin/src/reititin/foo.clj"

Hukka07:07:33

So I guess earlier there was a problem with mismatched cider-nrepl and refactor-nrepl versions

Hukka07:07:06

And now I'm getting an AST error with another file, when I rename a symbol. So that's probably what you were talking earlier, and perhaps the file renames borked all the files 🙂

Hukka07:07:23

But it's progress. I'll git reset and let's see from the beginning

dominicm07:07:57

hehe, okay.

dominicm07:07:18

I think refactor-nrepl can be a little difficult tbh. refactor.nvim should try and ease more of that, but contributions are needed upstream really.

Hukka07:07:52

So what does needing a repl even mean. I thought that fireplace always launches a nrepl behind the scenes

Hukka07:07:12

The lein repl is just a premade instance of that, I thought

dominicm07:07:15

@tomi.hukkalainen_slac salve might do that, fireplace doesn't.

dominicm07:07:26

I don't use salve, it was really slow for me.

Hukka07:07:14

Ok. I misread the docs to think that salve helps when there is no repl

dominicm07:07:42

fireplace definitely doesn't auto-start a repl.

Hukka07:07:52

"Oh, and if you don't have an nREPL connection, installing salve.vim lets it fall back to using java clojure.main for some of the basics, using a class path based on your Leiningen config. It's a bit slow, but a two-second delay is vastly preferable to being forced out of my flow for a single command, in my book."

Hukka07:07:22

So I guess what happened, is that when I had my screen repl thingy running, it wasn't as much that it wasn't interfering with fireplace, it was making it work in the first place

dominicm07:07:26

I don't think your screen repl did anything. vim-salve was doing java -cp ~/.m2/repository/org/clojure/clojure.jar -e '(+ 1 1)' in the background

Hukka07:07:38

Is salve installed automatically?

dominicm07:07:56

Nope. Oh, if you don't have salve, then yes, your screen repl was doing it, yup

dominicm07:07:03

It was running lein repl I'd guess?

Hukka07:07:58

I turned it off after the refactor rename file fell on its face, when it had extra buffers open (the :terminal buffer)

Hukka07:07:47

Ok. Things are now working, somewhat. Thanks! There are still gaps, though, like renaming a function doesn't rename spec/fdef calls

dominicm07:07:53

yeah, that functionality definitely doesn't exist in refactor

dominicm07:07:10

contributions welcome 😄

Hukka07:07:02

Seems a bit too tall order for now, when I'm still struggling to understand how to even use these tools

Hukka07:07:17

Next year, perhaps

dominicm07:07:47

It's a fun journey to go on, it results in interesting knowledge 🙂

Hukka08:07:17

I think I would start from implementing some missing refactorings. I'd like to have promote-fn-literal

dominicm08:07:48

I just fixed vim-jack-in's dispatch.vim integration, which I hadn't realised was broken due to the hidden fallback behaviour I added. Some have mentioned that they don't like starting a repl inside neovim, perfectly understandable. If you set g:dispatch_terminal_exec to something like xterm -e, it will open in a new terminal. I believe it has native tmux tab integration too.

dominicm08:07:01

Oh, apparently I have to use the non-backgrounding version to have tmux integration work. I might add a bang flag to the commands for foreground/background, to help with that.

Hukka08:07:03

That sounds suspiciously interestingly related to my screen thingy needs

dominicm08:07:13

very possibly 🙂

dominicm08:07:17

I think dispatch supports screen in fact

dominicm08:07:30

vim-jack-in will auto-inject cider & refactor-nrepl for you though 🙂

dominicm08:07:44

no need to fiddle with lein profiles, boot tasks or clj aliases.

Hukka08:07:50

Does it work with fireplace, or does the repl need to be running when nvim launches?

dominicm08:07:11

it works with fireplace. Or rather, it works independently of it.

Hukka08:07:51

To clarify, fireplace will then use the repl jack-in created?

Hukka08:07:32

My vim is turning into an emacs with all of these bolt-ons

dominicm08:07:09

" Clojure {{{

" Update the static files for clojure from it's upstream,
" this includes fixes like indenting #() properly.
Plug 'guns/vim-clojure-static'

" This plugin allows you to manipulate sexp (clojure
" parens) in magical ways.
Plug 'guns/vim-sexp'
" By default == has a maximum number of lines to prevent
" hanging. Disable that, because I'm happy to wait when I
" want this.
let g:clojure_maxlines = 0

" Unfortunately the default mappings for vim-sexp are hard
" to press (lots of ctrl & alt), but tpope has us covered:
Plug 'tpope/vim-sexp-mappings-for-regular-people'

" FiREPLace is a plugin for integrating with a Clojure
" nREPL.
Plug 'tpope/vim-fireplace'

" REPLant is a plugin for enhancing your REPL experience
" with vim I develop this, so I've selected my src dir.
Plug '~/src/github.com/SevereOverfl0w/replant'

" A plugin for managing nREPL middleware and starting the
" nREPL.
Plug '~/src/github.com/clojure-vim/vim-jack-in'
" }}}
^ My clojure configuration

dominicm08:07:49

Heavier perhaps than most language-specific setups, but when you have such power in integration it's really valuable.

dominicm08:07:59

I'm still faster in vim than emacs colleagues, I think

dominicm08:07:43

They have all sorts of weird things, like having to do the equivalent of )a before being able to evaluate with some ctrl-x-a-eg-b-a combo. This is because there's only an eval-last-sexpr instead of being able to do cp followed by whatever text object you like (`af`)

Hukka08:07:21

Do you have that config uploaded?

Hukka08:07:40

Just thinking whether to open a tab for later processing, or process now before slack loses it 😉

dominicm08:07:16

I'm still tweaking it. I rewrote it over the weekend.

cristibalan15:07:42

Hi. Is there a way to list what connections vim-fireplace has established? Or turn on some debugging?

cristibalan15:07:12

I have this situation with cljs where there are two cljs repls started by the app and I have to call a function in the clojure repl that would switch to the appropriate cljs repl (the emacs users have to do this as well and can't rely on the automagic of cider).

cristibalan15:07:48

I am very unknowledgeable to all this btw, sorry if I assume weird stuff.

cristibalan15:07:55

The function just does (figwheel-sidecar.repl-api.cljs-repl "blah") it seems.

dominicm16:07:16

From the perspective of nrepl, there's only one repl connection. You use your underlying driver to switch, figwheel has a way of switching for example.

cristibalan16:07:48

Ok, cool. Progress in undestanding at least.

cristibalan16:07:53

Ok, so the first situation is that when in a clj file, when I eval the switch, it works and I get the figwheel doc output. However, when trying to eval (js/alert "blah") in the same file. it appears fireplace attempts to eval the current buffer as cljs.

dominicm16:07:13

It's been a while since I had to do this.

cristibalan16:07:24

This is vim, btw. Not neovim.

dominicm16:07:41

What if you run it from figwheel? Sure, all the same for fireplace.

cristibalan16:07:09

The js alert works just fine (shows up in the browser) when I connect to the repl with lein on the cli and switch there.

cristibalan16:07:11

It appears that there is some magic in fireplace that assumes something about the connection and maybe reconnects instead of reusing the existing switched one?

cristibalan16:07:41

The second and main problem is that I can't eval anything in a cljs file, that's why I tried to eval the switch in a clj file in the first place.

cristibalan16:07:50

I get this error

clojure.lang.ExceptionInfo: No such namespace: react-portal, could not locate react_portal.cljs, react_portal.cljc, or JavaScript source providing "react-portal" (Please check that namespaces with dashes use underscores in the Cloju
reScript file name) in file
which kinda makes it seem it didn't load all the necessary cljs stuff.

cristibalan16:07:26

There are several files with dashes and this works for the emacs people, so renaming as it says is probably not the answer.

cristibalan16:07:37

I have no beef with adding debugging statements like a maniac to fireplace, but I'm not really sure where or what to look for.

cristibalan16:07:01

Is there a way I could reload it without restarting vim after every change?

cristibalan16:07:34

I've had some success and actually one output of js/console.log in the browser after doing :Piggieback (the-repl-switcher-fn). Can't consistently reproduce the incantation tho :face_with_rolling_eyes:

cristibalan16:07:23

After outputing twice just moved to printing things to the cli log instead of the browser.

cristibalan16:07:42

(╯°□°)╯︵ ┻━┻

dominicm17:07:02

Fireplaces connection handling isn't sensible tbh, it may not be cut out.

dominicm18:07:23

I'm sure I managed this though