CodeContext

Development Guide

πŸ› οΈ Setting Up Your Development Environment

Prerequisites

Clone and Build

# Clone the repository
git clone https://github.com/sonii-shivansh/CodeContext.git
cd CodeContext

# Build the project
./gradlew build

# Run tests
./gradlew test

# Install distribution locally
./gradlew installDist

πŸƒ Running Locally

Run via Gradle

# Analyze current directory
./gradlew run --args="analyze ."

# Analyze specific directory
./gradlew run --args="analyze /path/to/project"

# Clear cache and analyze
./gradlew run --args="analyze . --clear-cache"

# Disable cache
./gradlew run --args="analyze . --no-cache"

Run via Installed Distribution

# After running ./gradlew installDist
./build/install/codecontext/bin/codecontext analyze .

πŸ§ͺ Testing

Run All Tests

./gradlew test

Run Specific Test Class

./gradlew test --tests "com.codecontext.core.parser.ParserTest"

Run Tests with Coverage

./gradlew test jacocoTestReport
open build/reports/jacoco/test/html/index.html

Test Categories


πŸ› Debugging

Debug in IntelliJ IDEA

  1. Open the project in IntelliJ IDEA
  2. Create a new β€œGradle” run configuration
  3. Set task to: run --args="analyze ."
  4. Set breakpoints in the code
  5. Click β€œDebug” button

Debug Tests

  1. Right-click on a test class or method
  2. Select β€œDebug β€˜TestName’”

Enable Debug Logging

Edit src/main/resources/logback.xml:

<root level="DEBUG">
    <appender-ref ref="STDOUT" />
</root>

πŸ“ Project Structure

src/
β”œβ”€β”€ main/kotlin/com/codecontext/
β”‚   β”œβ”€β”€ Main.kt                    # Entry point
β”‚   β”œβ”€β”€ cli/                       # CLI commands
β”‚   β”‚   β”œβ”€β”€ MainCommand.kt         # Root command
β”‚   β”‚   β”œβ”€β”€ ImprovedAnalyzeCommand.kt  # Analyze command
β”‚   β”‚   β”œβ”€β”€ ServerCommand.kt       # API server
β”‚   β”‚   └── AIAssistantCommand.kt  # AI features
β”‚   β”œβ”€β”€ core/                      # Core logic
β”‚   β”‚   β”œβ”€β”€ scanner/
β”‚   β”‚   β”‚   β”œβ”€β”€ RepositoryScanner.kt      # File scanning
β”‚   β”‚   β”‚   └── OptimizedGitAnalyzer.kt   # Git analysis
β”‚   β”‚   β”œβ”€β”€ parser/
β”‚   β”‚   β”‚   β”œβ”€β”€ JavaRealParser.kt         # Java parsing
β”‚   β”‚   β”‚   β”œβ”€β”€ KotlinRegexParser.kt      # Kotlin parsing
β”‚   β”‚   β”‚   β”œβ”€β”€ ParsedFile.kt             # Data model
β”‚   β”‚   β”‚   └── ParserFactory.kt          # Parser selection
β”‚   β”‚   β”œβ”€β”€ graph/
β”‚   β”‚   β”‚   └── RobustDependencyGraph.kt  # Graph building
β”‚   β”‚   β”œβ”€β”€ generator/
β”‚   β”‚   β”‚   └── LearningPathGenerator.kt  # Learning paths
β”‚   β”‚   β”œβ”€β”€ cache/
β”‚   β”‚   β”‚   └── CacheManager.kt           # Caching
β”‚   β”‚   └── config/
β”‚   β”‚       └── CodeContextConfig.kt      # Configuration
β”‚   β”œβ”€β”€ output/
β”‚   β”‚   └── ReportGenerator.kt     # HTML generation
β”‚   └── server/
β”‚       └── ApiServer.kt           # REST API
└── test/kotlin/com/codecontext/   # Tests

🎨 Code Style

Kotlin Conventions

We follow Kotlin Coding Conventions:

KDoc Comments

Add KDoc for public APIs:

/**
 * Parses a source file and extracts package and import information.
 *
 * @param file The file to parse
 * @return ParsedFile containing extracted metadata
 * @throws IllegalArgumentException if file type is unsupported
 */
fun parse(file: File): ParsedFile

πŸ”§ Common Development Tasks

Add a New Language Parser

  1. Create parser class implementing LanguageParser:
    class PythonParser : LanguageParser {
     override fun parse(file: File): ParsedFile {
         // Implementation
     }
    }
    
  2. Register in ParserFactory.kt:
    "py" -> pythonParser
    
  3. Add tests in src/test/kotlin/com/codecontext/core/parser/

Add a New CLI Command

  1. Create command class extending CliktCommand:
    class MyCommand : CliktCommand(name = "mycommand", help = "Description") {
     override fun run() {
         // Implementation
     }
    }
    
  2. Register in Main.kt:
    MainCommand()
     .subcommands(
         ImprovedAnalyzeCommand(),
         MyCommand()  // Add here
     )
    

Modify Report Output

Edit src/main/kotlin/com/codecontext/output/ReportGenerator.kt

The report uses kotlinx.html DSL:

div("my-section") {
    h2 { +"My Section" }
    p { +"Content" }
}

πŸš€ Release Process

Version Bumping

  1. Update version in build.gradle.kts:
    version = "0.2.0"
    
  2. Update CHANGELOG.md with release notes

  3. Commit and tag:
    git commit -m "chore: bump version to 0.2.0"
    git tag v0.2.0
    git push origin main --tags
    

Build Release Artifacts

./gradlew clean build installDist

πŸ“Š Performance Profiling

Measure Analysis Time

time ./gradlew run --args="analyze /path/to/large/project"

Profile with VisualVM

  1. Run with JMX enabled:
    ./gradlew run --args="analyze ." -Dcom.sun.management.jmxremote
    
  2. Connect VisualVM to the process

🀝 Getting Help


Happy coding! πŸŽ‰