list_code_definition_names
The list_code_definition_names tool provides a structured overview of your codebase by extracting code definitions from top-level source files in a specified directory. It helps VJSP understand code architecture by displaying line numbers and definition snippets.
list_code_definition_names
Parameters
The tool accepts the following parameters:
path(required): The path to the directory for listing top-level source code definitions, relative to the current working directory
What It Does
This tool scans source code files at the top level of a specified directory and extracts code definitions such as classes, functions, and interfaces. It displays the line numbers and actual code for each definition, enabling quick mapping of key components in your codebase.
Application Scenarios
- When VJSP needs to quickly understand your codebase architecture
- When VJSP needs to locate important code constructs across multiple files
- When planning refactoring or extensions to existing code
- Before using other tools to dive into implementation details
- When identifying relationships between different parts of your codebase
Key Features
- Extracts classes, functions, methods, interfaces, and other definitions from source files
- Displays line numbers and actual source code for each definition
- Supports multiple programming languages including JavaScript, TypeScript, Python, Rust, Go, C++, C, C#, Ruby, Java, PHP, Swift, and Kotlin
- Processes only files at the top level of the specified directory (not subdirectories)
- Limits processing to a maximum of 50 files for performance optimization
- Focuses on top-level definitions to avoid information overload
- Helps identify code organization patterns across the project
- Constructs a mental map of your codebase architecture
- Works in conjunction with other tools like
read_filefor deeper analysis
Limitations
- Only identifies top-level definitions, not nested ones
- Only processes files at the top level of the specified directory, not subdirectories
- Limited to processing a maximum of 50 files per request
- Dependent on language-specific parsers, with varying detection quality
- May not recognize all definitions in languages with complex syntax
- Not a substitute for reading code to understand implementation details
- Cannot detect runtime patterns or dynamic code relationships
- Does not provide information about how definitions are used
- May have reduced accuracy with highly dynamic or metaprogrammed code
- Limited to languages supported by Tree-sitter parsers
How It Works
When the list_code_definition_names tool is invoked, it follows this workflow:
- Parameter Validation: Validates the required
pathparameter - Path Resolution: Resolves the relative path to an absolute path
- Directory Scanning: Scans only the top level of the specified directory for source code files (non-recursive)
- File Filtering: Limits processing to a maximum of 50 files for performance
- Language Detection: Identifies file types based on extensions (.js, .jsx, .ts, .tsx, .py, .rs, .go, .cpp, .hpp, .c, .h, .cs, .rb, .java, .php, .swift, .kt, .kts)
- Code Parsing: Uses Tree-sitter to parse code and extract definitions through these steps:
- Parses file content into an Abstract Syntax Tree (AST)
- Creates a query using a language-specific query string
- Sorts captures by their position in the file
- Result Formatting: Outputs definitions with line numbers and actual source code
Output Format
The output displays file paths followed by definition line numbers and actual source code. For example:
src/utils.js:
0--0 | export class HttpClient {
5--5 | formatDate() {
10--10 | function parseConfig(data) {
src/models/User.js:
0--0 | interface UserProfile {
10--10 | export class User {
20--20 | function createUser(data) {Each line shows:
- Start and end line numbers of the definition
- Separator (|)
- Actual source code of the definition
This output format helps you quickly view where definitions are located in files and their implementation details.
Usage Examples
- When starting a new task, VJSP first lists key code definitions to understand the overall project structure.
- When planning refactoring work, VJSP uses this tool to identify classes and functions that may be affected.
- When exploring unfamiliar codebases, VJSP maps important code structures before diving into implementation details.
- When adding new features, VJSP identifies existing patterns and related code definitions to maintain consistency.
- When troubleshooting errors, VJSP maps the codebase structure to locate potential sources of problems.
- When planning architectural changes, VJSP identifies all affected components.
Code Examples
List code definitions in the current directory:
<list_code_definition_names>
<path>.</path>
</list_code_definition_names>Examine a specific module's structure:
<list_code_definition_names>
<path>src/components</path>
</list_code_definition_names>Explore a utility library:
<list_code_definition_names>
<path>lib/utils</path>
</list_code_definition_names>