Skip to content

Commit

Permalink
devtools: introduce :beautify-function-names feature
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Jun 2, 2016
1 parent 84501e1 commit 5c84b7a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 13 deletions.
4 changes: 3 additions & 1 deletion resources/unpacked/devtools/front_end/dirac/dirac.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Object.assign(window.dirac, (function() {
"enable-clustered-locals",
"inline-custom-formatters",
"welcome-message",
"clean-urls"];
"clean-urls",
"beautify-function-names"];

function hasFeature(feature) {
var flag = featureFlags[feature];
Expand Down Expand Up @@ -202,6 +203,7 @@ Object.assign(window.dirac, (function() {
hasInlineCFs: hasFeature("inline-custom-formatters"),
hasWelcomeMessage: hasFeature("welcome-message"),
hasCleanUrls: hasFeature("clean-urls"),
hasBeautifyFunctionNames: hasFeature("beautify-function-names"),
hasFeature: hasFeature,
codeAsString: codeAsString,
stringEscape: stringEscape,
Expand Down
14 changes: 14 additions & 0 deletions resources/unpacked/devtools/front_end/externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ var dirac = {
hasWelcomeMessage: true,
/** @type {boolean} */
hasCleanUrls: true,
/** @type {boolean} */
hasBeautifyFunctionNames: true,
/**
* @param {string} code
* @return {string}
Expand Down Expand Up @@ -439,6 +441,18 @@ var dirac = {
*/
nsToRelpath: function(ns, ext) {},

/**
* @param {string} name
* @returns {string}
*/
getFunctionName: function(name) {},

/**
* @param {string} name
* @returns {string}
*/
getFullFunctionName: function(name) {},

/**
* @param {string} source
* @returns {?dirac.NamespaceDescriptor}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ WebInspector.CallStackSidebarPane.prototype = {
WebInspector.CallStackSidebarPane.CallFrame = function(functionName, location, linkifier, debuggerCallFrame, locationPool, asyncCallFrame)
{
WebInspector.UIList.Item.call(this, WebInspector.beautifyFunctionName(functionName), "");
if (dirac.hasBeautifyFunctionNames) {
this.titleElement.title = dirac.getFullFunctionName(functionName);
}
this._location = location;
this._debuggerCallFrame = debuggerCallFrame;
this._asyncCallFrame = asyncCallFrame;
Expand Down
4 changes: 4 additions & 0 deletions resources/unpacked/devtools/front_end/ui/UIUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,10 @@ WebInspector.initializeUIUtils = function(document, themeSetting)
*/
WebInspector.beautifyFunctionName = function(name)
{
if (name && dirac.hasBeautifyFunctionNames) {
return dirac.getFunctionName(name);
}

return name || WebInspector.UIString("(anonymous function)");
}

Expand Down
3 changes: 2 additions & 1 deletion src/background/dirac/background/tools.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
:enable-clustered-locals
:inline-custom-formatters
:welcome-message
:clean-urls])
:clean-urls
:beautify-function-names])

(def last-active-tab-query #js {"lastFocusedWindow" true
"active" true})
Expand Down
44 changes: 35 additions & 9 deletions src/implant/dirac/implant.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,45 @@
(when-let [ns-decl (ns-parse/read-ns-decl reader)]
#js {:name (str (ns-parse/name-from-ns-decl ns-decl))})))

(defn is-cljs-function-name? [munged-name]
(some? (re-matches #"^[^$]+\$[^$]+\$.*$" munged-name))) ; must have at least two dollars but not at the beginning

(defn demunge-ns [munged-name]
(string/replace munged-name "$" "."))

(defn break-and-demunge-name [munged-name]
(let [index (.lastIndexOf munged-name "$")]
(if (= index -1)
["" (demunge munged-name)]
(let [ns (demunge (demunge-ns (.substring munged-name 0 index)))
name (demunge (.substring munged-name (inc index) (.-length munged-name)))]
[ns name]))))

(defn get-function-name [munged-name]
(if (is-cljs-function-name? munged-name)
(second (break-and-demunge-name munged-name))
munged-name))

(defn get-full-function-name [munged-name]
(if (is-cljs-function-name? munged-name)
(string/join "/" (break-and-demunge-name munged-name))
munged-name))

; -- dirac object augumentation ---------------------------------------------------------------------------------------------

; !!! don't forget to update externs.js when touching this !!!
(def dirac-api-to-export
{"feedback" post-feedback!
"initConsole" init-console!
"initRepl" init-repl!
"adoptPrompt" adopt-prompt!
"sendEvalRequest" send-eval-request!
"getVersion" get-version
"getRuntimeTag" get-runtime-tag
"parseNsFromSource" parse-ns-from-source
"nsToRelpath" ns-to-relpath})
{"feedback" post-feedback!
"initConsole" init-console!
"initRepl" init-repl!
"adoptPrompt" adopt-prompt!
"sendEvalRequest" send-eval-request!
"getVersion" get-version
"getRuntimeTag" get-runtime-tag
"parseNsFromSource" parse-ns-from-source
"nsToRelpath" ns-to-relpath
"getFunctionName" get-function-name
"getFullFunctionName" get-full-function-name})

(defn enhance-dirac-object! [dirac]
(doseq [[name fn] dirac-api-to-export]
Expand Down
3 changes: 2 additions & 1 deletion src/options/dirac/options/ui.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
(f/checkbox "Enable friendly locals" data [:options :enable-friendly-locals])
(f/checkbox "Enable clustered locals" data [:options :enable-clustered-locals])
(f/checkbox "Inline Custom Formatters in sources" data [:options :inline-custom-formatters])
(f/checkbox "Enable clean URLs" data [:options :clean-urls])])
(f/checkbox "Enable clean URLs" data [:options :clean-urls])
(f/checkbox "Beautify function names" data [:options :beautify-function-names])])
(f/form-buttons
(f/button "Reset to Defaults" reset-to-defaults!)
(f/button "Save and Exit" save-state-and-exit!))))))
Expand Down
3 changes: 2 additions & 1 deletion src/shared/dirac/options/model.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
:enable-clustered-locals true
:inline-custom-formatters true
:welcome-message true
:clean-urls true})
:clean-urls true
:beautify-function-names true})

(defonce cached-options (atom nil))
(defonce chrome-event-channel (make-chrome-event-channel (chan)))
Expand Down

0 comments on commit 5c84b7a

Please sign in to comment.