microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.67k stars 770 forks source link

Pylance Call Graph Visualizer #6043

Closed ezhang7423 closed 6 days ago

ezhang7423 commented 1 week ago

Hi there! I'm interested in building a visualization tool for python modules using Pylance similar to https://githubnext.com/projects/repo-visualization and https://github.com/scottrogowski/code2flow

This is a resource that I have been referring to: https://markgacoka.medium.com/how-to-visualize-your-codebase-7c4c4d948141.

Is there any advice on how I might go about doing this, and if there's any interest in potentially supporting this within Pylance?

heejaechang commented 1 week ago

@ezhang7423, you might want to use @microsoft/pyright as a library and build a Program to gather the information you need, such as parse trees, walking the tree to find call nodes, and using the type evaluator to find callees and create a call graph. However, pyright is not intended to be used as a library. The API you're using is not a public API and doesn't guarantee backward compatibility. While you can use it for your purposes (assuming you can build or modify any missing or not-working-quite-the-way-you-want parts), it may not meet your exact needs as a compiler service API.