Lazygit is a VS Code extension that provides a webview-based chat interface allowing users to convert natural language commands into Git commands using Google Generative AI and execute these commands directly in the VS Code terminal.
- Gemini AIStudio Docs: https://ai.google.dev/gemini-api/docs/get-started/tutorial?lang=node
- Vscode WebView Docs: https://code.visualstudio.com/api/extension-guides/webview#scripts-and-message-passing.
- VsCode Extension Docs: https://code.visualstudio.com/api/extension-guides/command.
- src/extension.ts: Main entry point for the extension. It handles activation, command registration, and message communication between the webview and the extension.
- src/webview.ts: Contains the HTML and JavaScript for the webview content, including the React-based chat interface.
- vscode: Core VS Code API module.
- @google/generative-ai: Google Generative AI SDK.
-
Install Dependencies
- Install necessary npm packages including the Google Generative AI SDK.
-
Activate the Extension
- Register the
lazygit.openChat
command. - Set up the webview panel to display the chat interface.
- Register the
-
Webview Content
- The webview displays a chat interface where users can input natural language commands.
- Messages are sent to the extension to be processed and converted into Git commands.
-
Activation and Command Registration
- Registers the command that opens the chat interface.
- Creates a webview panel and loads the content from
webview.ts
.
-
Webview Content
- HTML and CSS for a styled chat interface.
- React component to handle user input and display messages.
- JavaScript to communicate with the VS Code extension.
-
Message Handling
- Handles messages sent from the webview to the extension.
- Processes user input to convert natural language commands into Git commands using Google Generative AI.
- Sends the resulting Git commands back to the webview for display and execution.
-
Executing Git Commands
- Opens a terminal within VS Code to run the Git commands generated by the AI.
-
Open Chat Interface
- Use the command
lazygit.openChat
to open the chat interface.
- Use the command
-
Input Natural Language Commands
- Type a natural language command into the chat input box and send it.
-
Receive and Run Git Commands
- The AI will convert the input into Git commands.
- The Git commands will be displayed with an option to run them directly in the terminal.