Skip to content

Adding function information to the /render page#134

Merged
tmr232 merged 80 commits into
tmr232:mainfrom
AlonBilman:issue#94
Sep 8, 2025
Merged

Adding function information to the /render page#134
tmr232 merged 80 commits into
tmr232:mainfrom
AlonBilman:issue#94

Conversation

@AlonBilman

Copy link
Copy Markdown
Contributor

Hey Tamir!

We've added function info to the render page - it updates only when fetching from GitHub (via URL).
Currently, most of the code is in App.svelte.
Here are some example links to test locally (port 5173):
1
2
3
4
5
6
7
8
We are waiting for your feedback and hopefully it meets your standards.

@tmr232 tmr232 changed the title Issue#94 Adding function information to the /render page Mar 19, 2025
@tmr232 tmr232 self-requested a review March 19, 2025 18:36

@tmr232 tmr232 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Alon,

Thanks for your contribution!

I went over it, and there are a few things that need more work.
There's a bit of code to change and move around, and tests that need to be written.

Additionally, I think there are visual-design changes required:

  • The current color is shared for both the dark and light themes, and only kinda works with either. I think it is better to use different colors for the different themes. This is especially important on the light theme, that currently has very low contrast of text and background.
  • As this is a programming tool, and we're presenting data, I think a monospaced font will be a better fit.
  • There is currently a lot of spacing in the display. Between the lines and between the labels and the info. I think it should be tightened.
  • I think the text should be selectable. There is no reason to prevent selection.
  • I think it'll be better for the data to be presented under the controls and not on the opposite side
  • Maybe it's worth it to add the project and filepath as well as the function name?

image
image

If you have any disagreement regarding the visual side - please let me know!

Last but not least - please make sure you run the linters (bun lint) and they pass before submitting your code. Note that this is critical, and in most cases I would not review code that does not pass the automated checks.

Comment thread CHANGELOG.md Outdated
Comment thread src/render/src/app.css Outdated
Comment thread src/render/src/App.svelte Outdated
Comment thread src/render/src/App.svelte Outdated
Comment thread src/render/src/App.svelte Outdated
Comment thread src/render/src/App.svelte Outdated
Comment thread src/render/src/App.svelte Outdated
Comment thread src/render/src/App.svelte Outdated
Comment thread src/render/src/App.svelte Outdated
Comment thread src/render/src/app.css Outdated
@AlonBilman

Copy link
Copy Markdown
Contributor Author

Hey Tamir!

First of all, thank you for reviewing the code!

Regarding linting:
When running bun lint, it modifies the entire codebase, resulting in 100+ changes.
Is there a way to apply the linter to a specific file? Running bun lint <file path> also seems to modify everything.

Secondly, in CONTRIBUTING.md, there is a mention of the command bun check but I couldn’t get it to work. It says there is no script called "check."
Could you please clarify how to run this command correctly? - I believe this is the reason the code didn't pass the automation.

Regarding the visual aspects - any preferences you have will be applied

Of course, all your comments will be addressed, fixed, and modified accordingly.

Thanks again for the review! changes are on the way :)

@tmr232

tmr232 commented Mar 20, 2025

Copy link
Copy Markdown
Owner

Regarding linting: When running bun lint, it modifies the entire codebase, resulting in 100+ changes. Is there a way to apply the linter to a specific file? Running bun lint <file path> also seems to modify everything.

The linters passing for all files are required for merging the code, you can see the failing checks at https://github.com/tmr232/function-graph-overview/actions/runs/13949594615/job/39061318568?pr=134
If you're getting a large number of changes, especially in files you did not edit yourself, it is likely that your tools are not up to date as I recently replaced prettier with biome. Try running bun install again and then bun lint.

Secondly, in CONTRIBUTING.md, there is a mention of the command bun check but I couldn’t get it to work. It says there is no script called "check." Could you please clarify how to run this command correctly? - I believe this is the reason the code didn't pass the automation.

That's my bad - I changed the command from bun check to bun lint and forgot to update the docs.

