Extracting to def, extracting to function
@ericdallo what about the private question, I took a look on the configs, but I could not find anything that I could use to disable that. The closest is :use-metadata-for-privacy? but that only configures the way how the visibility shoulb be set
Ah we have no option for that, also not sure it's really worth it to be honest
Since we are not using these visibility attributes therefore it is quite annoying to remove them all the time
There are code actions to toggle private in a function which may help
Feel free to open a issue to add a flag for that tho
Thank you!
@ikaraszi just pushed to master this via :private-by-default-on-extract? setting, would be nice if you could test the nightly build available in a few mins in #clojure-lsp-builds
Wow! Amazing, sure thing!
$ ./install --version nightly --dir ~/bin
Downloading to /var/folders/rp/rmpzy6ls5clcgzlw2bymxnqh0000gn/T/tmp.bMPTkecmrl
[clojure-lsp-native-macos-aarch64.zip]
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of clojure-lsp-native-macos-aarch64.zip or
clojure-lsp-native-macos-aarch64.zip.zip, and cannot find clojure-lsp-native-macos-aarch64.zip.ZIP, period. I believe the master install script is broken
usually this happens when nightly build didn't finish yet
https://github.com/clojure-lsp/clojure-lsp/actions/runs/23744914195/job/69171165011
I set the :private-by-default-on-extract? to true in my .lsp/config.edn
haha, it should be false
It does not work for me 😞
Neither for the Extract to def, nor for Extract function
clojure-lsp 2026.03.30-12.34.10-nightly
clj-kondo 2026.01.20-SNAPSHOT.lsp/config.edn:
{:clean {:ns-import-classes-indentation :same-line
:sort {:ns true
:require true
:import true
:import-classes {:classes-per-line -1}
:refer {:max-line-length 120}}}
:private-by-default-on-extract? false
:test-locations-regex #{"^/test/metric/"}}what function are you trying so I can test the same
lsp-execute-code-action
I mean the code, can you try a simpler function and paste here
(defn x []
(prn :foo))My cursor is at the opening paren of (prn :foo)
Wait, it started the wrong lsp
Works, like a charm!
(I had an explicit lsp-clojure-custom-server-command set because of our devenv setup)
good!
Thank you very much!
youre welcome!
I have two questions here related to this functionality:
1. Can I somehow configure clojure-lsp to not use private defs or defns when I do extraction?
2. Wouldn’t it be better instead of coming up with new-value and new-function it would prompt how to name these? The TypeScript LSP does something like that
Because these are really great features and I use them often, but I need to remove the visibility and rename them every time
(Perhaps this is a divisive opinion, but I believe visibility only matters for public libraries, but for private ones they are in the way and they don’t help much)
for the names, you can pass in a name with your codeAction request and it'll use that. it takes [file-uri, row, col, name] and the name is optional
I guess then my Emacs integration needs to be changed somehow
i don't know how emacs works, but for vim, i could either run "call codeAction at cursor" and then it would prompt for which code action to run and execute without any name prompts, or i could write a custom function to prompt for the name and then call the specific action myself
I’ll check how that can be done with Emacs, thanks for the directions!
This is something I want to add in the future somehow, the worst thing is the LSP spec not supporting prompts in code actions that's why we don't do that, but I think we can try some workaround to the spec to achieve that
The way how the TypeScript LSP (or the integration) does is that it first extracts the thing then let’s you rename that
Yeah that sounds like an interesting approach