This extension for VS Code enables you to create UML-compliant Mermaid sequence diagrams from Python code to perform reverse engineering and to gain more knowledge about a piece of code.
- Improved sequencing. If there is a call like
foo(bar(x))
, from now onbar()
will come beforefoo()
as it is actually called first. - Object name matches UML syntax, instead of class:instance, instance :class is used from now on.
- New settings to specify return message label, and to choose what message details you want to see, including sequence numbers, parameters, signatures or nothing.
- Some fixes.
MIT license applies, so it's all free and open. Donation options available in the repo to support further development.
This work is loosely based on VS Code Chartographer, the call graph creating extension from Richard Putra.
Thanks for the valuable advices of arpicheck.
- Create UML-compliant sequence diagram for any function in Mermaid language
- Limit call depth to have higher-level diagrams
- Ignore calls you don't need
- Ignore calls to 3rd party packages, as well as physical and virtual Python environments
- Automatically view created diagrams for preview using Mermaid Editor from tomoyukim
- Automatically save created diagrams (in the format and to the location you set in Mermaid Editor)
-
Click in or point to a function's name.
-
Either
-
Right-click and select PySequenceReverse: Create diagram for this function
or
-
Hit
Ctrl+Shift+P
and start typingPySequenceReverse: Create diagram for this function
, the hit it, too.
-
-
Wait for the diagram to be created and watch out for status messages.
If automated saving and automatically opening diagrams are both enabled, you'll be presented with the diagram once the operation completes. If auto-save is not enabled, first you'll need to save the diagram.
In VS Code, click File > Preferences > Settings, select User or Workspace, expand Extensions and select PySequenceReverse to view and edit settings.
Set the scope of what you would like to see on the sequence diagrams.
List file patterns. Files matching these patterns won't be analyzed. If a call targets an item in such a file, it won't be added to the diagram. Use this to ignore calls that are not of much value or only distract the reader. Logging methods may be a typical example.
Limit code analysis to the current VS Code workspace. Calls targeting anything out of it won't be added to the diagrams. You can use this to not analyze third-party packages.
With this self-explanatory setting. This includes folders named .venv
and .conda
, as well as the Python path set in VS Code Settings, as well as the values set in the Venv folders and Venv Path settings of Python in VS Code Settings.
Settings to control what to do once a diagram is created.
When checked, each diagram you create will be saved automatically to the workspace's root folder, with the file name composed of the name of the function, its containing class or module and workspace-relative path. When not checked, you'll be presented with a dialog to select a location and specify a name for the file.
When checked, the diagram saved automatically or manually will be displayed in VS Code after successful save if Mermaid Editor is installed.
Settings related to the sequence diagrams, their contents and formatting.
Only up this level of nesting will calls be detailed to let you control the amount of information and level of complexity you tolerate on a diagram. When limited depth is reached and there are further function calls to deeper levels, instead of gathering them, a note will let you know next to the relevant method that further details are cut. This way you'll know where to go for further details if you need any.
When checked, messages won't show details (like arguments passed or function signature), only the message name.¸
When checked, no sequence numbers will be shown in front of messages.
When checked, and message details are not omitted, the signatures of the called functions will be shown for messages instead of the parameters passed to the function.
If unchecked, you'll find the parameters there.
Observed only when message details are not omitted.
The label to show on return messages. The default is return value. If you specify an empty value, a space will be used to comply with Mermaid syntax.
PySequenceReverse relies on the "call hierarchy" feature of an LSP server. So, to use PySequenceReverse for your project analysis, you must have a language server extension that supports "call hierarchy."
Mermaid Editor from tomoyukim is required to view Mermaid diagrams.
Support, bug reports, feature requests and other stuff in the GitHub repo.