CodeMaster Visual Studio Code Extension
CodeMaster is a powerful Visual Studio Code extension that helps you speed up your development workflow by automating code generation, refactoring, bug fixing, testing, and documentation. Powered by the OpenAI API, it supports a wide range of programming languages and provides seamless integration with your development environment.
Features
With CodeMaster, you can:
- Generate code snippets and templates.
- Generate code from selected text.
- Refactor code to improve testability and readability.
- Convert code to a language's idiomatic style.
- Fix bugs in your code automatically.
- Generate unit tests for your code.
- Generate documentation for your code.
- Set your active programming language.
- Authenticate with your OpenAI API Key.
Commands
The following commands are available for the CodeMaster extension:
1. CodeMaster - Generate Code
:
Generate code snippets and templates.
2. CodeMaster - Generate Code From Selection
:
Generate code based on your current selection.
3. CodeMaster - Refactor code - Improve testability
:
Refactor code to enhance testability.
4. CodeMaster - Refactor - To Language's Idiomatic Style
:
Convert code to the idiomatic style of the active programming language.
5. CodeMaster - Fix Bug
:
Automatically fix bugs in your code.
6. CodeMaster - Generate Tests
:
Generate unit tests for your code.
7. CodeMaster - Generate Documentation
:
Generate documentation for your code.
8. CodeMaster - Authentication - OpenAI API Key
:
Authenticate the extension with your OpenAI API Key.
9. CodeMaster - Set Active Programming Language
:
Set the active programming language for the extension.
Installation
To install the CodeMaster extension, follow these steps:
- Open Visual Studio Code.
- Click on the Extensions view icon or press
Ctrl+Shift+X
or Cmd+Shift+X
on macOS.
- Search for "CodeMaster".
- Click the Install button.
Configuration
Before using the extension, you need to configure it with your OpenAI API Key:
- Open the command palette with
Ctrl+Shift+P
or Cmd+Shift+P
on macOS.
- Run the
CodeMaster - Authentication - OpenAI API Key
command.
- Enter your OpenAI API Key when prompted.
To set your active programming language, follow these steps:
- Open the command palette with
Ctrl+Shift+P
or Cmd+Shift+P
on macOS.
- Run the
CodeMaster - Set Active Programming Language
command.
- Select your desired programming language from the list.
Usage
To use any of the CodeMaster commands, open the command palette with Ctrl+Shift+P
or Cmd+Shift+P
on macOS, and run the desired command.
Examples
Below are examples for each command available in the CodeMaster extension:
CodeMaster - Generate Code
:
To generate code snippets or templates, open the command palette and run the CodeMaster - Generate Code
command.
Input: "Create a Python function to add two numbers"
Generated code snippet:
def add_numbers(a, b):
return a + b
CodeMaster - Generate Code From Selection
:
To generate code based on your current selection, select the text you want to generate code from, open the command palette, and run the CodeMaster - Generate Code From Selection
command.
Selected text: "Calculate the area of a circle"
Generated code snippet:
def area_of_circle(radius):
import math
return math.pi * radius * radius
CodeMaster - Refactor code - Improve testability
:
To refactor code for better testability, select the code you want to refactor, open the command palette, and run the CodeMaster - Refactor code - Improve testability
command.
Selected code:
import requests
def get_weather(city):
api_key = "your_api_key"
url = f"https://api.example.com/weather?city={city}&key={api_key}"
response = requests.get(url)
return response.json()["weather"]
Refactored code:
import requests
def get_weather_data(url):
response = requests.get(url)
return response.json()["weather"]
def build_weather_url(city, api_key):
return f"https://api.example.com/weather?city={city}&key={api_key}"
api_key = "your_api_key"
city = "London"
url = build_weather_url(city, api_key)
weather = get_weather_data(url)
CodeMaster - Refactor - To Language's Idiomatic Style
:
To convert code to the idiomatic style of the active programming language, select the code you want to refactor, open the command palette, and run the CodeMaster - Refactor - To Language's Idiomatic Style
command.
Selected non-idiomatic Python code:
def print_hello(name):
if name == None:
name = "World"
print("Hello, " + name + "!")
Refactored idiomatic Python code:
def print_hello(name=None):
if name is None:
name = "World"
print(f"Hello, {name}!")
CodeMaster - Fix Bug
:
To automatically fix bugs in your code, select the buggy code, open the command palette, and run the CodeMaster - Fix Bug
command.
Selected buggy code:
def divide(a, b):
return a / 0
Fixed code:
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
CodeMaster - Generate Tests
:
To generate unit tests for your code, select the code you want to generate tests for, open the command palette, and run the CodeMaster - Generate Tests
command.
Selected code:
def add_numbers(a, b):
return a + b
Generated test code:
import unittest
class TestAddNumbers(unittest.TestCase):
def test_add_numbers(self):
self.assertEqual(add_numbers(1, 2), 3)
self.assertEqual(add_numbers(-1, 1), 0)
self.assertEqual(add_numbers(0, 0), 0)
if __name__ == 'main':
unittest.main()
CodeMaster - Generate Documentation
:
To generate documentation for your code, select the code you want to generate documentation for, open the command palette, and run the CodeMaster - Generate Documentation
command.
Selected code:
def add_numbers(a, b):
return a + b
Generated documentation:
"""
Function to add two numbers.
Args:
a (int/float): The first number to add.
b (int/float): The second number to add.
Returns:
int/float: The sum of the two input numbers.
"""
CodeMaster - Authentication - OpenAI API Key
:
To authenticate the extension with your OpenAI API Key, open the command palette and run the CodeMaster - Authentication - OpenAI API Key
command. Enter your OpenAI API Key when prompted. You can retrieve your API Key from your OpenAI account. You can retrieve your API Key from your OpenAI account.
CodeMaster - Set Active Programming Language
:
To set the active programming language for the extension, open the command palette and run the CodeMaster - Set Active Programming Language
command. Select your desired programming language from the list.
IMPORTANT:
Please note that the examples provided in the previous responses are hypothetical and may not produce the exact output mentioned. The actual output of the CodeMaster extension will be based on the underlying OpenAI API implementation and may vary.
In general, the CodeMaster extension aims to help developers with various tasks, including code generation, refactoring, bug fixing, test generation, and documentation generation. By using this extension, developers can save time and effort during the development process, improve code quality, and maintain a more efficient workflow.
It is essential to ensure that the CodeMaster extension is properly configured with the OpenAI API Key and the desired active programming language to achieve optimal results. Additionally, it's important to remember that the extension's performance will depend on the capabilities of the underlying OpenAI API, which may have limitations in certain scenarios.
Developers should review and test the code generated by the CodeMaster extension thoroughly to ensure it meets their requirements and follows best practices for their specific programming language and project.