Fork me on GitHub
#cursive
<
2024-04-03
>
Ernesto Garcia08:04:19

Hi, is it possible to have validation and code-completion for code inside (comment ...) ?

kolstae13:04:12

code-completion should work as expected inside comment - at least it does in all my projects. I'm not sure what you mean by validation, but some things like manually required stuff is not validated correctly (how could it :thinking_face: )

1
cfleming21:04:53

Code completion does work inside comment blocks at the moment, with some caveats - vars which have been defined inside comment blocks won’t be picked up.

cfleming21:04:48

However, inspections are currently not run inside comment blocks, the initial thinking behind that was that people sometimes have temporary code there which might not be complete or valid, or might refer to other vars etc defined in comment blocks which have not been executed yet. But this is occasionally annoying, since things like the automatic import of classes and namespaces is implemented via inspections, and those don’t work in comment blocks as a result. I’m still thinking about the best way to handle this.

hlship19:04:34

Is there a way to debug namespace reloading in Cursive? On the project I'm working on, I keep changing a namespace, then running tests. The changed namespace seems to reload, but other namespaces that rely on the changed namespace do not; end result is an intermediate namespace captures a reference to a Var's value (e.g., (def captured (changed/f))) and that doesn't reload until I explicitly reload the capturing namespace. Maybe this is normal Cursive behavior, and I've never noticed it before because my code normally has no such globals, but I'm working on an existing project's code.

hlship19:04:51

So I believe the Cursive behavior is a) identify changed namespaces b) work out dependency order c) reload changed namespaces. And that's ok. The trick is to change my code to (defn captured [] (changed/f)) which defers invoking the changed namespace's code until execution time, so it picks up the updated value in the changed/f Var.

cfleming21:04:32

Yes, that’s an accurate way of describing it. I’d actually like to have more sophisticated handling of this, so it could reload namespaces taking into account protocol definitions and multimethods, but there’s nothing like that at the moment.

hlship16:04:24

^-- @U0567Q30W could this be an option?

cfleming05:04:31

Looks like there’s a similar issue: https://github.com/cursive-ide/cursive/issues/2107. I think that might make sense as an option, although as the issue mentions, the dep graph could get pretty huge.

onetom05:04:42

To circumvent the reloading issues with multi-methods, I have a (user/reload-multi-method #'~current-var) REPL Command called Redefine multi-method, which is implemented like this:

(defn reload-multi-method [current-var]
  (let [current-ns (.name (.ns current-var))
        current-sym (.sym current-var)

        namespaces-to-reload
        (into [current-ns]
              (when (instance? clojure.lang.MultiFn @current-var)
                (-> @current-var methods vals
                    (->> (map #(-> % class .getName Compiler/demunge
                                   (.split "/") first symbol))))))]
    (printf "Undefining %s/%s\n" current-ns current-sym)
    (ns-unmap current-ns current-sym)
    (run! (fn [ns-sym]
            (println " Reloading" ns-sym)
            (require ns-sym :reload))
          namespaces-to-reload)))
so I can change the definition of the dispatch function, while ensuring all previous implementation being hooked up to this new definition.