Skip to content

Commit

Permalink
fix inserting code wtih VSCode snippet syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
timkmecl committed Jan 30, 2023
1 parent e4cbc0d commit 6b8190b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ This Visual Studio Code extension allows you to use the [official OpenAI API](ht

<br>

*This is currently a work-in-progress, if there are any problems please let me know. You can also try [ChatGPT extension](https://github.com/timkmecl/chatgpt-vscode) ([marketplace](https://marketplace.visualstudio.com/items?itemName=timkmecl.chatgpt)) which is smarter, but the setup is more complicated and it may not work (403/429 errors)*
<a href="https://www.buymeacoffee.com/timkmecl" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 40px" ></a>

*This extension is free, however you need an OpenAI Account. You can also try [ChatGPT extension](https://github.com/timkmecl/chatgpt-vscode) ([marketplace](https://marketplace.visualstudio.com/items?itemName=timkmecl.chatgpt)) which is smarter but currently doesn't work for most users.*

<br>

<img src="examples/main.png" alt="Refactoring selected code using chatGPT"/>

## Features
- 💡 **Ask general questions** or use code snippets from the editor to query ChatGPT via an input box in the sidebar
- 💡 **Ask general questions** or use code snippets from the editor to query GPT3 via an input box in the sidebar
- 🖱️ Right click on a code selection and run one of the context menu **shortcuts**
- automatically write documentation for your code
- explain the selected code
- refactor or optimize it
- find problems with it
- 💻 View ChatGPT's responses in a panel next to the editor
- 💻 View GPT's responses in a panel next to the editor
- 📝 **Insert code snippets** from the AI's response into the active editor by clicking on them


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "codegpt3",
"displayName": "CodeGPT: write and improve code using AI",
"description": "Use GPT3 right inside the IDE to enhance and automate your coding with AI-powered assistance",
"version": "1.0.0",
"version": "1.0.1",
"publisher": "timkmecl",
"icon": "resources/extensionIcon.png",
"license": "MIT",
Expand Down
6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ class CodeGPTViewProvider implements vscode.WebviewViewProvider {
break;
}
let code = data.value;
code = code.replace(/([^\\])(\$)([^{0-9])/g, "$1\\$$$3");
//code = code.replace(/([^\\])(\$)([^{0-9])/g, "$1\\$$$3");
const snippet = new vscode.SnippetString();
snippet.appendText(code);
// insert the code as a snippet into the active text editor
vscode.window.activeTextEditor?.insertSnippet(new vscode.SnippetString(code));
vscode.window.activeTextEditor?.insertSnippet(snippet);
break;
}
case 'prompt':
Expand Down

0 comments on commit 6b8190b

Please sign in to comment.