vvvvalvalval / scope-capture

Project your Clojure(Script) REPL into the same context as your code when it ran
MIT License
576 stars 14 forks source link

Non intrusive support for naming code sites: multi methods #43

Open kloimhardt opened 3 years ago

kloimhardt commented 3 years ago

The following 4 code changes have allowed me to do something like (sc.api/defsc :brk-1) in ClojureScript, which pages in the scope prevailing at the last call to (sc.api/spy {:sc/cs-label :brk-1} ...). I argue that the proposed code changes do not alter the behaviour of scope-capture in any way, as they are basically only switching functions to multimethods.

I did three things in sc.impl: 1) in the map of function make-cs-data I added a key-value pair :sc.cs/label (get opts :sc/cs-label nil) 2) out of function find-ep I made a (defmulti find-ep #(type %2)) (plus defmethod :default) 3) out of function resolve-code-site I also made a multimethod (dispatch function type)

In sc.api I 4 . removed the line ep-id (i/resolve-ep-id ep-id) from macro defsc. This line is rudundant, as the check (validate-ep-identifier ep-id) is triggered by the immediate above call to our (default) resolve-code-site, and the subsequent call to our find-ep does resolve-ep-id ep-id on its own.

With additional definitions of find-ep and resolve-code-site multimethods in my own codebase (here and here), I am able to introduce breakpoints in Clojurescript in the sense described at the beginning.