Skip to content

Fixed broken links caught by mintlify #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions docs/api-reference/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Welcome to the Codegen API reference. This documentation covers the core classes
and call sites.
</Card>
<Card
title="CallGraph"
title="Symbol"
icon="diagram-project"
href="/api-reference/core/CallGraph"
href="/api-reference/core/Symbol"
>
Navigate function calls and dependencies throughout your codebase.
Represents a symbol in your codebase, includes functions, classes, and more.
</Card>
</CardGroup>

Expand All @@ -45,24 +45,23 @@ Welcome to the Codegen API reference. This documentation covers the core classes

### Code Analysis

- [Finding Functions](/api-reference/core/Codebase#find_function)
- [Analyzing Dependencies](/api-reference/core/CallGraph#get_dependencies)
- [Working with ASTs](/api-reference/core/File#get_ast)
- [Type Information](/api-reference/core/Function#get_type)
- [Finding Functions](/api-reference/core/Codebase#get-function)
- [Analyzing Dependencies](/api-reference/core/Symbol#dependencies)
- [Analyzing Usages](/api-reference/core/Symbol#usages)

### Code Transformation

- [Editing Files](/api-reference/core/File#edit)
- [Managing Imports](/api-reference/core/File#add_import)
- [Renaming Symbols](/api-reference/core/Codebase#rename)
- [Moving Code](/api-reference/core/File#move)
- [Managing Imports](/api-reference/core/SourceFile#add-import-from-import-string)
- [Renaming Symbols](/api-reference/core/Symbol#set-name)
- [Managing Return Types](/api-reference/core/Function#set-return-type)
- [Moving Code](/api-reference/core/Symbol#move-to-file)

### React & TypeScript

- [Component Analysis](/api-reference/typescript/ReactComponent)
- [Type Definitions](/api-reference/typescript/TypeDefinition)
- [JSX Manipulation](/api-reference/typescript/JSXElement)
- [Props & State](/api-reference/typescript/Props)
- [JSX Components](/api-reference/typescript/JSXElement)
- [Props & State](/api-reference/typescript/JSXProp)
- [Type Aliases](/api-reference/typescript/TSTypeAlias)

<Note>
Each class and function includes detailed examples and common use cases. Use
Expand Down
2 changes: 1 addition & 1 deletion docs/building-with-codegen/at-a-glance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Learn how to use Codegen's core APIs to analyze and transform code.
<Card
title="Symbols, Functions and Classes"
icon="pen-to-square"
href="/building-with-codegen/symbols-functions-and-classes"
href="/building-with-codegen/the-editable-api"
>
Master the core abstractions for manipulating code safely and effectively.
</Card>
Expand Down
2 changes: 1 addition & 1 deletion docs/building-with-codegen/class-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ icon: "cube"
iconType: "solid"
---

The [Class](/api-reference/core/class.py) API extends the [Symbol](/building-with-codegen/symbol-api) API to support methods, attributes, and inheritance hierarchies.
The [Class](/api-reference/core/Class) API extends the [Symbol](/building-with-codegen/symbol-api) API to support methods, attributes, and inheritance hierarchies.

## Methods and Method Usages

Expand Down
4 changes: 2 additions & 2 deletions docs/building-with-codegen/collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ icon: "layer-group"
iconType: "solid"
---

Codegen enables traversing and manipulating collections through the [Collection](../api-reference/core/Collection) class and its implementations [List](../api-reference/core/List) and [Dict](../api-reference/core/Dict).
Codegen enables traversing and manipulating collections through the [List](/api-reference/core/List) and [Dict](/api-reference/core/Dict) classes.

These APIs work consistently across Python and TypeScript while preserving formatting and structure.

## Core Concepts

The [Collection](../api-reference/core/Collection) class provides a consistent interface for working with ordered sequences of elements. Key features include:
The [List](/api-reference/core/List) and [Dict](/api-reference/core/Dict) classes provide a consistent interface for working with ordered sequences of elements. Key features include:

- Standard sequence operations (indexing, length, iteration)
- Automatic formatting preservation
Expand Down
10 changes: 5 additions & 5 deletions docs/building-with-codegen/dependencies-and-usages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ This document explains how to use the dependency and usage tracking APIs in Code

Codegen provides two main ways to track relationships between symbols:

- [`.dependencies`](../api-reference/core/Symbol#dependencies) / [`.get_dependencies(...)`](../api-reference/core/Symbol#get_dependencies) - What symbols does this symbol depend on?
- [`.usages`](../api-reference/core/Symbol.mdx#usages) / [`.usages(...)`](../api-reference/core/Symbol.mdx#usages) - Where is this symbol used?
- [`.dependencies`](/api-reference/core/Symbol#dependencies) / [`.get_dependencies(...)`](/api-reference/core/Symbol#get-dependencies) - What symbols does this symbol depend on?
- [`.usages`](/api-reference/core/Symbol#usages) / [`.usages(...)`](/api-reference/core/Symbol#usages) - Where is this symbol used?

Dependencies and usages are inverses of each other. For example, given the following input code:

Expand Down Expand Up @@ -161,14 +161,14 @@ deps = my_class.get_dependencies(
```python
# Check if a symbol is unused
def is_dead_code(symbol):
return len(symbol.usages()) == 0
return not symbol.usages

# Find all unused functions in a file
dead_functions = [f for f in file.functions if is_dead_code(f)]
dead_functions = [f for f in file.functions if not f.usages]
```

<Tip>
See [Finding Unused Code](/tutorials/dead-code) to learn more about finding
See [Deleting Dead Code](/tutorials/deleting-dead-code) to learn more about finding
unused code.
</Tip>

Expand Down
36 changes: 14 additions & 22 deletions docs/building-with-codegen/editables-and-behaviors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ This guide explains the key behaviors and how to use them effectively.

## Core Behaviors

- [`HasName`](../api-reference/interfaces/HasName): For elements with names (functions, classes, variables)
- [`HasValue`](../api-reference/interfaces/HasValue): For elements with values (variables, parameters)
- [`HasBlock`](../api-reference/interfaces/HasBlock): For elements containing code blocks (functions, classes)
- [`HasAttribute`](../api-reference/interfaces/HasAttribute): For elements that can have attributes accessed
- [`Editable`](../api-reference/interfaces/Editable): For elements that can be safely modified ([learn more](/building-with-codegen/the-editable-api))
- [`HasName`](/api-reference/core/HasName): For elements with names (functions, classes, variables)
- [`HasValue`](/api-reference/core/HasValue): For elements with values (variables, parameters)
- [`HasBlock`](/api-reference/core/HasBlock): For elements containing code blocks (functions, classes)
- [`Editable`](/api-reference/core/Editable): For elements that can be safely modified ([learn more](/building-with-codegen/the-editable-api))

## Working with Names

The [`HasName`](../api-reference/interfaces/HasName) behavior provides APIs for working with named elements:
The [`HasName`](/api-reference/core/HasName) behavior provides APIs for working with named elements:

```python
# Access the name
Expand All @@ -36,7 +35,7 @@ name_node = function.get_name()

## Working with Values

The [`HasValue`](../api-reference/interfaces/HasValue) behavior provides APIs for elements that have values:
The [`HasValue`](/api-reference/core/HasValue) behavior provides APIs for elements that have values:

```python
# Access the value
Expand All @@ -53,7 +52,7 @@ if variable.value is not None:

## Working with Code Blocks

The [`HasBlock`](../api-reference/interfaces/HasBlock) behavior provides APIs for elements containing code:
The [`HasBlock`](/api-reference/core/HasBlock) behavior provides APIs for elements containing code:

```python
# Access the code block
Expand All @@ -77,20 +76,20 @@ for fcall in function.function_calls:

## Working with Attributes

The [`HasAttribute`](../api-reference/interfaces/HasAttribute) behavior provides APIs for attribute access:
The [get_attribute](/api-reference/core/Class#get-attribute) method provides APIs for attribute access:

```python
# Resolve attributes
attr = obj.resolve_attribute("property_name")
if attr:
print(f"Found attribute: {attr.name}")

# Common patterns
class_attr = class_def.resolve_attribute("class_var")
class_attr = class_def.get_attribute("attribute_name")
if class_attr:
print(f"Class variable value: {class_attr.value.source}")
```

<Info>
Learn more about [working with Attributes
here](/building-with-codegen/class-api#class-attributes).
</Info>

## Behavior Combinations

Many code elements inherit multiple behaviors. For example, a function typically has:
Expand All @@ -111,10 +110,3 @@ function.add_decorator("@timer")
function.edit("def process_input():\n pass")
```

## Best Practices

1. **Use Behavior APIs**: Prefer using behavior methods over direct manipulation
2. **Check for None**: Some behavior properties may return None (e.g., value, docstring)
3. **Update References**: Use methods like `rename()` that handle reference updates
4. **Combine Behaviors**: Take advantage of behavior combinations for complex operations
5. **Preserve Context**: Let the behaviors handle formatting and context preservation
2 changes: 1 addition & 1 deletion docs/building-with-codegen/files-and-directories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ if main_function:
Files themselves are [`Editable`](../api-reference/core/Editable.mdx) objects, just like Functions and Classes.

<Tip>
Learn more about the [Editable API](/building-with-codegen/editable-api).
Learn more about the [Editable API](/building-with-codegen/the-editable-api).
</Tip>

This means they expose many useful operations, including:
Expand Down
24 changes: 9 additions & 15 deletions docs/building-with-codegen/inheritable-behaviors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ This guide explains the key behaviors and how to use them effectively.

## Core Behaviors

- [HasName](../api-reference/core/HasName): For elements with [Names](/api-reference/core/Name) (Functions, Classes, Assignments, etc.)
- [HasValue](../api-reference/core/HasValue): For elements with [Values](/api-reference/core/Value) (Arguments, Assignments, etc.)
- [HasBlock](../api-reference/core/HasBlock): For elements containing [CodeBlocks](/api-reference/core/CodeBlock) (Files, Functions, Classes)
- [HasAttribute](../api-reference/core/HasAttribute): For elements with [Attributes](/api-reference/core/Attribute) (Classes, Types, Inferfaces, etc.)
- [Editable](../api-reference/core/Editable): For elements that can be safely modified ([learn more](/building-with-codegen/the-editable-api))
- [HasName](/api-reference/core/HasName): For elements with [Names](/api-reference/core/Name) (Functions, Classes, Assignments, etc.)
- [HasValue](/api-reference/core/HasValue): For elements with [Values](/api-reference/core/Value) (Arguments, Assignments, etc.)
- [HasBlock](/api-reference/core/HasBlock): For elements containing [CodeBlocks](/api-reference/core/CodeBlock) (Files, Functions, Classes)
- [Editable](/api-reference/core/Editable): For elements that can be safely modified ([learn more](/building-with-codegen/the-editable-api))

<Note>These "behaviors" are implemented as inherited classes.</Note>

## Working with Names

The [HasName](../api-reference/core/HasName) behavior provides APIs for working with named elements:
The [HasName](/api-reference/core/HasName) behavior provides APIs for working with named elements:

```python
# Access the name
Expand All @@ -38,7 +37,7 @@ name_node = function.get_name()

## Working with Values

The [HasValue](../api-reference/core/HasValue) behavior provides APIs for elements that have values:
The [HasValue](/api-reference/core/HasValue) behavior provides APIs for elements that have values:

```python
# Access the value
Expand All @@ -55,7 +54,7 @@ if variable.value is not None:

## Working with Code Blocks

The [HasBlock](../api-reference/core/HasBlock) behavior provides APIs for elements containing code:
The [HasBlock](/api-reference/core/HasBlock) behavior provides APIs for elements containing code:

```python
# Access the code block
Expand All @@ -71,16 +70,11 @@ printS(block.source)

## Working with Attributes

The [HasAttribute](api-reference/core/HasAttribute) behavior provides APIs for attribute access:
The [get_attribute](/api-reference/core/Class#get-attribute) method provides APIs for attribute access:

```python
# Resolve attributes
attr = obj.resolve_attribute("property_name")
if attr:
print(f"Found attribute: {attr.name}")

# Common patterns
class_attr = class_def.resolve_attribute("class_var")
class_attr = class_def.get_attribute("attribute_name")
if class_attr:
print(f"Class variable value: {class_attr.value.source}")
```
Expand Down
22 changes: 11 additions & 11 deletions docs/building-with-codegen/language-support.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ TSCodebaseType = Codebase[

Every code element has both a Python and TypeScript implementation that inherits from a common base class. For example:

- [`Function`](../api-reference/core/Function)
- [`PyFunction`](../api-reference/python/function.py)
- [`TSFunction`](../api-reference/typescript/function.py)
- [`Class`](../api-reference/core/Class)
- [`PyClass`](../api-reference/python/class.py)
- [`TSClass`](../api-reference/typescript/class.py)
- [`Import`](../api-reference/core/Import)
- [`PyImport`](../api-reference/python/import.py)
- [`TSImport`](../api-reference/typescript/import.py)
- [`Function`](/api-reference/core/Function)
- [`PyFunction`](/api-reference/python/PyFunction)
- [`TSFunction`](/api-reference/typescript/TSFunction)
- [`Class`](/api-reference/core/Class)
- [`PyClass`](/api-reference/python/PyClass)
- [`TSClass`](/api-reference/typescript/TSClass)
- [`Import`](/api-reference/core/Import)
- [`PyImport`](/api-reference/python/PyImport)
- [`TSImport`](/api-reference/typescript/TSImport)

...

Expand Down Expand Up @@ -91,8 +91,8 @@ for function in codebase.functions:

Some features are only available in TypeScript codebases:

- **Types and Interfaces**: TypeScript's rich type system ([`TSType`](../api-reference/typescript/type.py), [`TSInterface`](../api-reference/typescript/interface.py))
- **Exports**: Module exports and re-exports ([`TSExport`](../api-reference/typescript/export.py))
- **Types and Interfaces**: TypeScript's rich type system ([`TSTypeAlias`](/api-reference/typescript/TSTypeAlias), [`TSInterface`](/api-reference/typescript/TSInterface))
- **Exports**: Module exports and re-exports ([`TSExport`](/api-reference/typescript/TSExport))
- **JSX/TSX**: React component handling (see [React and JSX](/building-with-codegen/react-and-jsx))

Example of TypeScript-specific features:
Expand Down
4 changes: 2 additions & 2 deletions docs/building-with-codegen/parsing-codebases.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ icon: "power-off"
iconType: "solid"
---

The primary entrypoint to programs leveraging Codegen is the [Codebase](../api-reference/core/Codebase) class.
The primary entrypoint to programs leveraging Codegen is the [Codebase](/api-reference/core/Codebase) class.

## Local Codebases

Expand Down Expand Up @@ -61,5 +61,5 @@ codebase = codegen.from_repo(
Codegen currently supports:

- [Python](/api-reference/python)
- [TypeScript/JavaScript](/api-reference/javascript)
- [TypeScript/JavaScript](/api-reference/typescript)
- [React/JSX](/building-with-codegen/react-and-jsx)
13 changes: 7 additions & 6 deletions docs/building-with-codegen/react-and-jsx.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ GraphSitter exposes several React and JSX-specific APIs for working with modern

Key APIs include:

- [Function.is_jsx](../api-reference/core/Function#is_jsx) - Check if a function contains JSX elements
- [Symbol.jsx_elements](../api-reference/core/Symbol#jsx_elements) - Get all JSX elements in a symbol
- [JSXElement](../api-reference/core/JSXElement) - Manipulate JSX elements
- [JSXProp](../api-reference/core/JSXProp) - Manipulate JSX props
- [Function.is_jsx](/api-reference/typescript/TSFunction#is-jsx) - Check if a function contains JSX elements
- [Class.jsx_elements](/api-reference/typescript/TSClass#jsx-elements) - Get all JSX elements in a class
- [Function.jsx_elements](/api-reference/typescript/TSFunction#jsx-elements) - Get all JSX elements in a function
- [JSXElement](/api-reference/typescript/JSXElement) - Manipulate JSX elements
- [JSXProp](/api-reference/typescript/JSXProp) - Manipulate JSX props

<Tip>
See [React Modernization](/tutorials/react-modernization) for tutorials and
Expand All @@ -35,9 +36,9 @@ is_component = class_def.is_jsx # True for React class components

## Working with JSX Elements

Given a React component, you can access its JSX elements using the [jsx_elements](../api-reference/core/Function#jsx-elements) property.
Given a React component, you can access its JSX elements using the [jsx_elements](/api-reference/typescript/TSFunction#jsx-elements) property.

You can manipulate these elements by using the [JSXElement](../api-reference/core/JSXElement) and [JSXProp](../api-reference/core/JSXProp) APIs.
You can manipulate these elements by using the [JSXElement](/api-reference/typescript/JSXElement) and [JSXProp](/api-reference/typescript/JSXProp) APIs.

```python
# Get all JSX elements in a component
Expand Down
24 changes: 12 additions & 12 deletions docs/building-with-codegen/symbol-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ icon: "shapes"
iconType: "solid"
---

The [`Symbol`](/api-reference/core/symbol.py) is the primary way developers interact with code in Codegen. It maps to how developers think about code - as functions, classes, variables, and other named entities.
The [`Symbol`](/api-reference/core/Symbol) is the primary way developers interact with code in Codegen. It maps to how developers think about code - as functions, classes, variables, and other named entities.

Both the [`Function`](/api-reference/core/function.py) and [`Class`](/api-reference/core/class.py) symbols are subclasses of the [`Symbol`](/api-reference/core/symbol.py) class.
Both the [`Function`](/api-reference/core/Function) and [`Class`](/api-reference/core/Class) symbols are subclasses of the [`Symbol`](/api-reference/core/Symbol) class.

## Accessing Symbols

The [`Codebase`](/api-reference/core/codebase.py) class provides getters and iterators for functions, classes and symbols:
The [`Codebase`](/api-reference/core/Codebase) class provides getters and iterators for functions, classes and symbols:

```python
# Core symbol types
Expand All @@ -34,15 +34,15 @@ All symbols share common APIs for manipulation:

- The [`Editable`](/api-reference/core/Editable) API
- Metadata
- [`symbol.name`](/api-reference/core/symbol.py#name)
- [`symbol.source`](/api-reference/core/symbol.py#source)
- [`symbol.docstring`](/api-reference/core/symbol.py#docstring)
- [`symbol.name`](/api-reference/core/Symbol#name)
- [`symbol.source`](/api-reference/core/Symbol#source)
- [`symbol.docstring`](/api-reference/core/Symbol#docstring)
- Edit operations
- [`symbol.set_docstring`](/api-reference/core/symbol.py#add_comment)
- [`symbol.move_to_file`](/api-reference/core/symbol.py#move-to-file) (see [Moving Symbols](/building-with-codegen/moving-symbols))
- [`symbol.set_docstring`](/api-reference/core/Symbol#add_comment)
- [`symbol.move_to_file`](/api-reference/core/Symbol#move-to-file) (see [Moving Symbols](/building-with-codegen/moving-symbols))
- Graph relations (See [Usages and Dependencies](/building-with-codegen/dependencies-and-usages))
- [`symbol.usages`](/api-reference/core/symbol.py#usages)
- [`symbol.dependencies`](/api-reference/core/symbol.py#dependencies)
- [`symbol.usages`](/api-reference/core/Symbol#usages)
- [`symbol.dependencies`](/api-reference/core/Symbol#dependencies)

## Name operations

Expand Down Expand Up @@ -71,8 +71,8 @@ symbol.insert_after("# end deprecated")

Functions provide special APIs for adding statements to their body:

- [Function.prepend_statements](/api-reference/core/function.py#prepend_statements) - add statements to the start of the function body
- [Function.add_statements](/api-reference/core/function.py#add_statements) - add statements to the end of the function body
- [Function.prepend_statements](/api-reference/core/Function#prepend_statements) - add statements to the start of the function body
- [Function.add_statements](/api-reference/core/Function#add_statements) - add statements to the end of the function body

```python
# Add statements at the start of a function
Expand Down
Loading
Loading