Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Stack Graph of Nested Dirs/Files - Question #100

Closed
maxwnewcomer opened this issue Aug 24, 2022 · 2 comments
Closed

Creating Stack Graph of Nested Dirs/Files - Question #100

maxwnewcomer opened this issue Aug 24, 2022 · 2 comments

Comments

@maxwnewcomer
Copy link
Contributor

I was wondering what way is suggested to build a stack graph of nested directories with files in those directories. Would it involve a recursive call on directories and then calling StackGraph::add_from_graph(someMasterGraph, fileStackGraph);? Is there any example tsg_source anyone would be willing to provide to create nodes for each directory and nodes for each file, then connect the files to the directory/would that even work? I'm essentially looking to create something like this:
Screen Shot 2022-08-24 at 10 38 06 AM

with each f*.py having their own stack graph (that of course connect files/methods/functions with the right definitions, possibly from directories up or across).

Any suggestions/directions I should head?

I really think what y'all have built is so neat, just trying to learn how to use it! Super cool stuff.

@hendrikvanantwerpen
Copy link
Collaborator

Hi @maxwnewcomer! Good question. What you are trying to achieve is certainly possible. You'll need to orchestrate a little using the API to make it happen. The general structure would be something like this:

  1. For each directory in the tree (from top to bottom), create the nodes for that directory, and build the directory structure by creating edges between those nodes. This wouldn't be done using TSG, because that requires a syntax tree, which directories don't have. So you'll have to do that programmatically using the API. Create a file handle for each directory with StackGraph::add_file and create nodes with the other methods in StackGraph for each directory.
  2. Build the stack graphs for the f*.py files using the TSG file using StackGraphLanguage.html::build_stack_graph_into. To make the connection with the containing directory, add global variables with the nodes files should connect to. In the TSG, declare that global variable, e.g. global DIR_NODE, and then add edges as you would with the ROOT_NODE.

Hope this helps to get going!

@maxwnewcomer
Copy link
Contributor Author

Yes this makes so much sense, thank you so much for the clarification! Going to close, but will reopen if I have any further questions. Again, thanks so much.

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

No branches or pull requests

2 participants