Flagging Symbols

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.

Basic Usage

The simplest way to flag a symbol is to call the flag() method on any symbol:

# Flag a function
function.flag(message="This function needs optimization")

# Flag a class
my_class.flag(message="Consider breaking this into smaller classes")

# Flag a variable
variable.flag(message="Type hints needed here")

When you flag a symbol, two things happen:

  1. A visual flag emoji (🚩) is added as an inline comment
  2. A CodeFlag object is created to track the flag in the system

Language-Specific Behavior

The flag system adapts automatically to the programming language being used:

# Python
# Results in: def my_function():  # 🚩 Review needed
python_function.flag(message="Review needed")

# TypeScript
# Results in: function myFunction() {  // 🚩 Review needed
typescript_function.flag(message="Review needed")

Example: Code Analysis

Here’s an example of using flags during code analysis:

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.

Was this page helpful?