├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── img ├── codegeeker.gif ├── codegeeker.png ├── codegeeker1.gif └── gitclone.png ├── package.json ├── src ├── extension.ts └── test │ ├── runTest.ts │ └── suite │ ├── extension.test.ts │ └── index.ts ├── tsconfig.json ├── vsc-extension-quickstart.md └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "codegeeker" 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 | ## [0.3.1] 8 | 9 | - change max-length from 64 to 32 10 | 11 | ## [0.3.0] 12 | 13 | - support openai GPT-J 14 | 15 | ## [0.2.0] 16 | 17 | - show only one completion item 18 | - support typescript 19 | 20 | ## [0.1.0] 21 | 22 | - Initial release -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 git-cloner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Codegeeker 2 | VSCode code generation Extension based on SalesForce CodeGen. 3 | 4 | Source code of Extension: https://github.com/git-cloner/codegeeker 5 | 6 | Source code of CodeGen : https://github.com/git-cloner/codegen 7 | 8 | Online demo: https://gitclone.com/aiit/codegen 9 | 10 | VSCode Extension: 11 | 12 | ![](https://gitclone.com/download1/aiit/codegeeker.gif) 13 | 14 | ## Extension install 15 | 16 | In VSCode,press ctrl+shift+x,search Codegeeker and install. 17 | 18 | ![](https://gitclone.com/download1/aiit/extension.png) 19 | 20 | ## Extension usage 21 | 22 | If you use Python or PlainText, enter a colon (:) in the VScode editor to display the generated candidate code snippet. 23 | 24 | If it is C, C++, Go, JavaScript, Java, etc., enter { in the VScode editor to display the generated candidate code fragment. 25 | 26 | if you enter ! then CodeGen uses openai ChatGPT(just test!!) 27 | 28 | ## Implementation principle 29 | 30 | Enter triggerCharacters (:or {), post current line to the backend (https://github.com/git-cloner/codegen) to generate the code, and the backend uses salesforce's CodeGen model (https://github.com/salesforce/CodeGen) to generate the code snippet. 31 | 32 | ## 中文说明 33 | 34 | 基于 salesforce codegen的VSCode代码生成插件。 35 | 36 | 插件源码:https://github.com/git-cloner/codegeeker 37 | 38 | 生成源码:https://github.com/git-cloner/codegen 39 | 40 | 在线演示:https://gitclone.com/aiit/codegen 41 | 42 | ### 1、插件安装 43 | 44 | 在VSCode里,按ctrl+shift+x,搜索Codegeeker,安装。 45 | 46 | ### 2、插件用法 47 | 48 | 如果是python或plaintext,在vscode编辑器中输入冒号(:),显示生成的候选代码片断。 49 | 50 | 如果是c、c++、go、javascript、java等,在vscode编辑器中输入{,显示生成的候选代码片断。 51 | 52 | 如果输入感叹号或者本行含有中文,则会调用openai ChatGPT。 53 | 54 | ### 3、实现原理 55 | 56 | 输入triggerCharacters(:或{),将本行代码post到后台(https://github.com/git-cloner/codegen)生成代码,后台使用salesforce的CodeGen模型(https://github.com/salesforce/CodeGen)生成代码片断返回。 57 | 58 | -------------------------------------------------------------------------------- /img/codegeeker.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-cloner/codegeeker/3dcc0c0d0d3dfefaac65fbe9d2403f5624c75306/img/codegeeker.gif -------------------------------------------------------------------------------- /img/codegeeker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-cloner/codegeeker/3dcc0c0d0d3dfefaac65fbe9d2403f5624c75306/img/codegeeker.png -------------------------------------------------------------------------------- /img/codegeeker1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-cloner/codegeeker/3dcc0c0d0d3dfefaac65fbe9d2403f5624c75306/img/codegeeker1.gif -------------------------------------------------------------------------------- /img/gitclone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-cloner/codegeeker/3dcc0c0d0d3dfefaac65fbe9d2403f5624c75306/img/gitclone.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codegeeker", 3 | "displayName": "Codegeeker", 4 | "description": "Code generator base on salesforce codegen", 5 | "publisher": "git-cloner", 6 | "repository": { 7 | "type ": "git", 8 | "url": "https://github.com/git-cloner/codegeeker" 9 | }, 10 | "version": "0.3.1", 11 | "keywords": [ 12 | "codegen", 13 | "salesforce codegen", 14 | "Codegeeker" 15 | ], 16 | "engines": { 17 | "vscode": "^1.73.0" 18 | }, 19 | "categories": [ 20 | "Snippets" 21 | ], 22 | "activationEvents": [ 23 | "onLanguage:python", 24 | "onLanguage:typescript", 25 | "onLanguage:javascript", 26 | "onLanguage:java", 27 | "onLanguage:c", 28 | "onLanguage:cpp", 29 | "onLanguage:go" 30 | ], 31 | "main": "./dist/extension.js", 32 | "contributes": { 33 | "commands": [] 34 | }, 35 | "scripts": { 36 | "vscode:prepublish": "npm run package", 37 | "compile": "webpack", 38 | "watch": "webpack --watch", 39 | "package": "webpack --mode production --devtool hidden-source-map", 40 | "compile-tests": "tsc -p . --outDir out", 41 | "watch-tests": "tsc -p . -w --outDir out", 42 | "pretest": "npm run compile-tests && npm run compile && npm run lint", 43 | "lint": "eslint src --ext ts", 44 | "test": "node ./out/test/runTest.js" 45 | }, 46 | "devDependencies": { 47 | "@types/glob": "^8.0.0", 48 | "@types/mocha": "^10.0.0", 49 | "@types/node": "16.x", 50 | "@types/vscode": "^1.73.0", 51 | "@typescript-eslint/eslint-plugin": "^5.42.0", 52 | "@typescript-eslint/parser": "^5.42.0", 53 | "@vscode/test-electron": "^2.2.0", 54 | "eslint": "^8.26.0", 55 | "glob": "^8.0.3", 56 | "mocha": "^10.1.0", 57 | "ts-loader": "^9.4.1", 58 | "typescript": "^4.8.4", 59 | "webpack": "^5.74.0", 60 | "webpack-cli": "^4.10.0" 61 | }, 62 | "dependencies": { 63 | "axios": "^1.2.0" 64 | } 65 | } -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | // The module 'vscode' contains the VS Code extensibility API 2 | // Import the module and reference it with the alias vscode in your code below 3 | import * as vscode from 'vscode'; 4 | import axios from 'axios'; 5 | 6 | // This method is called when your extension is activated 7 | // Your extension is activated the very first time the command is executed 8 | export function activate(context: vscode.ExtensionContext) { 9 | const provider = vscode.languages.registerCompletionItemProvider(["python", "plaintext"], { 10 | async provideCompletionItems(doc, pos) { 11 | return getCompletionItemsFromRemote(doc, pos); 12 | } 13 | }, ':'); 14 | const provider1 = vscode.languages.registerCompletionItemProvider(["python", "plaintext", "cpp", "c", "java", "javascript", "go", "typescript"], { 15 | async provideCompletionItems(doc, pos) { 16 | return getCompletionItemsFromRemote(doc, pos); 17 | } 18 | }, '{'); 19 | const provider2 = vscode.languages.registerCompletionItemProvider(["python", "plaintext", "cpp", "c", "java", "javascript", "go", "typescript"], { 20 | async provideCompletionItems(doc, pos) { 21 | return getCompletionItemsFromRemote(doc, pos); 22 | } 23 | }, '!'); 24 | context.subscriptions.push(provider, provider1,provider2); 25 | } 26 | 27 | async function getCompletionItemsFromRemote(doc: vscode.TextDocument, pos: vscode.Position) { 28 | let currentLine = doc.lineAt(pos).text; 29 | if (!currentLine.endsWith(":") && !currentLine.endsWith("{") && !currentLine.endsWith("}")) { 30 | return undefined; 31 | }; 32 | //vscode.window.showInformationMessage('Hello World from Codegeeker!'); 33 | const json = JSON.stringify({ "context": currentLine.replace("..", ""), "maxlength": 32 }); 34 | const res = await axios.post('https://gitclone.com/aiit/codegen', json, { 35 | headers: { 36 | // eslint-disable-next-line @typescript-eslint/naming-convention 37 | "Content-Type": "application/json" 38 | } 39 | }); 40 | var allCode = res.data.result; 41 | let completionItems: vscode.CompletionItem[] = []; 42 | if (allCode) { 43 | var sl = allCode.split("\n"); 44 | for (var i = 0; i < sl.length; i++) { 45 | if (sl[i] !== undefined && (sl[i].trim()) !== "") { 46 | const commandCompletion = new vscode.CompletionItem(sl[i]); 47 | commandCompletion.kind = vscode.CompletionItemKind.Snippet; 48 | commandCompletion.detail = allCode; 49 | commandCompletion.documentation = new vscode.MarkdownString(allCode); 50 | commandCompletion.insertText = new vscode.SnippetString(allCode); 51 | completionItems.push(commandCompletion); 52 | break; 53 | } 54 | } 55 | } 56 | return completionItems; 57 | } 58 | 59 | 60 | // This method is called when your extension is deactivated 61 | export function deactivate() { } 62 | -------------------------------------------------------------------------------- /src/test/runTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | 3 | import { runTests } from '@vscode/test-electron'; 4 | 5 | async function main() { 6 | try { 7 | // The folder containing the Extension Manifest package.json 8 | // Passed to `--extensionDevelopmentPath` 9 | const extensionDevelopmentPath = path.resolve(__dirname, '../../'); 10 | 11 | // The path to test runner 12 | // Passed to --extensionTestsPath 13 | const extensionTestsPath = path.resolve(__dirname, './suite/index'); 14 | 15 | // Download VS Code, unzip it and run the integration test 16 | await runTests({ extensionDevelopmentPath, extensionTestsPath }); 17 | } catch (err) { 18 | console.error('Failed to run tests'); 19 | process.exit(1); 20 | } 21 | } 22 | 23 | main(); 24 | -------------------------------------------------------------------------------- /src/test/suite/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from 'vscode'; 6 | // import * as myExtension from '../../extension'; 7 | 8 | suite('Extension Test Suite', () => { 9 | vscode.window.showInformationMessage('Start all tests.'); 10 | 11 | test('Sample test', () => { 12 | assert.strictEqual(-1, [1, 2, 3].indexOf(5)); 13 | assert.strictEqual(-1, [1, 2, 3].indexOf(0)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/test/suite/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import * as Mocha from 'mocha'; 3 | import * as glob from 'glob'; 4 | 5 | export function run(): Promise { 6 | // Create the mocha test 7 | const mocha = new Mocha({ 8 | ui: 'tdd', 9 | color: true 10 | }); 11 | 12 | const testsRoot = path.resolve(__dirname, '..'); 13 | 14 | return new Promise((c, e) => { 15 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { 16 | if (err) { 17 | return e(err); 18 | } 19 | 20 | // Add files to the test suite 21 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); 22 | 23 | try { 24 | // Run the mocha test 25 | mocha.run(failures => { 26 | if (failures > 0) { 27 | e(new Error(`${failures} tests failed.`)); 28 | } else { 29 | c(); 30 | } 31 | }); 32 | } catch (err) { 33 | console.error(err); 34 | e(err); 35 | } 36 | }); 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "ES2020", 5 | "lib": [ 6 | "ES2020" 7 | ], 8 | "sourceMap": true, 9 | "rootDir": "src", 10 | "strict": true /* enable all strict type-checking options */ 11 | /* Additional Checks */ 12 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 13 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 14 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vsc-extension-quickstart.md: -------------------------------------------------------------------------------- 1 | # Welcome to your VS Code Extension 2 | 3 | ## What's in the folder 4 | 5 | * This folder contains all of the files necessary for your extension. 6 | * `package.json` - this is the manifest file in which you declare your extension and command. 7 | * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. 8 | * `src/extension.ts` - this is the main file where you will provide the implementation of your command. 9 | * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. 10 | * We pass the function containing the implementation of the command as the second parameter to `registerCommand`. 11 | 12 | ## Setup 13 | 14 | * install the recommended extensions (amodio.tsl-problem-matcher and dbaeumer.vscode-eslint) 15 | 16 | 17 | ## Get up and running straight away 18 | 19 | * Press `F5` to open a new window with your extension loaded. 20 | * Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. 21 | * Set breakpoints in your code inside `src/extension.ts` to debug your extension. 22 | * Find output from your extension in the debug console. 23 | 24 | ## Make changes 25 | 26 | * You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. 27 | * You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. 28 | 29 | 30 | ## Explore the API 31 | 32 | * You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. 33 | 34 | ## Run tests 35 | 36 | * Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`. 37 | * Press `F5` to run the tests in a new window with your extension loaded. 38 | * See the output of the test result in the debug console. 39 | * Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder. 40 | * The provided test runner will only consider files matching the name pattern `**.test.ts`. 41 | * You can create folders inside the `test` folder to structure your tests any way you want. 42 | 43 | ## Go further 44 | 45 | - Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension). 46 | - [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace. 47 | - Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration). 48 | 49 | - package: vsce package -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | //@ts-check 2 | 3 | 'use strict'; 4 | 5 | const path = require('path'); 6 | 7 | //@ts-check 8 | /** @typedef {import('webpack').Configuration} WebpackConfig **/ 9 | 10 | /** @type WebpackConfig */ 11 | const extensionConfig = { 12 | target: 'node', // VS Code extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ 13 | mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') 14 | 15 | entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ 16 | output: { 17 | // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/ 18 | path: path.resolve(__dirname, 'dist'), 19 | filename: 'extension.js', 20 | libraryTarget: 'commonjs2' 21 | }, 22 | externals: { 23 | vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/ 24 | // modules added here also need to be added in the .vscodeignore file 25 | }, 26 | resolve: { 27 | // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader 28 | extensions: ['.ts', '.js'] 29 | }, 30 | module: { 31 | rules: [ 32 | { 33 | test: /\.ts$/, 34 | exclude: /node_modules/, 35 | use: [ 36 | { 37 | loader: 'ts-loader' 38 | } 39 | ] 40 | } 41 | ] 42 | }, 43 | devtool: 'nosources-source-map', 44 | infrastructureLogging: { 45 | level: "log", // enables logging required for problem matchers 46 | }, 47 | }; 48 | module.exports = [ extensionConfig ]; --------------------------------------------------------------------------------