I'm seeing an issue with extract-function. I noticed that when I select two expressions and use extract-function only the first expression is added to the new function. I'm using the lightbulb popup, see the video in the thread. I thought I had used this before, but maybe not? I see that extract-function is using clojureLsp.refactor.extractFunction, but I don't know how to tell if Calva is passing clojure-lsp the full selection. I was using clojure-lsp latest, but tried a few other versions (eg 2025.02.07-16.11.24) with the same result.
Calva version used: v2.0.525 clojure-lsp version used: 2025.08.25-14.21.46 clj-kondo version used: 2025.07.28 Ubuntu 24.04.3
You can see how I select both the lines with "hello" and "world", but only the println with "hello" gets added to the new function. (I tried to reproduce this with emacs' clojure-lsp, but it's getting a NPE. I didn't pursue why.) Does this seem like a bug or my misunderstanding of how extract-function would work?
It seems that extract-function's API is
(extract-function zloc uri fn-name db)
so when I see Calva send this
[Trace - 9:13:49 PM] Sending request 'workspace/executeCommand - (59)'.
Params: {
"command": "extract-function",
"arguments": [
"file:///home/jrichard/Projects/Test/pacman2/mytest2.clj",
1,
2,
"new-fn"
]
}
I guess that the 1, 2 part is the start of the zloc? And the zloc is the root of the tree that clojure-lsp uses to do an extract?
If I'm guessing correctly, then clojure-lsp can only extract at a root of a tree, and my trying to select two expressions wouldn't work?Yes, I think it may be that only one expression can be extracted. #lsp is the place to ask about this. Calva sort of only gives clojure-lsp and the VS Code LSP Client this scene.