Skip to content

Programming-Assistant-AI-Bot/VsCodeExtension

Repository files navigation

Perl Programming Assistant - VS Code Extension

A powerful VS Code extension that provides AI-powered assistance for Perl development, featuring intelligent code suggestions, error detection, and context-aware recommendations.

πŸš€ Features

πŸ€– AI-Powered Code Generation

  • Comment-to-Code: Write comments starting with # and get intelligent code suggestions
  • Context-Aware Suggestions: Leverages your project structure, imports, and variable definitions for accurate code generation
  • Smart Caching: Prevents duplicate requests for the same comments, improving performance

πŸ“‹ Alternative Code Suggestions

  • Sidebar Integration: Select any code block to see alternative implementations in the sidebar
  • Copy to Clipboard: One-click copying of suggested code alternatives
  • Real-time Updates: Suggestions update automatically as you select different code blocks

πŸ” Intelligent Error Detection

  • Real-time Analysis: Automatic error detection as you type with configurable debounce timing
  • Visual Indicators: Errors are highlighted directly in your code with detailed descriptions
  • AI-Powered: Uses advanced AI to detect logical and syntactical issues beyond traditional linting

πŸ“š Advanced Code Understanding

  • Project Structure Analysis: Automatically indexes your Perl codebase for better context
  • Import Resolution: Tracks and resolves module imports and dependencies
  • Variable Definition Tracking: Understands variable scope and definitions across files
  • Symbol Usage Analysis: Identifies how symbols are used throughout your project

πŸ” Vector-Based Semantic Search

  • LanceDB Integration: Uses LanceDB for high-performance vector storage and semantic search
  • Embedding-Based Matching: Leverages MiniLM embeddings to find semantically similar code
  • Intelligent Code Retrieval: Finds relevant code examples based on context and meaning, not just keywords
  • Persistent Index: Maintains a persistent vector database for fast startup and consistent performance

πŸ“¦ Installation

  1. Install the Extension

    # Clone the repository
    git clone <repository-url>
    cd git_check/VsCodeExtension
    
    # Install dependencies
    npm install
  2. Package the Extension

    # Install vsce if you haven't already
    npm install -g vsce
    
    # Package the extension
    vsce package
  3. Install in VS Code

    • Open VS Code
    • Go to Extensions (Ctrl+Shift+X)
    • Click the "..." menu and select "Install from VSIX..."
    • Select the generated .vsix file

πŸ› οΈ Prerequisites

Backend Server

This extension requires the Programming Assistant AI Bot backend server to be running:

# Start the backend server (typically on port 8000)
cd ../backend
python -m uvicorn main:app --reload

Supported File Types

  • .pl - Perl scripts
  • .pm - Perl modules
  • .t - Perl test files

βš™οΈ Configuration

Access settings through File > Preferences > Settings and search for "Perl Code Generation":

Available Settings

Setting Default Description
perlCodeGeneration.relevantCodeCount 3 Number of relevant code examples to retrieve for context
perlCodeGeneration.indexOnStartup true Automatically index the Perl codebase when extension activates
perlCodeGeneration.contextWindowSize 15 Number of lines to consider around cursor for context
perlCodeGeneration.useMemoryIndex true Use in-memory index instead of LanceDB for module resolution

LanceDB Configuration

The extension uses LanceDB for vector-based semantic search to provide more intelligent code suggestions:

  • Database Location: Stored in your system's temp directory under perl-code-gen-lancedb
  • Vector Dimensions: Uses 384-dimensional vectors (MiniLM-L6-v2 embeddings)
  • Table Schema: Stores code content, file paths, titles, and vector embeddings
  • Automatic Indexing: Builds vector index during workspace initialization

Example Configuration

{
  "perlCodeGeneration.relevantCodeCount": 5,
  "perlCodeGeneration.indexOnStartup": true,
  "perlCodeGeneration.contextWindowSize": 20,
  "perlCodeGeneration.useMemoryIndex": false
}

Note: Set useMemoryIndex to false to enable LanceDB vector search for enhanced semantic code matching.

🎯 Usage

