lsp

JR 2025-09-10T15:26:02.830459Z

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?

JR 2025-09-10T15:28:13.834869Z

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

ericdallo 2025-09-10T15:29:42.792299Z

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

ericdallo 2025-09-10T15:30:05.823069Z

you can add a do block wrapping everything and extract-function, but I agree it's not the most convenient

JR 2025-09-10T15:33:21.216159Z

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?

JR 2025-09-10T15:34:07.521149Z

Or maybe another API that takes a list?

ericdallo 2025-09-10T15:34:19.592709Z

yeah, maybe we could evolve the current one to support additional args which would be the end selection, if present it's a selection

JR 2025-09-10T15:34:47.578849Z

Ah, interesting!

JR 2025-09-10T15:35:48.861709Z

Is this something that is reasonable? Like reasonable enough to enter an issue (and maybe I could look at it)?

ericdallo 2025-09-10T15:38:07.214419Z

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

JR 2025-09-10T15:40:08.096259Z

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!

ericdallo 2025-09-10T15:40:53.225169Z

Agree!

ericdallo 2025-09-10T15:40:57.670929Z

thanks

👍 1