Skip to content

Commit

Permalink
implement code completions for shadow-cljs
Browse files Browse the repository at this point in the history
unfortunately namespaces evaluated via "load JS" do not work because
they are missing source maps
  • Loading branch information
darwin committed Jun 17, 2020
1 parent 709c53b commit 5972027
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions resources/unpacked/devtools/front_end/dirac_lazy/dirac_lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,21 @@ Object.assign(window.dirac, (function () {
* @return {function(string)}
*/
function prepareUrlMatcher(namespaceName) {
const relativeNSPath = dirac.nsToRelpath(namespaceName, 'js');
// shadow-cljs uses slightly different convention to output files
// for example given namespaceName 'my.cool.ns'
// standard clojurescript outputs into directory structure $some-prefix/my/cool/ns.js
// cljs files are placed under the same names
//
// shadow-cljs outputs into flat directory structure cljs-runtime/my.cool.ns.js
// but shadow-cljs maintains tree-like structure for original cljs sources, similar to standard
//
const relativeNSPathStandard = dirac.nsToRelpath(namespaceName, 'js');
const relativeNSPathShadow = relativeNSPathStandard.replace('/', '.');
const parser = document.createElement('a');
return /** @suppressGlobalPropertiesCheck */ function (url) {
const parser = document.createElement('a');
parser.href = url;
return parser.pathname.endsWith(relativeNSPath);
// console.log("URL MATCH", relativeNSPathShadow, parser.pathname);
return parser.pathname.endsWith(relativeNSPathStandard) || parser.pathname.endsWith(relativeNSPathShadow);
};
}

Expand All @@ -356,7 +366,9 @@ Object.assign(window.dirac, (function () {
*/
function parseClojureScriptNamespaces(url, cljsSourceCode) {
if (dirac.DEBUG_CACHES) {
console.log('parseClojureScriptNamespaces ', url, cljsSourceCode);
console.groupCollapsed("parseClojureScriptNamespaces: " + url);
console.log(cljsSourceCode);
console.groupEnd();
}
if (!cljsSourceCode) {
console.warn('unexpected empty source from ' + url);
Expand All @@ -378,18 +390,22 @@ Object.assign(window.dirac, (function () {
*/
function parsePseudoNamespaces(url, jsSourceCode) {
if (dirac.DEBUG_CACHES) {
console.log('parsePseudoNamespaces ', url, jsSourceCode);
console.groupCollapsed("parsePseudoNamespaces: " + url);
console.log(jsSourceCode);
console.groupEnd();
}
if (!jsSourceCode) {
console.warn('unexpected empty source from ' + url);
return [];
}

const result = [];
const re = /goog\.provide\('(.*?)'\);/gm;
// standard clojurescript emits: goog.provide('goog.something');
// shadow-cljs emits: goog.module("goog.something");

This comment has been minimized.

Copy link
@thheller

thheller Jul 2, 2020

It does not?

I mean there are some Closure Library namespaces that use goog.module but shadow-cljs never emits goog.module anywhere for any code it creates?

const re = /goog\.(provide|module)\(['"](.*?)['"]\);/gm;
let m;
while (m = re.exec(jsSourceCode)) {
const namespaceName = m[1];
const namespaceName = m[2];
const descriptor = {
name: namespaceName,
url: url,
Expand Down Expand Up @@ -745,7 +761,7 @@ Object.assign(window.dirac, (function () {
return;
}

// we simply extract names from all matching source maps and then we filter then to match our namespace name and
// we simply extract names from all matching source maps and then we filter them to match our namespace name and
// deduplicate them
const results = [];
for (const uiSourceCode of matchingSourceCodes) {
Expand Down

0 comments on commit 5972027

Please sign in to comment.