diff --git a/docs/api-reference/index.mdx b/docs/api-reference/index.mdx index b8fac7ce1..b674d0941 100644 --- a/docs/api-reference/index.mdx +++ b/docs/api-reference/index.mdx @@ -22,11 +22,11 @@ Welcome to the Codegen API reference. This documentation covers the core classes and call sites. - Navigate function calls and dependencies throughout your codebase. + Represents a symbol in your codebase, includes functions, classes, and more. @@ -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) Each class and function includes detailed examples and common use cases. Use diff --git a/docs/building-with-codegen/at-a-glance.mdx b/docs/building-with-codegen/at-a-glance.mdx index 42dc5bfa5..934716d57 100644 --- a/docs/building-with-codegen/at-a-glance.mdx +++ b/docs/building-with-codegen/at-a-glance.mdx @@ -35,7 +35,7 @@ Learn how to use Codegen's core APIs to analyze and transform code. Master the core abstractions for manipulating code safely and effectively. diff --git a/docs/building-with-codegen/class-api.mdx b/docs/building-with-codegen/class-api.mdx index 2f42b93a6..70f4ee686 100644 --- a/docs/building-with-codegen/class-api.mdx +++ b/docs/building-with-codegen/class-api.mdx @@ -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 diff --git a/docs/building-with-codegen/collections.mdx b/docs/building-with-codegen/collections.mdx index 91e482bef..c49c21ea2 100644 --- a/docs/building-with-codegen/collections.mdx +++ b/docs/building-with-codegen/collections.mdx @@ -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 diff --git a/docs/building-with-codegen/dependencies-and-usages.mdx b/docs/building-with-codegen/dependencies-and-usages.mdx index 9a0f8e90a..21ad0f0da 100644 --- a/docs/building-with-codegen/dependencies-and-usages.mdx +++ b/docs/building-with-codegen/dependencies-and-usages.mdx @@ -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: @@ -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] ``` - 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. diff --git a/docs/building-with-codegen/editables-and-behaviors.mdx b/docs/building-with-codegen/editables-and-behaviors.mdx index d4b559e49..daf87984c 100644 --- a/docs/building-with-codegen/editables-and-behaviors.mdx +++ b/docs/building-with-codegen/editables-and-behaviors.mdx @@ -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 @@ -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 @@ -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 @@ -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}") ``` + + Learn more about [working with Attributes + here](/building-with-codegen/class-api#class-attributes). + + ## Behavior Combinations Many code elements inherit multiple behaviors. For example, a function typically has: @@ -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 diff --git a/docs/building-with-codegen/files-and-directories.mdx b/docs/building-with-codegen/files-and-directories.mdx index d3dfd12b4..914be1038 100644 --- a/docs/building-with-codegen/files-and-directories.mdx +++ b/docs/building-with-codegen/files-and-directories.mdx @@ -147,7 +147,7 @@ if main_function: Files themselves are [`Editable`](../api-reference/core/Editable.mdx) objects, just like Functions and Classes. - Learn more about the [Editable API](/building-with-codegen/editable-api). + Learn more about the [Editable API](/building-with-codegen/the-editable-api). This means they expose many useful operations, including: diff --git a/docs/building-with-codegen/inheritable-behaviors.mdx b/docs/building-with-codegen/inheritable-behaviors.mdx index bde909bca..f13a64dcc 100644 --- a/docs/building-with-codegen/inheritable-behaviors.mdx +++ b/docs/building-with-codegen/inheritable-behaviors.mdx @@ -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)) These "behaviors" are implemented as inherited classes. ## 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 @@ -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 @@ -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 @@ -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}") ``` diff --git a/docs/building-with-codegen/language-support.mdx b/docs/building-with-codegen/language-support.mdx index 5a5fbef37..b2df734aa 100644 --- a/docs/building-with-codegen/language-support.mdx +++ b/docs/building-with-codegen/language-support.mdx @@ -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) ... @@ -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: diff --git a/docs/building-with-codegen/parsing-codebases.mdx b/docs/building-with-codegen/parsing-codebases.mdx index 446f7dcbe..72d19dca8 100644 --- a/docs/building-with-codegen/parsing-codebases.mdx +++ b/docs/building-with-codegen/parsing-codebases.mdx @@ -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 @@ -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) diff --git a/docs/building-with-codegen/react-and-jsx.mdx b/docs/building-with-codegen/react-and-jsx.mdx index bbb081f98..395a16dd6 100644 --- a/docs/building-with-codegen/react-and-jsx.mdx +++ b/docs/building-with-codegen/react-and-jsx.mdx @@ -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 See [React Modernization](/tutorials/react-modernization) for tutorials and @@ -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 diff --git a/docs/building-with-codegen/symbol-api.mdx b/docs/building-with-codegen/symbol-api.mdx index a25eb6328..ff099a522 100644 --- a/docs/building-with-codegen/symbol-api.mdx +++ b/docs/building-with-codegen/symbol-api.mdx @@ -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 @@ -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 @@ -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 diff --git a/docs/building-with-codegen/traversing-the-call-graph.mdx b/docs/building-with-codegen/traversing-the-call-graph.mdx index b02934f7b..43336bb3d 100644 --- a/docs/building-with-codegen/traversing-the-call-graph.mdx +++ b/docs/building-with-codegen/traversing-the-call-graph.mdx @@ -7,9 +7,9 @@ iconType: "solid" Codegen provides powerful capabilities for analyzing and visualizing function call relationships in your codebase. This guide will show you how to traverse the call graph and create visual representations of function call paths. -## Understanding Call Graph Successors +## Understanding Call Graph Traversal -At the heart of call graph traversal is the `call_graph_successors()` method, which returns information about all function calls made within a function: +At the heart of call graph traversal is the [.function_calls](/api-reference/core/Function#function-calls) property, which returns information about all function calls made within a function: ```python def example_function(): @@ -18,16 +18,12 @@ def example_function(): return result # Get all calls made by example_function -successors = example_function.call_graph_successors() +successors = example_function.function_calls for successor in successors: - print(f"Call: {successor.call.source}") # The actual function call - print(f"Called: {successor.callables[0].name}") # The function being called + print(f"Call: {successor.source}") # The actual function call + print(f"Called: {successor.function_definition.name}") # The function being called ``` -Each successor contains: -- `call`: The function call definition (location, source code, arguments) -- `callables`: The function(s) being called - ## Building a Call Graph Here's how to build a directed graph of function calls using NetworkX: @@ -48,13 +44,12 @@ def create_call_graph(start_func, end_func, max_depth=5): if isinstance(parent_func, Function): src_call = src_func = parent_func else: - src_func = parent_func.callables[0] - src_call = parent_func.call + src_func = parent_func.function_definition + src_call = parent_func # Traverse all function calls - for func_call_def in src_func.call_graph_successors(): - call = func_call_def.call - func = func_call_def.callables[0] + for call in src_func.function_calls: + func = call.function_definition # Skip recursive calls if func.name == src_func.name: @@ -70,7 +65,7 @@ def create_call_graph(start_func, end_func, max_depth=5): return # Continue traversal - traverse_calls(func_call_def, current_depth + 1) + traverse_calls(call, current_depth + 1) # Initialize graph G.add_node(start_func, color="blue") # Start node @@ -106,18 +101,6 @@ codebase.visualize(filtered_graph) ## Advanced Usage -### Controlling Traversal - -You can control what types of calls to include: - -```python -# Get only internal function calls (exclude external modules) -successors = function.call_graph_successors(include_external=False) - -# Include or exclude class instantiations -successors = function.call_graph_successors(include_classes=False) -``` - ### Example: Finding Dead Code You can use call graph analysis to find unused functions: @@ -126,7 +109,7 @@ You can use call graph analysis to find unused functions: def find_dead_code(codebase): dead_functions = [] for function in codebase.functions: - if not any(function.call_graph_predecessors()): + if not any(function.function_calls): # No other functions call this one dead_functions.append(function) return dead_functions @@ -143,8 +126,8 @@ def get_max_call_chain(function): def build_graph(func, depth=0): if depth > 10: # Prevent infinite recursion return - for successor in func.call_graph_successors(): - called_func = successor.callables[0] + for call in func.function_calls: + called_func = call.function_definition G.add_edge(func, called_func) build_graph(called_func, depth + 1) @@ -153,7 +136,7 @@ def get_max_call_chain(function): ``` -The `call_graph_successors()` method is optimized for performance and uses Codegen's internal graph structure to quickly traverse relationships. It's much faster than parsing the code repeatedly. +The `.function_calls` property is optimized for performance and uses Codegen's internal graph structure to quickly traverse relationships. It's much faster than parsing the code repeatedly. diff --git a/docs/introduction/faq.mdx b/docs/introduction/faq.mdx index e2a5d4d1d..2572ef84f 100644 --- a/docs/introduction/faq.mdx +++ b/docs/introduction/faq.mdx @@ -17,7 +17,7 @@ iconType: "solid" Support](/building-with-codegen/language-support) guide. - Interested in adding support for your language? [Let us know](https://x.com/codegen) or [contribute](/introduction/contributing)! + Interested in adding support for your language? [Let us know](https://x.com/codegen) or [contribute](/introduction/community)! @@ -29,7 +29,7 @@ iconType: "solid" - Yes - [by design](3333/guiding-principles#python-first-composability). + Yes - [by design](/introduction/guiding-principles#python-first-composability). Codegen works like any other python package. It works alongside your IDE, version control system, and other development tools. diff --git a/docs/introduction/getting-started.mdx b/docs/introduction/getting-started.mdx index ab8d8c9da..96733d86f 100644 --- a/docs/introduction/getting-started.mdx +++ b/docs/introduction/getting-started.mdx @@ -281,7 +281,7 @@ if base_class: Learn more about [dependencies and - references](/building-with-codegen/dependencies-and-references) or [imports + references](/building-with-codegen/dependencies-and-usages) or [imports and exports](/building-with-codegen/imports-and-exports). diff --git a/docs/introduction/how-it-works.mdx b/docs/introduction/how-it-works.mdx index 029aeb340..179785b75 100644 --- a/docs/introduction/how-it-works.mdx +++ b/docs/introduction/how-it-works.mdx @@ -17,7 +17,7 @@ Codegen performs advanced static analysis to build a rich graph representation o ## The Codebase Graph -At the heart of Codegen is a comprehensive graph representation of your code. When you initialize a `[Codebase](/codebase-sdk/core/codebase)`, it performs static analysis to construct a rich graph structure connecting code elements: +At the heart of Codegen is a comprehensive graph representation of your code. When you initialize a `[Codebase](/api-reference/core/Codebase)`, it performs static analysis to construct a rich graph structure connecting code elements: ```python # Initialize and analyze the codebase @@ -36,7 +36,7 @@ Codegen's graph construction happens in two stages: 1. **AST Parsing**: We use [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) as our foundation for parsing code into Abstract Syntax Trees. Tree-sitter provides fast, reliable parsing across multiple languages. -2. **Multi-file Graph Construction**: Custom parsing logic, implemented in [rustworkx](https://github.com/Qiskit/rustworkx) and Python, analyzes these ASTs to construct a more sophisticated graph structure. This graph captures relationships between [symbols](/codebase-sdk/core/symbol), [files](/codebase-sdk/core/file), [imports](/codebase-sdk/core/import), and more. +2. **Multi-file Graph Construction**: Custom parsing logic, implemented in [rustworkx](https://github.com/Qiskit/rustworkx) and Python, analyzes these ASTs to construct a more sophisticated graph structure. This graph captures relationships between [symbols](/api-reference/core/Symbol), [files](/api-reference/core/SourceFile), [imports](/api-reference/core/Import), and more. ### Performance Through Pre-computation @@ -82,4 +82,4 @@ Codegen is just getting started, and we're excited about the possibilities ahead - Adding new transformations - Improving documentation -Check out our [contribution guide](/contributing) to get involved! +Check out our [contribution guide](/introduction/community) to get involved! diff --git a/docs/introduction/work-with-ai.mdx b/docs/introduction/work-with-ai.mdx index b5ed54e1b..dc5e7cd53 100644 --- a/docs/introduction/work-with-ai.mdx +++ b/docs/introduction/work-with-ai.mdx @@ -23,7 +23,7 @@ The [Codegen Playground](https://codegen.sh/playground) includes an integrated c ## Generating System Prompts -The [Codegen CLI](/cli/overview) provides commands to generate `.md` files that can be fed to any AI assistant for more accurate and contextual help. +The [Codegen CLI](/cli/about) provides commands to generate `.md` files that can be fed to any AI assistant for more accurate and contextual help. When you create a new codemod via [`codegen create`](/cli/create): diff --git a/docs/tutorials/creating-documentation.mdx b/docs/tutorials/creating-documentation.mdx index cd4fed966..89d999ef1 100644 --- a/docs/tutorials/creating-documentation.mdx +++ b/docs/tutorials/creating-documentation.mdx @@ -8,8 +8,8 @@ iconType: "solid" This guide demonstrates how to determine docs coverage and create documentation for your codebase. This primarily leverages two APIs: -- [`codebase.ai(...)`](/api-reference/Codebase#ai) for generating docstrings -- [`function.set_docstring(...)`](/codebase-sdk/core/HasBlock#set-docstring) for modifying them +- [`codebase.ai(...)`](/api-reference/core/Codebase#ai) for generating docstrings +- [`function.set_docstring(...)`](/api-reference/core/HasBlock#set-docstring) for modifying them ## Determining Documentation Coverage @@ -137,7 +137,7 @@ Which provides the following output: For non-trivial codebases, it can be challenging to achieve full documentation coverage. -The most efficient way to edit informative docstrings is to use [codebase.ai](/codebase-sdk/core/HasBlock#set-docstring) to generate docstrings, then use the [set_docstring](/codebase-sdk/core/HasBlock#set-docstring) method to update the docstring. +The most efficient way to edit informative docstrings is to use [codebase.ai](/api-reference/core/Codebase#ai) to generate docstrings, then use the [set_docstring](/api-reference/core/HasBlock#set-docstring) method to update the docstring. Learn more about using AI in our [guides](/building-with-codegen/calling-out-to-llms). @@ -211,48 +211,3 @@ for function in codebase.functions: # Set the new docstring function.set_docstring(docstring) ``` - -## Migrating to Google-Style Docstrings - -You can use [`docstring.to_google_docstring`](/api-reference/Docstring#to-google-docstring) to convert existing docstrings to Google style format. This is particularly useful when standardizing documentation across a codebase: - -```python python -# Convert all docstrings to Google style -for function in codebase.functions: - # Check if function has a docstring using walrus operator - if docstring := function.docstring: - # Convert to Google style using the docstring API - google_style_docstring = docstring.to_google_docstring(function) - # Update the function's docstring - function.set_docstring(google_style_docstring) -``` - -This will convert docstrings from various formats (e.g., reST, NumPy) to Google style, preserving all parameter descriptions, return types, and other documentation elements. - -For example, this reST style docstring: -```python -""" -Process the input data. - -:param data: The input data to process -:type data: pd.DataFrame -:param inplace: Whether to modify in place -:type inplace: bool -:returns: The processed data -:rtype: pd.DataFrame -""" -``` - -Will be converted to: -```python -""" -Process the input data. - -Args: - data (pd.DataFrame): The input data to process - inplace (bool): Whether to modify in place - -Returns: - pd.DataFrame: The processed data -""" -``` diff --git a/docs/tutorials/deleting-dead-code.mdx b/docs/tutorials/deleting-dead-code.mdx index 594934898..7028681c1 100644 --- a/docs/tutorials/deleting-dead-code.mdx +++ b/docs/tutorials/deleting-dead-code.mdx @@ -20,7 +20,7 @@ This guide will show you how to safely identify and remove genuinely unused code To simply identify code without any external usages, you can check for the absence of [`Symbol.usages`](/api-reference/core/Symbol#usages). -See [Dependencies and Usages](/api-references/dependencies-and-usages) for more information on how to use these properties. +See [Dependencies and Usages](/building-with-codegen/dependencies-and-usages) for more information on how to use these properties. ```python # Iterate through all functions in the codebase diff --git a/docs/tutorials/manage-feature-flags.mdx b/docs/tutorials/manage-feature-flags.mdx index e4385ef5f..117b65007 100644 --- a/docs/tutorials/manage-feature-flags.mdx +++ b/docs/tutorials/manage-feature-flags.mdx @@ -68,7 +68,7 @@ for usage in flag_var.usages(): ## Deleting unused feature flags -Detecting unused feature flag is a specific use case of [deleting dead code](/codebase-sdk/guides/deleting-dead-code), isolated to a specific search space. +Detecting unused feature flag is a specific use case of [deleting dead code](/tutorials/deleting-dead-code), isolated to a specific search space. ```python Delete unused flag print = codebase.log @@ -112,6 +112,6 @@ Once rolled out feature flags are removed, new dead code paths may have been cre 2. **Fix Tests**: Check for additional ways feature flags are used in the codebase (e.g. string arguments in test patches). -### Related Skills -- [reduce if statements](/codebase-sdk/examples/skills#reduce-if-statement-condition-python) -- [unwrap with statements](/codebase-sdk/examples/skills#unwrap-with-statement-python) +### Related Examples +- [reduce if statements](/building-with-codegen/reducing-conditions) +- [unwrap with statements](/building-with-codegen/statements-and-code-blocks#wrapping-and-unwrapping-statements) \ No newline at end of file diff --git a/docs/tutorials/organize-your-codebase.mdx b/docs/tutorials/organize-your-codebase.mdx index a4242c275..ff8a188d3 100644 --- a/docs/tutorials/organize-your-codebase.mdx +++ b/docs/tutorials/organize-your-codebase.mdx @@ -146,7 +146,7 @@ print("\n✅ Import cycles resolved!") ## Basic Symbol Movement -To move a symbol from one file to another, you can use the [move_to_file](/codebase-sdk/core/Function#move-to-file) method. +To move a symbol from one file to another, you can use the [move_to_file](/api-reference/core/Function#move-to-file) method. ```python python