Skip to content

Commit

Permalink
handle [macro] paths, improve std lib path regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Antriel committed Dec 10, 2024
1 parent f0fe6fe commit d4d02e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config.smartLabelsStd ??= true;
config.smartLabelsSrc ??= true;
config.smartLabelsHaxelib ??= true;
config.smartLabelsPrefix ??= true;
config.smartLabelsShowMacro ??= true;
config.smartLabelsCustom ??= [];

const gui = new GUI({ title: 'Config' });
Expand Down Expand Up @@ -100,6 +101,7 @@ labels.add(config, 'smartLabelsStd').name('extract Haxe Std lib');
labels.add(config, 'smartLabelsSrc').name('extract after src/');
labels.add(config, 'smartLabelsHaxelib').name('try extract haxelib paths')
labels.add(config, 'smartLabelsPrefix').name('remove common prefix');
labels.add(config, 'smartLabelsShowMacro').name('mark macros in labels');
addCustomStringValues(labels, 'Custom Smart Labels (Use Capture Group)', config.smartLabelsCustom);

// TODO load state of the GUI?
10 changes: 6 additions & 4 deletions src/createGraph.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ const nodeIds = new Map();
const nodeAtts = new Map();
const edgeAtts = new Map();

const haxeReg = /.+haxe\/.+\/std\/(.+).hx$/;
const importReg = /.+\/import.hx$/;


const labelStd = /.+haxe\/.+\/std\/(.+).hx$/;
const labelStd = /.+haxe[0-9a-f_]*(?:\/.+\/)?std\/(.+).hx$/;
const labelSrc = /.+src\/(.+).hx$/;
const labelHaxelib = [
/.+haxe_libraries\/.+\/.+\/haxelib\/(.+).hx$/,
Expand Down Expand Up @@ -43,6 +41,7 @@ const labelHaxelib = [
* @property {boolean} smartLabelsSrc
* @property {boolean} smartLabelsHaxelib
* @property {boolean} smartLabelsPrefix
* @property {boolean} smartLabelsShowMacro
* @property {{reg:string,enabled:boolean}[]} smartLabelsCustom
*
*/
Expand All @@ -61,6 +60,7 @@ export default function createGraph(deps, config) {
if (config.smartLabelsSrc) activeLabelRegs.push(labelSrc);
if (config.smartLabelsHaxelib) activeLabelRegs.push(...labelHaxelib);

for (const d of deps.keys()) d.label = null; // Reset label in case config changed.
function parseLabel(path) {
for (const r of activeLabelRegs) if (r) {
const matches = r.exec(path);
Expand Down Expand Up @@ -117,7 +117,7 @@ export default function createGraph(deps, config) {

function shouldRemove(/** @type{import("./parser.mjs").DepData} */ data) {
let rem = false;
if (config.hideStd) rem = rem || haxeReg.test(data.path);
if (config.hideStd) rem = rem || labelStd.test(data.path);
if (config.hideImport) rem = rem || importReg.test(data.path);
rem = rem || customRemoves.some(r => r?.test(data.path));

Expand All @@ -137,6 +137,8 @@ export default function createGraph(deps, config) {
if (!nodeAtts.has(node.path)) nodeAtts.set(node.path, {});
const atts = nodeAtts.get(node.path);
atts.label = node.label;
if (config.smartLabelsShowMacro && node.isMacro)
atts.label = '[macro] ' + atts.label;
atts.degree = -1;
graph.addNode(node.path, atts);
posGraph.addNode(node.path, atts);
Expand Down
8 changes: 7 additions & 1 deletion src/parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ export function parse(txt, isDependants = false) {
*/
function getData(path) {
path = path.replaceAll('\\', '/'); // Normalize...
let isMacro = false;
if (path.startsWith('[macro] ')) {
isMacro = true;
path = path.substring('[macro] '.length);
}
let obj = objMap.get(path);
if (obj) return obj;
obj = { path };
obj = { path, isMacro };
objMap.set(path, obj);
deps.set(obj, new Set());
return obj;
Expand All @@ -40,5 +45,6 @@ export function parse(txt, isDependants = false) {
/**
* @typedef {Object} DepData
* @property {string} path
* @property {boolean} isMacro
* @property {string} label
*/

0 comments on commit d4d02e3

Please sign in to comment.