|
| 1 | +--- |
| 2 | +title: "Flagging Symbols" |
| 3 | +description: "Learn how to use symbol flags for debugging, tracking changes, and marking code for review" |
| 4 | +icon: "flag" |
| 5 | +iconType: "solid" |
| 6 | +--- |
| 7 | + |
| 8 | +# Flagging Symbols |
| 9 | + |
| 10 | +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. |
| 11 | + |
| 12 | +## Basic Usage |
| 13 | + |
| 14 | +The simplest way to flag a symbol is to call the `flag()` method on any symbol: |
| 15 | + |
| 16 | +```python |
| 17 | +# Flag a function |
| 18 | +function.flag(message="This function needs optimization") |
| 19 | + |
| 20 | +# Flag a class |
| 21 | +my_class.flag(message="Consider breaking this into smaller classes") |
| 22 | + |
| 23 | +# Flag a variable |
| 24 | +variable.flag(message="Type hints needed here") |
| 25 | +``` |
| 26 | + |
| 27 | +When you flag a symbol, two things happen: |
| 28 | +1. A visual flag emoji (🚩) is added as an inline comment |
| 29 | +2. A `CodeFlag` object is created to track the flag in the system |
| 30 | + |
| 31 | + |
| 32 | +## Language-Specific Behavior |
| 33 | + |
| 34 | +The flag system adapts automatically to the programming language being used: |
| 35 | + |
| 36 | +```python |
| 37 | +# Python |
| 38 | +# Results in: def my_function(): # 🚩 Review needed |
| 39 | +python_function.flag(message="Review needed") |
| 40 | + |
| 41 | +# TypeScript |
| 42 | +# Results in: function myFunction() { // 🚩 Review needed |
| 43 | +typescript_function.flag(message="Review needed") |
| 44 | +``` |
| 45 | + |
| 46 | + |
| 47 | +## Example: Code Analysis |
| 48 | + |
| 49 | +Here's an example of using flags during code analysis: |
| 50 | + |
| 51 | +```python |
| 52 | +def analyze_codebase(codebase): |
| 53 | + for function in codebase.functions: |
| 54 | + # Check documentation |
| 55 | + if not function.docstring: |
| 56 | + function.flag( |
| 57 | + message="Missing docstring", |
| 58 | + ) |
| 59 | + |
| 60 | + # Check error handling |
| 61 | + if function.is_async and not function.has_try_catch: |
| 62 | + function.flag( |
| 63 | + message="Async function missing error handling", |
| 64 | + ) |
| 65 | +``` |
| 66 | + |
| 67 | +This feature is particularly useful when building, and iterating on the symbols that you are trying to modify. |
0 commit comments