LazyRefactor
Refactor your codebase to adhere to best coding practices using AI.
Table of Contents
Introduction
LazyRefactor is a Visual Studio Code extension that leverages advanced AI capabilities to improve your codebase. By utilizing OpenAI's GPT-4o model and a multi-agent Retrieval-Augmented Generation (RAG) system with embeddings from text-embedding-3-large
, LazyRefactor provides automated code enhancements directly within your development environment.
Features
- Analyze Repository: Builds a graph-based index of your codebase using embeddings for efficient retrieval.
- Refactor Code: Refactors your code to follow best coding standards and practices.
- Generate Documentation: Automatically adds comprehensive documentation to your code.
- Create Unit Tests: Generates unit tests for your codebase to improve test coverage.
- Apply Security Best Practices: Enhances your code by applying security best practices.
Prerequisites
- Visual Studio Code (version 1.50.0 or later)
- Node.js (version 12 or later)
- Python (version 3.7 or later)
- OpenAI API Key with access to
gpt-4o
and text-embedding-3-large
models
Installation
1. Clone the Repository
git clone <repository-url>
cd LazyRefactor
2. Install Node.js Dependencies
npm install
3. Compile the TypeScript Code
npm run compile
4. Set Up Python Environment
cd backend
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
5. Install Python Dependencies
pip install -r requirements.txt
6. Set Up Environment Variables
Set your OpenAI API Key:
export OPENAI_API_KEY=your-api-key
Alternatively, you can set the API key within the extension settings in VS Code.
7. Run the Extension
Usage
Open a Git Repository
- Open a folder in VS Code that contains a Git repository.
Set OpenAI API Key
- In VS Code, go to
File
> Preferences
> Settings
(or Code
> Preferences
> Settings
on macOS).
- Search for
LazyRefactor
.
- Enter your OpenAI API Key in the
LazyRefactor: OpenAI Api Key
field.
Use the Extension Commands
Open the Command Palette (Ctrl+Shift+P
or Cmd+Shift+P
on macOS).
Run any of the following commands:
LazyRefactor: Analyze Repository
LazyRefactor: Refactor Code
LazyRefactor: Generate Documentation
LazyRefactor: Create Unit Tests
LazyRefactor: Apply Security Best Practices
Follow the prompts and wait for the tasks to complete. Progress will be shown in the status bar.
Configuration
You can configure the extension settings through the VS Code settings:
- OpenAI API Key: Your OpenAI API key. Required for the extension to function.
Development
Setup for Development
Clone the Repository
git clone <repository-url>
cd LazyRefactor
Install Dependencies
npm install
Compile TypeScript
npm run compile
Install Python Dependencies
cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Run the Extension
Testing
- Ensure you have test repositories to work with.
- Use the commands and verify their outputs.
- Check logs and outputs for any errors.
Building the Extension
Install vsce
:
npm install -g vsce
Package the extension:
vsce package
Publishing
Create a Publisher Account
Create a Personal Access Token (PAT)
- Generate a PAT with the required scopes for publishing.
Login with VSCE
vsce login <publisher-name>
Publish the Extension
vsce publish
Contributing
Contributions are welcome! Please follow these steps:
Fork the Repository
- Click the "Fork" button at the top right of the repository page.
Create a New Branch
git checkout -b feature/your-feature-name
Commit Your Changes
git commit -m "Add your message"
Push to the Branch
git push origin feature/your-feature-name
Open a Pull Request
- Go to your forked repository and click the "New Pull Request" button.
Please ensure your code follows the project's coding standards and includes appropriate tests.
License
This project is licensed under the MIT License.
Acknowledgements