Skip to content

Commit 6ecad9c

Browse files
authored
Adds guide for using symbol.flag to docs (#288)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed
1 parent bcf53f3 commit 6ecad9c

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
"building-with-codegen/traversing-the-call-graph",
138138
"building-with-codegen/react-and-jsx",
139139
"building-with-codegen/codebase-visualization",
140+
"building-with-codegen/flagging-symbols",
140141
"building-with-codegen/calling-out-to-llms",
141142
"building-with-codegen/reducing-conditions"
142143
]

0 commit comments

Comments
 (0)