The "vscode-openai-code-analyzer" is a Visual Studio Code extension that leverages OpenAI GPT technology to analyze and summarize code snippets in various programming languages. It also performs a code review. This is configurable thru the contents of the system, assistent and user roles (see Configuration section below).
This revamped extension now includes:
- Improved user interaction with the Summarize Code and OpenAI Code Analyzer Settings commands.
- More comprehensive code analysis and summarization by utilizing a role-based message system in OpenAI API calls.
- Enhanced configurability with options to specify the GPT model and customize the content of system, assistant, and user prompts.
- A new Markdown preview feature that renders the summary, token usage, and other relevant information in a well-formatted Markdown document.
- Error handling improvements to provide more informative error messages.
- Progress reporting during the summarization process.
To use this extension, you need an OpenAI API key. Set the OPENAI_API_KEY
environment variable with your API key value. For example:
cd /mysrc/
export OPENAI_API_KEY=sk-...
code .
- Select the code snippet you want to analyze in the editor.
- Press
Cmd+Shift+P
(Mac) orCtrl+Shift+P
(Windows/Linux) to open the Command Palette. - Type "Summarize Code" and press Enter.
The extension will send the selected code to the OpenAI API, and the summary along with other relevant information will be displayed in a new Markdown preview pane.
You can configure the following settings in Visual Studio Code:
openaiCodeAnalyzer.maxTokens
: Set the maximum number of tokens for the code summary generated by OpenAI API (default is 600).openaiCodeAnalyzer.gptModel
: Specify the GPT model to use with the OpenAI API (default is "gpt-4").openaiCodeAnalyzer.roleSystemContent
: Customize the content for the system role message.openaiCodeAnalyzer.roleAssistantContent
: Customize the content for the assistant role message.openaiCodeAnalyzer.roleUserContent
: Customize the content for the user role message.
To access these settings, follow these steps:
- Open the Command Palette with
Ctrl+Shift+P
(Windows/Linux) orCmd+Shift+P
(Mac). - Type "OpenAI Code Analyzer Settings" and press Enter. This will open settings for this extension where you can override VS Code's settings with your own.
- Make sure you have Docker installed on your machine.
- Set the
OPENAI_API_KEY
environment variable with your API key value. - Run the
docker_build.sh
script to build the Docker image.
docker_build.sh
- Run the
docker_test.sh
script to test the project.
docker_test.sh
To build and install the extension locally, follow these steps:
- Clone the repository to your local machine.
git clone https://github.com/NorSoulx/vscode-openai-code-analyzer.git
- Change to the cloned repository directory.
cd vscode-openai-code-analyzer
- Install the required dependencies.
npm install
- Build the extension.
npm run package
This command will generate a .vsix
file in the project directory.
- Install the extension in Visual Studio Code.
- Open Visual Studio Code.
- Press
Cmd+Shift+P
(Mac) orCtrl+Shift+P
(Windows/Linux) to open the Command Palette. - Type "Extensions: Install from VSIX..." and press Enter.
- Locate the
.vsix
file generated in step 4 and click "Open" to install the extension.
None at the moment.
- Added new commands and configuration options for enhanced customizability and user interaction.
- Introduced a Markdown preview feature for rendering summaries.
- Improved error handling and progress reporting.
- Updated the OpenAI API interaction to use a role-based message system for better summarization results.
- Initial release of the "openai-code-analyzer" extension with support for various programming languages.
If you encounter any issues or have any suggestions for improvements, please create an issue on GitHub.
Enjoy using the Visual Studio Code OpenAI Code Analyzer extension!