Am I using extract-method wrong? From poking around at the code, it seems like the extract-method API takes a single location, finds the closest sexp, and extracts that. Naively coming from Java, I had been selecting multiple expressions (with side effects) and puzzling over why extract method didn't work. For example, if I select the printlns expressions with Hello and World below and extract-method, only the Hello println is extracted.
(defn greet []
(println "greeting: ")
(println "Hello")
(println "World"))
Is it that:
• it's not straightforward to pass multiple zlocations to the LSP API, or
• it's not easy to move multiple expression trees, or
• extract-function is trying to save me from myself by making it harder to write side effecting code?
Background info here: https://clojurians.slack.com/archives/CBE668G4R/p1757465470204349 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
the issue would be the first you mentioned: currently we pass only cursor position, not a selection, so you can extract sexprs once per command
you can add a do block wrapping everything and extract-function, but I agree it's not the most convenient
Thanks for answering! Maybe, in theory, it would be possible to add another API like continue-extract-function that puts additional sexpressions into the new function?
Or maybe another API that takes a list?
yeah, maybe we could evolve the current one to support additional args which would be the end selection, if present it's a selection
Ah, interesting!
Is this something that is reasonable? Like reasonable enough to enter an issue (and maybe I could look at it)?
yes, issue welcome, • we first need to understand the API in server for that (https://github.com/clojure-lsp/clojure-lsp/blob/889903c76ea54ff7c0f4a8026ab440d31aa2354f/lib/src/clojure_lsp/feature/command.clj#L80) in a way we avoid breaking changes • I think that won't work for code actions tho, as code action in spec has no range only current cursor position IIRC • change clients/editors to send the range in this command call if calling manually
I'll enter an issue then, and try to be useful at taking a stab at it. It'll be good to learn how this thing works!
Agree!
thanks