I got this kinda working. But... it kinda is a small footgun. In playing around with it, I've accidentally made a bunch of changes to keywords that spread into other files. An example of this is the tests - there's a bunch of :a, which I renamed, and then I had like a dozen files with changes. I can imagine this happening with :id, :name, etc...
I'm wondering if we should start to introduce LSP's needs-confirmation annotation, perhaps for changes that exceed one file?
I hacked clojure-lsp up and sent a reply with needs-confirmation to Calva, and I get this UI:
I can publish the PR as it is now (/soon) though, if people think this behavior is OK for now. We can talk about requesting a refactor preview later...
oh last time I checked there was no way to have a confirmation dialog for this, interested on how you did it, but yes, a dialog is ideal for this
The hack was to make shared/client-changes return this (hardcoded for testing):
{
:document-changes [
{
:text-document {
:version 388,
:uri "file:///home/john/Projects/clojure-lsp/lib/src/clojure_lsp/refactor/mytest4.clj"
},
:edits [
{
:range {
:start { :line 13, :character 0 },
:end { :line 13, :character 10 }
},
:new-text "::my-a-kw5",
:annotation-id "confirmClojureRefactor"
}
]
}
],
:change-annotations {
"confirmClojureRefactor" {:label "Confirm Clojure Refactor",
:needs-confirmation true,
:description "Reviewing keyword replacement in mytest4.clj"
}
}
}
It might actually be useful for other refactorings when they are large.oh I missed that from protocol, that's quite clever! looks good to me, and yes we can use for more commands, I wish there was a way to specify options for user to choose, not only a confirmation yes/no, but that's good for this feature. Just remind that we should check for client capability before returning those (unless it's ok add this and clients that don't support will ignore, I think they will), I can add support for this in emacs lsp-mode later
I think the user can select to allow/disallow changes, so it's a little more than a binary confirmation. It's perhaps not quite as fully featured as Intellij though. > client capability Good call! I filed https://github.com/clojure-lsp/clojure-lsp/issues/2370 for this. I can look at it soon.