Symbol flags are a powerful feature in Codegen that allow you to mark and track specific code elements during development, debugging, or code review processes. Flags can be used to visually highlight code in the editor and can also integrate with various messaging systems.
The simplest way to flag a symbol is to call the flag() method on any symbol:
Copy
Ask AI
# Flag a functionfunction.flag(message="This function needs optimization")# Flag a classmy_class.flag(message="Consider breaking this into smaller classes")# Flag a variablevariable.flag(message="Type hints needed here")
When you flag a symbol, two things happen:
A visual flag emoji (🚩) is added as an inline comment
A CodeFlag object is created to track the flag in the system
Here’s an example of using flags during code analysis:
Copy
Ask AI
def analyze_codebase(codebase): for function in codebase.functions: # Check documentation if not function.docstring: function.flag( message="Missing docstring", ) # Check error handling if function.is_async and not function.has_try_catch: function.flag( message="Async function missing error handling", )
This feature is particularly useful when building, and iterating on the symbols that you are trying to modify.