[
  {
    "path": ".eslintrc.js",
    "content": "/**@type {import('eslint').Linter.Config} */\n// eslint-disable-next-line no-undef\nmodule.exports = {\n\troot: true,\n\tparser: '@typescript-eslint/parser',\n\tplugins: [\n\t\t'@typescript-eslint',\n\t],\n\textends: [\n\t\t'eslint:recommended',\n\t\t'plugin:@typescript-eslint/recommended',\n\t],\n\trules: {\n\t\t'semi': [2, \"always\"],\n\t\t'@typescript-eslint/no-unused-vars': 0,\n\t\t'@typescript-eslint/no-explicit-any': 0,\n\t\t'@typescript-eslint/explicit-module-boundary-types': 0,\n\t\t'@typescript-eslint/no-non-null-assertion': 0,\n\t}\n};"
  },
  {
    "path": ".gitignore",
    "content": "out\nnode_modules\n.vscode-test/\n*.vsix\nvscode.d.ts\npnpm-lock.yaml\n"
  },
  {
    "path": ".vscode/launch.json",
    "content": "{\n\t\"version\": \"0.2.0\",\n\t\"configurations\": [{\n\t\t\t\"name\": \"Run Extension\",\n\t\t\t\"type\": \"extensionHost\",\n\t\t\t\"request\": \"launch\",\n\t\t\t\"runtimeExecutable\": \"${execPath}\",\n\t\t\t\"args\": [\n\t\t\t\t\"--extensionDevelopmentPath=${workspaceFolder}\"\n\t\t\t],\n\t\t\t\"outFiles\": [\n\t\t\t\t\"${workspaceFolder}/out/**/*.js\"\n\t\t\t],\n\t\t\t\"preLaunchTask\": \"npm: watch\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"Run Extension Tests\",\n\t\t\t\"type\": \"extensionHost\",\n\t\t\t\"request\": \"launch\",\n\t\t\t\"runtimeExecutable\": \"${execPath}\",\n\t\t\t\"args\": [\n\t\t\t\t\"--extensionDevelopmentPath=${workspaceFolder}\",\n\t\t\t\t\"--extensionTestsPath=${workspaceFolder}/out/test\"\n\t\t\t],\n\t\t\t\"outFiles\": [\n\t\t\t\t\"${workspaceFolder}/out/test/**/*.js\"\n\t\t\t],\n\t\t\t\"preLaunchTask\": \"npm: watch\"\n\t\t}\n\t]\n}\n"
  },
  {
    "path": ".vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"type\": \"npm\",\n\t\t\t\"script\": \"watch\",\n\t\t\t\"problemMatcher\": \"$tsc-watch\",\n\t\t\t\"isBackground\": true,\n\t\t\t\"presentation\": {\n\t\t\t\t\"reveal\": \"never\"\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t}\n\t]\n}"
  },
  {
    "path": ".vscodeignore",
    "content": ".vscode/**\n.vscode-test/**\nout/test/**\nout/**/*.map\nsrc/**\n.gitignore\ntsconfig.json\nvsc-extension-quickstart.md\ntslint.json"
  },
  {
    "path": "README.md",
    "content": "![header](https://www.aiproducttools.com/images/codegpt/header.png)\n\n# [Code-GPT](https://marketplace.visualstudio.com/items?itemName=vaibhavacharya.code-gpt-va) — Make sense of any code, anytime. 🚀\n\n## Introduction 👋\n\nCode-GPT is an extension for VS Code that provides you **instant explanations for your code** within the code editor using AI.\n\nWith Code-GPT, you can:\n- 🧠 Get instant explanations for selected code in real-time\n- 💡 Increase your coding understanding and efficiency\n- ⏳ Save time and minimize frustration with clear code explanations\n- 🔍 Improve your coding skills with in-depth code analysis\n\n## Demo 📽\n[![demo video](https://www.aiproducttools.com/images/codegpt/demo.gif)](https://www.aiproducttools.com/images/codegpt/demo.mp4)\n\n## Installation 📦\n\n1. Open VS Code and click on the Extensions icon in the left sidebar\n2. Search for \"Code-GPT\" in the Extensions Marketplace\n3. Click on the Install button for \"Code-GPT\"\n\n## How to Use Code-GPT 🛠\n\n1. Select the code you want to understand in your VSCode editor\n2. Open the Command Palette (press `Ctrl + Shift + P` or `Cmd + Shift + P` on Mac)\n3. Type \"Explain Selected Code\" and select the command from the list\n4. Enter your email address if prompted\n5. Wait for the response and the explanation will be prepended to the selected code in your VSCode editor\n\nEnjoy the instant and comprehensive code explanations with Code-GPT! 🎉\n\n## Author ✏\n\n- Twitter → [@VaibhavAcharya_](https://twitter.com/VaibhavAcharya_)\n- Website → [vaibhavacharya.github.io](https://vaibhavacharya.github.io)\n- GitHub → [VaibhavAcharya](https://github.com/VaibhavAcharya)\n"
  },
  {
    "path": "package.json",
    "content": "{\n\t\"name\": \"code-gpt-va\",\n\t\"displayName\": \"Code-GPT — Make sense of any code, anytime. 🚀\",\n\t\"description\": \"Provides you instant explanations for your code within the code editor using AI.\",\n\t\"icon\": \"images/logo.png\",\n\t\"galleryBanner\": {\n\t\t\"color\": \"#000000\",\n\t\t\"theme\": \"dark\"\n\t},\n\t\"version\": \"0.0.6\",\n\t\"publisher\": \"vaibhavacharya\",\n\t\"author\": {\n\t\t\"name\": \"Vaibhav Acharya\",\n\t\t\"email\": \"vaibhavacharya111@gmail.com\",\n\t\t\"url\": \"https://www.twitter.com/VaibhavAcharya_\"\n\t},\n\t\"engines\": {\n\t\t\"vscode\": \"^1.74.0\"\n\t},\n\t\"private\": true,\n\t\"license\": \"MIT\",\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"https://github.com/VaibhavAcharya/code-gpt\"\n\t},\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/VaibhavAcharya/code-gpt/issues\"\n\t},\n\t\"categories\": [\n\t\t\"Machine Learning\",\n\t\t\"Other\"\n\t],\n\t\"keywords\": [\n\t\t\"ai\",\n\t\t\"code\",\n\t\t\"explanation\",\n\t\t\"comments\"\n\t],\n\t\"activationEvents\": [\n\t\t\"*\"\n\t],\n\t\"main\": \"./out/extension.js\",\n\t\"contributes\": {\n\t\t\"commands\": [\n\t\t\t{\n\t\t\t\t\"command\": \"extension.commentSelectedCode\",\n\t\t\t\t\"title\": \"Code-GPT → Comment Selected Code\"\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"command\": \"extension.explainSelectedCode\",\n\t\t\t\t\"title\": \"Code-GPT → Explain Selected Code\"\n\t\t\t}\n\t\t],\n\t\t\"menus\": {\n\t\t\t\"editor/context\": [\n\t\t\t  {\n\t\t\t\t  \"command\": \"extension.commentSelectedCode\",\n\t\t\t\t  \"when\": \"editorHasSelection\"\n\t\t\t  },\n\t\t\t  {\n\t\t\t\t  \"command\": \"extension.explainSelectedCode\",\n\t\t\t\t  \"when\": \"editorHasSelection\"\n\t\t\t  }\n\t\t\t]\t\n\t\t}\n\t},\n\t\"scripts\": {\n\t\t\"vscode:prepublish\": \"npm run compile\",\n\t\t\"compile\": \"tsc -p ./\",\n\t\t\"lint\": \"eslint \\\"src/**/*.ts\\\"\",\n\t\t\"watch\": \"tsc -watch -p ./\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@types/node\": \"^16.11.7\",\n\t\t\"@types/vscode\": \"1.74.0\",\n\t\t\"@typescript-eslint/eslint-plugin\": \"^5.42.0\",\n\t\t\"@typescript-eslint/parser\": \"^5.42.0\",\n\t\t\"eslint\": \"^8.26.0\",\n\t\t\"typescript\": \"^4.8.4\"\n\t},\n\t\"dependencies\": {\n\t\t\"@octokit/rest\": \"^18.0.0\",\n\t\t\"axios\": \"^1.3.2\"\n\t}\n}\n"
  },
  {
    "path": "src/extension.ts",
    "content": "import { type ExtensionContext, window, commands } from \"vscode\";\r\nimport axios from \"axios\";\r\n\r\nimport { checkEmail } from \"./utils/email\";\r\nimport { displayError } from \"./utils/errors\";\r\nimport { languageSupportsComments, styleAsComment } from \"./utils/comments\";\r\n\r\n// Function to handle the selected code\r\nconst commentSelectedCode = async (context: ExtensionContext) => {\r\n    // Check if the email has been saved or not\r\n    await checkEmail(context);\r\n    const email = await context.globalState.get(\"email\");\r\n    if (!email) return displayError(\"noEmail\");\r\n\r\n    // Grab the editor window\r\n    const editor = window.activeTextEditor;\r\n    if (!editor) return displayError(\"noEditor\");\r\n\r\n    // Aquire the selected text\r\n    const selection = editor.selection;\r\n    const selectedText = editor.document.getText(selection);\r\n    if (!selectedText.length) return displayError(\"noSelection\");\r\n\r\n    const lang = editor.document.languageId;\r\n    const isLanguageSupported = languageSupportsComments(lang);\r\n    if (!isLanguageSupported) return displayError(\"languageNotSupported\");\r\n\r\n    // Send the selected code and email to the API\r\n    try {\r\n        const { data } = await axios.post(\"https://www.aiproducttools.com/api/codegpt\", {\r\n            email,\r\n            input: selectedText,\r\n            lang,\r\n        });\r\n\r\n        if (!data.output) return displayError(\"serverSentNothing\");\r\n\r\n        // Get the output from the API response\r\n        const output = data.output.trim();\r\n\r\n        // Wrap the output in a comment\r\n        const comment = styleAsComment(output, lang);\r\n\r\n        // Replace the selected text with the output\r\n        editor.edit((editBuilder) => {\r\n            editBuilder.insert(selection.start, `${comment}\\n`);\r\n        });\r\n    } catch (error) {\r\n        console.error(error);\r\n        return displayError(\"unableToConnect\");\r\n    }\r\n};\r\n\r\n// Function to handle the selected code\r\nconst explainSelectedCode = async (context: ExtensionContext) => {\r\n    // Check if the email has been saved or not\r\n    await checkEmail(context);\r\n    const email = await context.globalState.get(\"email\");\r\n    if (!email) return displayError(\"noEmail\");\r\n\r\n    // Grab the editor window\r\n    const editor = window.activeTextEditor;\r\n    if (!editor) return displayError(\"noEditor\");\r\n\r\n    // Aquire the selected text\r\n    const selection = editor.selection;\r\n    const selectedText = editor.document.getText(selection);\r\n    if (!selectedText.length) return displayError(\"noSelection\");\r\n\r\n    const lang = editor.document.languageId;\r\n    const isLanguageSupported = languageSupportsComments(lang);\r\n    if (!isLanguageSupported) return displayError(\"languageNotSupported\");\r\n\r\n    // Send the selected code and email to the API\r\n    try {\r\n        const { data } = await axios.post(\"https://www.aiproducttools.com/api/codegpt\", {\r\n            email,\r\n            input: selectedText,\r\n            lang,\r\n        });\r\n\r\n        if (!data.output) return displayError(\"serverSentNothing\");\r\n\r\n        // Get the output from the API response\r\n        const output = data.output.trim();\r\n\r\n        // Show the output in a message\r\n        window.showInformationMessage(output)\r\n        \r\n    } catch (error) {\r\n        console.error(error);\r\n        return displayError(\"unableToConnect\");\r\n    }\r\n};\r\n\r\n// Register the \"Explain Selected Code\" command\r\nexport function activate(context: ExtensionContext) {\r\n    const registerComment = commands.registerCommand(\"extension.commentSelectedCode\", () => commentSelectedCode(context));\r\n    const registerExplain = commands.registerCommand(\"extension.explainSelectedCode\", () => explainSelectedCode(context));\r\n    context.subscriptions.push(registerComment);\r\n    context.subscriptions.push(registerExplain);\r\n}\r\n\r\n// Deactivate the extension\r\nexport function deactivate() {\r\n    return null;\r\n}\r\n"
  },
  {
    "path": "src/utils/comments.ts",
    "content": "const singleLineCommentMap: Record<string, string> = {\n    abap: \"--\",\n    bat: \"::\",\n    bibtex: \"%\",\n    clojure: \";\",\n    coffeescript: \"#\",\n    c: \"//\",\n    cpp: \"//\",\n    csharp: \"//\",\n    \"cuda-cpp\": \"//\",\n    diff: \"//\",\n    dockerfile: \"#\",\n    fsharp: \"//\",\n    \"git-commit\": \"#\",\n    \"git-rebase\": \"#\",\n    go: \"//\",\n    groovy: \"//\",\n    ini: \";\",\n    java: \"//\",\n    javascript: \"//\",\n    javascriptreact: \"//\",\n    json: \"//\",\n    jsonc: \"//\",\n    latex: \"%\",\n    less: \"/*\",\n    lua: \"--\",\n    makefile: \"#\",\n    objectivec: \"//\",\n    objectivecpp: \"//\",\n    perl: \"#\",\n    perl6: \"#\",\n    php: \"//\",\n    plaintext: \"//\",\n    powershell: \"#\",\n    jade: \"//\",\n    pug: \"//\",\n    python: \"#\",\n    r: \"#\",\n    razor: \"@*\",\n    ruby: \"#\",\n    rust: \"//\",\n    sass: \"//\",\n    shaderlab: \"//\",\n    shellscript: \"#\",\n    sql: \"--\",\n    slim: \"//\",\n    stylus: \"//\",\n    swift: \"//\",\n    typescript: \"//\",\n    typescriptreact: \"//\",\n    tex: \"%\",\n    vb: \"'\",\n    yaml: \"#\",\n};\n\nconst multiLineCommentMap: Record<string, [string, string]> = {\n    css: [\"/*\", \"*/\"],\n    handlebars: [\"{{!--\", \"--}}\"],\n    html: [\"<!--\", \"-->\"],\n    markdown: [\"<!--\", \"-->\"],\n    scss: [\"/*\", \"*/\"],\n    xml: [\"<!--\", \"-->\"],\n    xsl: [\"<!--\", \"-->\"],\n};\n\nexport const styleAsComment = (text: string, lang: string) => {\n    const singleLineComment = singleLineCommentMap[lang];\n    const multiLineComment = multiLineCommentMap[lang];\n\n    if (!singleLineComment && !multiLineComment) return text;\n\n    if (singleLineComment) return `${singleLineComment} ${text}`;\n    if (multiLineComment) return `${multiLineComment[0]} ${text} ${multiLineComment[1]}`;\n};\n\nexport const languageSupportsComments = (lang: string) => {\n    return !!singleLineCommentMap[lang] || !!multiLineCommentMap[lang];\n};\n"
  },
  {
    "path": "src/utils/email.ts",
    "content": "import { type ExtensionContext, window } from \"vscode\";\n\nexport const checkEmail = async (context: ExtensionContext) => {\n    const email = await context.globalState.get(\"email\");\n\n    // If the email has not been saved, ask the user for their email\n    if (!email) {\n        const newEmail = await window.showInputBox({\n            title: \"Code-GPT\",\n            placeHolder: \"📧 Enter your email\",\n            prompt: \"To protect us from unlimited use. We won't spam your email, promise. 🤝\",\n            validateInput: (value) => {\n                const emailRegex =\n                    /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n\n                if (!emailRegex.test(value)) {\n                    return \"Error: Invalid email. ☹\";\n                }\n\n                return null;\n            },\n        });\n\n        await context.globalState.update(\"email\", newEmail);\n    }\n};\n"
  },
  {
    "path": "src/utils/errors.ts",
    "content": "import { window } from \"vscode\";\n\nconst errorMessages = {\n    noEditor: \"Error: Editor not found! 😵\",\n    noEmail: \"Error: Email is required! It is to protect us from unlimited use. We won't spam your email, promise. 🤝\",\n    noSelection: \"Nothing selected. 😅\",\n    languageNotSupported: \"Error: Language not supported yet! 😵\",\n    unableToConnect: \"Error: Unable to connect to server! 💀\",\n    serverSentNothing: \"Server sent nothing! 🙃\",\n};\n\nexport const displayError = (error: keyof typeof errorMessages) => {\n    return window.showErrorMessage(errorMessages[error]);\n};\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n\t\"compilerOptions\": {\n\t\t\"module\": \"commonjs\",\n\t\t\"target\": \"es2020\",\n\t\t\"outDir\": \"out\",\n\t\t\"sourceMap\": true,\n\t\t\"rootDir\": \"src\",\n\t\t\"strict\": true\n\t},\n\t\"exclude\": [\"node_modules\", \".vscode-test\"]\n}\n"
  }
]