Skip to content

Commit b2d1eb9

Browse files
committed
Initial commit
0 parents  commit b2d1eb9

21 files changed

+2722
-0
lines changed

.eslintrc.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 6,
6+
"sourceType": "module"
7+
},
8+
"plugins": [
9+
"@typescript-eslint"
10+
],
11+
"rules": {
12+
"@typescript-eslint/naming-convention": "warn",
13+
"@typescript-eslint/semi": "warn",
14+
"curly": "warn",
15+
"eqeqeq": "warn",
16+
"no-throw-literal": "warn",
17+
"semi": "off"
18+
},
19+
"ignorePatterns": [
20+
"out",
21+
"dist",
22+
"**/*.d.ts"
23+
]
24+
}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
out
2+
dist
3+
node_modules
4+
.vscode-test/
5+
*.vsix

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher"]
5+
}

.vscode/launch.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Run Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
],
15+
"outFiles": [
16+
"${workspaceFolder}/dist/**/*.js"
17+
],
18+
"preLaunchTask": "${defaultBuildTask}"
19+
},
20+
{
21+
"name": "Extension Tests",
22+
"type": "extensionHost",
23+
"request": "launch",
24+
"args": [
25+
"--extensionDevelopmentPath=${workspaceFolder}",
26+
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
27+
],
28+
"outFiles": [
29+
"${workspaceFolder}/out/**/*.js",
30+
"${workspaceFolder}/dist/**/*.js"
31+
],
32+
"preLaunchTask": "tasks: watch-tests"
33+
}
34+
]
35+
}

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"out": false, // set this to true to hide the "out" folder with the compiled JS files
5+
"dist": false // set this to true to hide the "dist" folder with the compiled JS files
6+
},
7+
"search.exclude": {
8+
"out": true, // set this to false to include "out" folder in search results
9+
"dist": true // set this to false to include "dist" folder in search results
10+
},
11+
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
12+
"typescript.tsc.autoDetect": "off"
13+
}

.vscode/tasks.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "watch",
9+
"problemMatcher": "$ts-webpack-watch",
10+
"isBackground": true,
11+
"presentation": {
12+
"reveal": "never",
13+
"group": "watchers"
14+
},
15+
"group": {
16+
"kind": "build",
17+
"isDefault": true
18+
}
19+
},
20+
{
21+
"type": "npm",
22+
"script": "watch-tests",
23+
"problemMatcher": "$tsc-watch",
24+
"isBackground": true,
25+
"presentation": {
26+
"reveal": "never",
27+
"group": "watchers"
28+
},
29+
"group": "build"
30+
},
31+
{
32+
"label": "tasks: watch-tests",
33+
"dependsOn": [
34+
"npm: watch",
35+
"npm: watch-tests"
36+
],
37+
"problemMatcher": []
38+
}
39+
]
40+
}

.vscodeignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.vscode/**
2+
.vscode-test/**
3+
out/**
4+
node_modules/**
5+
src/**
6+
.gitignore
7+
.yarnrc
8+
webpack.config.js
9+
vsc-extension-quickstart.md
10+
**/tsconfig.json
11+
**/.eslintrc.json
12+
**/*.map
13+
**/*.ts

.yarnrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--ignore-engines true

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
All notable changes to the "chatgpt" extension will be documented in this file.
4+
5+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6+
7+
## [Unreleased]
8+
9+
- Initial release

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ChatGPT for VSCode
2+
3+
This is a VSCode extension that allows you to use ChatGPT right within VSCode.
4+
5+
**Warning:** Right now, this is more of a proof of concept!
6+
7+
## How it works
8+
9+
The extension makes use of this [ChatGPT package](https://github.com/transitive-bullshit/chatgpt-api), which uses Playwright/a headless chrome in order to login and communicate with ChatGPT.
10+
11+
In order to use this with VSCode, it's best to run the extension in debug mode once.
12+
On the initial start, you will need to authenticate with OpenAI - this requires you to login via the headless Chrome.
13+
14+
When you are successfully authenticated, you can turn on headless mode so that the browser won't be visible.

media/main.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//@ts-check
2+
3+
// This script will be run within the webview itself
4+
// It cannot access the main VS Code APIs directly.
5+
(function () {
6+
const vscode = acquireVsCodeApi();
7+
8+
let response = '';
9+
10+
// Handle messages sent from the extension to the webview
11+
window.addEventListener("message", (event) => {
12+
const message = event.data;
13+
switch (message.type) {
14+
case "addResponse": {
15+
response = message.value;
16+
setResponse();
17+
break;
18+
}
19+
case "clearResponse": {
20+
response = '';
21+
break;
22+
}
23+
}
24+
});
25+
26+
function setResponse() {
27+
var converter = new showdown.Converter();
28+
html = converter.makeHtml(response);
29+
document.getElementById("response").innerHTML = html;
30+
31+
var preCodeBlocks = document.querySelectorAll("pre code");
32+
for (var i = 0; i < preCodeBlocks.length; i++) {
33+
preCodeBlocks[i].classList.add(
34+
"p-4",
35+
"my-4",
36+
"block"
37+
);
38+
}
39+
var codeBlocks = document.querySelectorAll('code');
40+
for (var i = 0; i < codeBlocks.length; i++) {
41+
// Check if innertext starts with "Copy code"
42+
if (codeBlocks[i].innerText.startsWith("Copy code")) {
43+
codeBlocks[i].innerText = codeBlocks[i].innerText.replace("Copy code", "");
44+
}
45+
46+
codeBlocks[i].classList.add("p-1", "inline-flex", "max-w-full", "overflow-hidden", "border", "rounded-sm", "cursor-pointer");
47+
48+
codeBlocks[i].addEventListener('click', function (e) {
49+
e.preventDefault();
50+
vscode.postMessage({
51+
type: 'codeSelected',
52+
value: this.innerText
53+
});
54+
});
55+
}
56+
}
57+
58+
document.getElementById('prompt-input').addEventListener('keyup', function (e) {
59+
if (e.keyCode === 13) {
60+
vscode.postMessage({
61+
type: 'prompt',
62+
value: this.value
63+
});
64+
}
65+
});
66+
})();

package.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"name": "chatgpt",
3+
"displayName": "chatgpt",
4+
"description": "",
5+
"version": "0.0.1",
6+
"engines": {
7+
"vscode": "^1.73.0"
8+
},
9+
"categories": [
10+
"Other"
11+
],
12+
"activationEvents": [
13+
"onCommand:chatgpt.ask",
14+
"onView:chatgpt.chatView"
15+
],
16+
"main": "./dist/extension.js",
17+
"contributes": {
18+
"commands": [
19+
{
20+
"command": "chatgpt.ask",
21+
"title": "Ask ChatGPT"
22+
}
23+
],
24+
"viewsContainers": {
25+
"activitybar": [
26+
{
27+
"id": "chatgpt",
28+
"title": "ChatGPT",
29+
"icon": "resources/icon.png"
30+
}
31+
]
32+
},
33+
"views": {
34+
"chatgpt": [
35+
{
36+
"type": "webview",
37+
"id": "chatgpt.chatView",
38+
"name": "ChatGPT"
39+
}
40+
]
41+
}
42+
},
43+
"scripts": {
44+
"vscode:prepublish": "yarn run package",
45+
"compile": "webpack",
46+
"watch": "webpack --watch",
47+
"package": "webpack --mode production --devtool hidden-source-map",
48+
"compile-tests": "tsc -p . --outDir out",
49+
"watch-tests": "tsc -p . -w --outDir out",
50+
"pretest": "yarn run compile-tests && yarn run compile && yarn run lint",
51+
"lint": "eslint src --ext ts",
52+
"test": "node ./out/test/runTest.js"
53+
},
54+
"devDependencies": {
55+
"@types/glob": "^8.0.0",
56+
"@types/mocha": "^10.0.1",
57+
"@types/node": "16.x",
58+
"@types/vscode": "^1.73.0",
59+
"@typescript-eslint/eslint-plugin": "^5.45.0",
60+
"@typescript-eslint/parser": "^5.45.0",
61+
"@vscode/test-electron": "^2.2.0",
62+
"eslint": "^8.28.0",
63+
"glob": "^8.0.3",
64+
"mocha": "^10.1.0",
65+
"ts-loader": "^9.4.1",
66+
"typescript": "^4.9.3",
67+
"webpack": "^5.75.0",
68+
"webpack-cli": "^5.0.0"
69+
},
70+
"dependencies": {
71+
"chatgpt": "^0.4.1"
72+
}
73+
}

resources/icon.png

2.32 KB
Loading

0 commit comments

Comments
 (0)