Comment-to-Code Generation

  1. Write a Comment: Start any line with # followed by your description

    # Create a subroutine that validates email addresses
  2. Get Suggestions: The extension will automatically generate code based on your comment

    # Create a subroutine that validates email addresses
    sub validate_email {
        my ($email) = @_;
        return $email =~ /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    }

Alternative Code Suggestions

  1. Select Code: Highlight any block of Perl code
  2. View Sidebar: Check the "Perl Code Suggestions" panel in the sidebar
  3. Copy Alternatives: Click on any suggestion to copy it to your clipboard

Error Detection

  • Automatic Detection: Errors are automatically detected as you type
  • Visual Feedback: Problematic code is underlined with error descriptions
  • Configurable Timing: Adjust detection sensitivity in settings

πŸ—οΈ Project Structure

VsCodeExtension/
β”œβ”€β”€ extension.js              # Main extension entry point
β”œβ”€β”€ package.json             # Extension manifest and configuration
β”œβ”€β”€ sidebarprovider.js       # Sidebar suggestions provider
β”œβ”€β”€ api/
β”‚   └── api.js              # Backend API communication
β”œβ”€β”€ collectors/             # Context and code analysis
β”‚   β”œβ”€β”€ contextCollector.js
β”‚   β”œβ”€β”€ definitionCollector.js
β”‚   β”œβ”€β”€ importDefinitionAnalyzer.js
β”‚   β”œβ”€β”€ perlImportAnalyzer.js
β”‚   └── repoMapProvider.js
β”œβ”€β”€ commands/
β”‚   └── commands.js         # VS Code command implementations
β”œβ”€β”€ embeddings/
β”‚   └── miniLmEmbeddings.js # MiniLM embedding generation
β”œβ”€β”€ indexers/               # Codebase indexing and search
β”‚   β”œβ”€β”€ codebaseIndexer.js
β”‚   β”œβ”€β”€ codeStructureIndex.js
β”‚   └── vectorIndex.js      # LanceDB vector operations
β”œβ”€β”€ parsers/
β”‚   └── treeSitter.js       # Tree-sitter parser integration
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ checkErrors.js      # Error detection utilities
β”‚   └── debounce.js        # Performance optimization
└── test/
    └── extension.test.js   # Unit tests

πŸ”§ Available Commands

Access commands through the Command Palette (Ctrl+Shift+P):

  • Perl: Index Codebase - Manually trigger codebase indexing
  • Perl: Show Suggestions - Display code suggestions panel
  • Perl: debugName - Debug module name resolution
  • Perl: debugImports - Debug import analysis

🚦 Status Indicators

  • Indexing Progress: Progress notifications during codebase analysis
  • Error Count: Status bar indicator showing detected errors
  • Backend Connection: Visual feedback for backend server connectivity

πŸ” Troubleshooting

Common Issues

  1. Backend Connection Failed

    Error: Backend server is not running
    

    Solution: Ensure the backend server is running on http://localhost:8000

  2. No Code Suggestions

    No specific code suggestions received from AI
    

    Solution: Check that your selection contains valid Perl code and the backend is responding

  3. Indexing Failed

    Failed to initialize indexer
    

    Solution: Ensure you have a workspace folder open with Perl files

  4. LanceDB Connection Issues

    Error initializing LanceDB
    

    Solution: Check write permissions to temp directory and ensure sufficient disk space for vector database

Debug Information

Enable debug logging by checking the "Perl Code Generation" output channel:

  • View > Output > Perl Code Generation

πŸ§ͺ Development

Running Tests

npm test

Development Setup

# Install dependencies
npm install

# Run in development mode
# Press F5 in VS Code to launch Extension Development Host

Building

# Lint code
npm run lint

# Package extension
vsce package

πŸ“‹ Requirements

  • VS Code: Version 1.60.0 or higher
  • Node.js: Version 14.0 or higher
  • Backend Server: Programming Assistant AI Bot backend running on port 8000
  • LanceDB: For vector-based semantic search (automatically installed with extension)
  • Perl: For testing and validation (optional)

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is part of the Programming Assistant AI Bot system. Please refer to the main project license for usage terms.

πŸ”— Related Projects

  • Frontend Interface: ../frontend - Web-based chat interface
  • Backend API: ../backend - AI processing server
  • Documentation: Full project documentation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •