calva icon indicating copy to clipboard operation
calva copied to clipboard

add command to eval the ns macro of current ns

Open behrica opened this issue 10 months ago • 2 comments

In some situations like mixed Clojure / Java projects with Virgil (see: PR #2724 )

we need to re-evaluate the ns macro of the current ns more often then in "usual Clojure coding", as the (:import ...) of changed java classes needed to be re-evaluated in some situations to pickup changes.

Having a dedicated command which does so, and does not change cursor position, could be very useful.

behrica avatar Feb 11 '25 15:02 behrica

I think it could be good for discoverability to have such a command.

For anyone who sets out to implement it. Calva has dev utilities for finding the current ns form. Currently I think it will find the closest ns or in-ns from the cursor and towards the beginning of the document. We would probably need a version of this that only finds ns forms.

PEZ avatar Feb 11 '25 17:02 PEZ

Just to clarify more the "use case". When working with Virgil, and some Java changes do not "refresh", (I saw it on change of method signatures)

the simplest for the user would be to re-eval all "import" expressions of Java classes which can be spread across the ns. (instead of searching the one for the Java code he has changed, which is an other option)

I am not sure, if there is a way "to find those..." and dynamically re-evaluate them. (so then we would talk about a Calva feature of 're-eval all import' statements

The second best practice is therefore to have all imports in the ns macro, and re-eval only that, when something in Java is not refreshed on Clojure side.

behrica avatar Feb 11 '25 22:02 behrica