CodeMentor VS Code Extension
CodeMentor is an AI-powered VS Code extension that enhances Python coding with real-time feedback. Using Hugging Face's distilgpt2
, it offers detailed code explanations (Ctrl+E
), concise hints (Ctrl+Y
), and automated solutions (Ctrl+Shift+S
) for syntax errors and improvements. Feedback is saved to CodeMentor_Feedback.txt
, making it ideal for learning and debugging.
Features
- Explain Mode (
Ctrl+E
): Detailed explanations of your Python code, including functionality and potential improvements.
- Hint Mode (
Ctrl+Y
): Concise hints to fix errors or optimize code without revealing the full solution.
- Solution Mode (
Ctrl+Shift+S
): Corrected code with explanations for syntax errors or enhancements.
- Set Hugging Face Token (
Ctrl+Shift+T
): Configure your Hugging Face API token for AI-powered feedback.
- Flake8 Integration: Checks for PEP 8 style violations and suggests fixes via
autopep8
.
Screenshots
Solution Mode fixing a missing colon in test.py
Installation
Install from Marketplace:
Set Up Python Environment:
Configure Hugging Face Token:
System Requirements:
- ~2GB RAM for
distilgpt2
(default model).
- ~50GB RAM/GPU for
mistralai/Mixtral-8x7B-Instruct-v0.1
(optional, edit mentor.py
line 88).
Usage
- Open a Python file (e.g.,
test.py
) in VS Code.
- Use these commands:
Ctrl+E
: Explain code functionality and suggest improvements.
Ctrl+Y
: Get a hint to fix or improve code.
Ctrl+Shift+S
: Receive corrected code with an explanation.
- Feedback is saved to
CodeMentor_Feedback.txt
in the same directory as your Python file.
Example
For test.py
:
def add(a, b) # Missing colon
return a + b
Setting Up a GitHub Repository
To contribute, fork, or publish updates, set up a GitHub repository for the source code.
Prerequisites
Steps to Create and Push to GitHub
Navigate to Project Directory:
cd "C:\Users\NIKHIL\OneDrive - South Indian Education Society\python practice\codebunny"
Initialize Git Repository (if not already initialized):
git init
Create .gitignore
:
Create a .gitignore
file to exclude unnecessary files:
echo "node_modules/
*.vsix
CodeMentor_Feedback.txt
.vscode/
*.log" > .gitignore
4. **Fix Corrupted `README.md`**:
- If `README.md` contains `�` characters, open it in VS Code or a text editor (e.g., Notepad++).
- Ensure it’s saved in UTF-8 encoding:
- In VS Code, click the encoding in the bottom-right (e.g., `UTF-16`) and select **Save with Encoding** > **UTF-8**.
- Replace with the content above or copy it manually.
5. **Add and Commit Files**:
Add all relevant files (`package.json`, `extension.js`, `mentor.py`, `README.md`, `LICENSE`, `images/codementor.png`):
```bash
git add .
git commit -m "Initial commit: Add CodeMentor extension files with corrected README"
Create GitHub Repository:
- Go to GitHub.
- Set:
- Repository Name:
Code-Mentor
- Description:
AI-powered VS Code extension for Python code analysis
- Visibility: Public (recommended) or Private
- Initialize with README: Uncheck (you have your own
README.md
)
- Click Create repository.
Link and Push to GitHub:
git remote add origin https://github.com/Rancidgift57/Code-Mentor.git
git branch -M main
git push -u origin main
Update package.json
:
Ensure the repository
field points to your GitHub URL:
"repository": {
"type": "git",
"url": "https://github.com/Rancidgift57/Code-Mentor"
}
Commit if changed:
git add package.json
git commit -m "Update repository URL in package.json"
git push origin main
Publishing to Visual Studio Marketplace
To publish version 0.0.3
with the corrected README.md
and LICENSE
:
Resolve Git Working Directory Error:
The npm version patch
error (Git working directory not clean
) from 6:59 PM IST, July 21, 2025, occurs due to uncommitted changes.
- Check:
git status
Example output:
Changes not staged for commit:
modified: README.md
modified: package.json
Untracked files:
LICENSE
images/codementor.png
- Commit:
git add README.md LICENSE package.json images/codementor.png
git commit -m "Add README.md, LICENSE, and update package.json for v0.0.3"
git push origin main
- Verify clean status:
git status
# Should show: nothing to commit, working tree clean
Create Publisher Account (if not done):
- Go to Visual Studio Marketplace.
- Sign in with a Microsoft account.
- Create publisher:
- ID:
nikhil-codementor
- Name:
NikhilCodeMentor
Create Personal Access Token (PAT):
- Go to Azure DevOps.
- Profile > Personal access tokens > New Token.
- Set:
- Name:
VSCodeExtensionPublish
- Organization: All accessible organizations
- Expiration: 1 year
- Scopes: Marketplace > Acquire and Publish
- Copy the token securely.
Package the Extension:
npm install -g vsce
vsce package
- Creates
codementor-0.0.2.vsix
(or 0.0.3
if version updated).
- Verify files:
vsce ls
Expected: README.md
, LICENSE
, package.json
, extension.js
, mentor.py
, images/codementor.png
.
Test Locally:
code --install-extension codementor-0.0.2.vsix
- Test with
test.py
:
def add(a, b) # Missing colon
return a + b
- Run
Ctrl+Shift+S
and check CodeMentor_Feedback.txt
:
Solution: Corrected code:
```python
def add(a, b):
return a + b
Explanation: Added missing colon.
- Verify
README.md
in Extensions view (Ctrl+Shift+X
).
Contributing
File issues or pull requests at GitHub.
License
MIT
For support, email: nnair7598@gmail.com.