@AlonBilman AlonBilman closed this Mar 23, 2025
@AlonBilman AlonBilman deleted the issue#94 branch March 23, 2025 13:50
@AlonBilman AlonBilman restored the issue#94 branch March 23, 2025 14:04
@tmr232 tmr232 reopened this Mar 23, 2025
AlonBilman and others added 4 commits August 20, 2025 13:16
Started testing function name extraction on C++ code.
Found multiple issues that need fixing -this part seems to be the hardest so far.
BUT hey, we're passing linter... :)
Comment thread src/control-flow/query-utils.ts Outdated
* @param tag - The capture tag name to filter by.
*
*/
export function extractTaggedValueFromTreeSitterQuery(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality is replicating the functionality of the block-matcher.ts file.
Unless you have a good reason not to use it - I'd prefer to used the existing code to maintain consistency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, so I'm trying to replace this function and I wanted to ask a few questions.

In the file block-matcher.ts, the function matchQuery returns only the first match.
That works pretty well for me, except for a couple of small cases.

In my function I'm using captures, which give me all the captures from all matches.
This is sometimes useful, for example when there are multiple assignments to multiple functions.
For instance, in Go:

var x, y = func() {}, func() {}

Maybe I should add a capture function to block-matcher.ts and export it?
I'd really like to hear a suggestion.

Just shooting an idea:
what if matchQuery would return all the matches,
but in the class the function match still return just the first one?
Then I could also add a function called matchAll that returns all the matches.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this in another branch earlier, it helps me a bit.
Do you want me to keep it, or better not change this file?
Link to diffs (only block-matcher.ts)

Comment thread src/control-flow/query-utils.ts Outdated
Comment thread src/control-flow/cfg-typescript.ts Outdated
Comment thread src/control-flow/function-utils.ts Outdated
Comment thread src/test/extractNameTypescript.test.ts Outdated
Comment thread src/test/extractNameTypescript.test.ts Outdated
Comment on lines +20 to +31
test("arrow variations", () => {
const code1 = "<T,>(value: T): T[] => {};";
expect(namesFrom(code1)).toEqual(["<anonymous>"]);

const code2 = `
function f() {
const b = n => n + 1;
const c = async () => { return 1; };
const d = () => () => {};
}
`;
expect(namesFrom(code2)).toEqual(["f", "b", "c", "d", "<anonymous>"]);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this into 2 tests.

Comment thread src/test/extractNameTypescript.test.ts Outdated
Comment on lines +36 to +45
test("function expression variants", () => {
const code1 = "const myFunction = function(name: string): string {};";
expect(namesFrom(code1)).toEqual(["myFunction"]);

const code2 = "const sum = function add(): number {};";
expect(namesFrom(code2)).toEqual(["add"]);

const code3 = "function(name: string): string {};";
expect(namesFrom(code3)).toEqual(["<anonymous>"]);
});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks repeat the same pattern. Please make them into a parameterized test instead.
Repeats.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, will do

Comment thread src/test/extractNameTypescript.test.ts Outdated
Comment thread src/control-flow/function-utils.ts Outdated
Comment thread src/control-flow/cfg-python.ts Outdated
@AlonBilman AlonBilman requested a review from tmr232 September 1, 2025 22:25

@tmr232 tmr232 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
Still a few changes needed, but they are minor.

Comment thread src/test/extractNameGo.test.ts Outdated
Comment on lines +138 to +159
describe("Go: keyed elements - not supported", () => {
test("simple keys", () => {
const code = `
var _ = map[interface{}]func(){
"simple": func() {},
'r': func() {},
fmt.Sprint(1): func() {},
T(1): func() {},
[2]int{1,2}: func() {},
1 + 2: func() {},
}
`;
expect(namesFrom(code)).toEqual([
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
]);
});
});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but this doesn't really make sense to me. Feels really far fetched.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we remove it?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Comment thread src/control-flow/query-utils.ts Outdated
/**
* Extracts the text content of syntax tree nodes captured by a Tree-sitter query.
*
* @param func - The syntax node from which to extract the tree.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be node, not func.

Comment thread src/control-flow/query-utils.ts Outdated
*
* @param func - The syntax node from which to extract the tree.
* @param query - The Tree-sitter query string to execute.
* @param tag - The capture tag name to filter by.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to captureName to be consistent with tree-sitter terminology.

Comment thread src/control-flow/function-utils.ts Outdated
* Mapping of languages to their function name extraction functions.
* This ensures all supported languages have extractors via TypeScript typing.
*/
const functionNameExtractors: Record<

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move these into the language definition in each cfg-<language>.ts file, and then grab it from the mapping in cfg.ts instead of creating an extra one.

Comment thread src/control-flow/cfg-typescript.ts
Comment thread src/render/src/App.svelte Outdated
@@ -106,8 +157,10 @@ async function getFunctionByLine(
function setBackgroundColor(colors: "light" | "dark") {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to rename to applyColors or similar, now that we're not only setting the background color!

Comment thread src/render/src/App.svelte

if (params.type === "GitHub") {
codeUrl = params.codeUrl;
const { func, language } = await fetchFunctionAndLanguage(params);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we're fetchign this twice, but I guess we'll have to do for now...

Comment thread src/render/src/App.svelte
Comment on lines +398 to +422
{#if functionAndCFGMetadata}
<!-- Metadata display -->
{#if metadataFields.some(field => showMetadata[field.key] && field.value() !== undefined)}
<div class="metadata" class:panel-open={isPanelOpen}>
{#each metadataFields.filter(field => field.value() !== undefined) as { key, label , value}}
{#if showMetadata[key]}
<span>{label}: {value()}</span>
{/if}
{/each}
</div>
{/if}
<button class="panel-toggle" onclick={togglePanel}>
{isPanelOpen ? '→' : '←'}
</button>
<!-- Control panel -->
<div class="control-panel" class:open={isPanelOpen}>
<h3>Display Options</h3>
{#each metadataFields.filter(field => field.value() !== undefined) as { key, label }}
<label>
<input type="checkbox" bind:checked={showMetadata[key]} />
{label}
</label>
{/each}
</div>
{/if}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the indentation here.

Comment thread src/render/src/App.svelte Outdated
// Update CFG metadata
const nodeCount: number = CFG.graph.order;
const edgeCount: number = CFG.graph.size;
const cyclomaticComplexity: number = CFG.graph.size - nodeCount + 2; // (https://en.wikipedia.org/wiki/Cyclomatic_complexity)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the comment to above the line, no need for the line to be this long...

Comment thread src/render/src/App.svelte Outdated
const cyclomaticComplexity: number = CFG.graph.size - nodeCount + 2; // (https://en.wikipedia.org/wiki/Cyclomatic_complexity)

return {
functionData: name && lineCount ? { name, lineCount, language } : undefined,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a proper if, or at least use parenthesis around the condition. Readability counts!

Bennahmias and others added 5 commits September 7, 2025 20:32
removed an unused case in findVariableBinding for TypeScript
Hopefully I did it right, and buherator doesn't count as a surname :-)
@AlonBilman AlonBilman requested a review from tmr232 September 7, 2025 22:13

@tmr232 tmr232 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@tmr232 tmr232 merged commit de661a6 into tmr232:main Sep 8, 2025
@AlonBilman

Copy link
Copy Markdown
Contributor Author

Thank you Tamir!
It was a great journey.
We learned a lot, and it means a lot that we made it happen :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants