├── .gitignore ├── media ├── jsc.gif ├── jsf.gif ├── build.gif ├── watch.gif └── flutter.png ├── .vscodeignore ├── .vscode ├── extensions.json ├── tasks.json ├── settings.json └── launch.json ├── CHANGELOG.md ├── tslint.json ├── src ├── test │ ├── suite │ │ ├── extension.test.ts │ │ └── index.ts │ └── runTest.ts └── extension.ts ├── tsconfig.json ├── dart.json ├── LICENSE ├── README.md ├── package.json └── vsc-extension-quickstart.md /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | *.vsix 5 | -------------------------------------------------------------------------------- /media/jsc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aksharpatel47/vscode_flutter_helper/HEAD/media/jsc.gif -------------------------------------------------------------------------------- /media/jsf.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aksharpatel47/vscode_flutter_helper/HEAD/media/jsf.gif -------------------------------------------------------------------------------- /media/build.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aksharpatel47/vscode_flutter_helper/HEAD/media/build.gif -------------------------------------------------------------------------------- /media/watch.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aksharpatel47/vscode_flutter_helper/HEAD/media/watch.gif -------------------------------------------------------------------------------- /media/flutter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aksharpatel47/vscode_flutter_helper/HEAD/media/flutter.png -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | src/** 5 | .gitignore 6 | vsc-extension-quickstart.md 7 | **/tsconfig.json 8 | **/tslint.json 9 | **/*.map 10 | **/*.ts -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "ms-vscode.vscode-typescript-tslint-plugin" 6 | ] 7 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "vscode-flutter-helper" 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 -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-string-throw": true, 4 | "no-unused-expression": true, 5 | "no-duplicate-variable": true, 6 | "curly": true, 7 | "class-name": true, 8 | "semicolon": [ 9 | true, 10 | "always" 11 | ], 12 | "triple-equals": true 13 | }, 14 | "defaultSeverity": "warning" 15 | } 16 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 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": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 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 | }, 6 | "search.exclude": { 7 | "out": true // set this to false to include "out" folder in search results 8 | }, 9 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 10 | "typescript.tsc.autoDetect": "off" 11 | } -------------------------------------------------------------------------------- /src/test/suite/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | import { before } from 'mocha'; 3 | 4 | // You can import and use all API from the 'vscode' module 5 | // as well as import your extension to test it 6 | import * as vscode from 'vscode'; 7 | // import * as myExtension from '../extension'; 8 | 9 | suite('Extension Test Suite', () => { 10 | before(() => { 11 | vscode.window.showInformationMessage('Start all tests.'); 12 | }); 13 | 14 | test('Sample test', () => { 15 | assert.equal(-1, [1, 2, 3].indexOf(5)); 16 | assert.equal(-1, [1, 2, 3].indexOf(0)); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "outDir": "out", 6 | "lib": [ 7 | "es6" 8 | ], 9 | "sourceMap": true, 10 | "rootDir": "src", 11 | "strict": true /* enable all strict type-checking options */ 12 | /* Additional Checks */ 13 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 14 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 15 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 16 | }, 17 | "exclude": [ 18 | "node_modules", 19 | ".vscode-test" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/test/runTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | 3 | import { runTests } from 'vscode-test'; 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 | -------------------------------------------------------------------------------- /dart.json: -------------------------------------------------------------------------------- 1 | { 2 | "Create a JSONSerializable Class": { 3 | "prefix": "jsc", 4 | "body": [ 5 | "@JsonSerializable()", 6 | "class $1 {", 7 | "", 8 | "\t$1();", 9 | "", 10 | "\tfactory $1.fromJson(Map json) => _$$1FromJson(json);", 11 | "\tMap toJson() => _$$1ToJson(this);", 12 | "}" 13 | ], 14 | "description": "Creates a JSONSerializable Model inside a dartlang file. Useful for flutter and dart for web." 15 | }, 16 | "Setup file for JSONSerializable annotation & Code Gen": { 17 | "prefix": "jsf", 18 | "body": [ 19 | "import 'package:json_annotation/json_annotation.dart';", 20 | "", 21 | "part '$TM_FILENAME_BASE.g.dart';" 22 | ], 23 | "description": "Setup a file which will have JSONSerializable annotated classes." 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /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 | }); 10 | mocha.useColors(true); 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 | e(err); 34 | } 35 | }); 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Akshar Patel 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 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 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 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ], 16 | "outFiles": [ 17 | "${workspaceFolder}/out/**/*.js" 18 | ], 19 | "preLaunchTask": "npm: watch" 20 | }, 21 | { 22 | "name": "Extension Tests", 23 | "type": "extensionHost", 24 | "request": "launch", 25 | "runtimeExecutable": "${execPath}", 26 | "args": [ 27 | "--extensionDevelopmentPath=${workspaceFolder}", 28 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" 29 | ], 30 | "outFiles": [ 31 | "${workspaceFolder}/out/test/**/*.js" 32 | ], 33 | "preLaunchTask": "npm: watch" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flutter Helpers VSCode Extension 2 | 3 | This extension currently helps you to easily write JSONSerializable annotated classes and allows you to run code generation for those classes. You can also watch the files so that code generation is faster. 4 | 5 | ## Setup your flutter project for code generation for JSONSerializable annotations 6 | 7 | In your pubspec.yaml file add the following libraries in the `dev_dependencies` and `dependencies` section: 8 | 9 | ``` 10 | dev_dependencies: 11 | // ... 12 | build_runner: ^1.0.0 13 | json_serializable: ^3.0.0 14 | 15 | dependencies: 16 | // ... 17 | json_annotation: ^2.4.0 18 | ``` 19 | 20 | ## Features 21 | 22 | ### Snippet for setting up a file with JSONSerializable annotated classes: `jsf` 23 | 24 | ![jsf](media/jsf.gif) 25 | 26 | ### Snippet for creating JSONSerializable annotated model: `jsc` 27 | 28 | ![jsc](media/jsc.gif) 29 | 30 | ### Run Code Gen for JSONSerializable annotated classes 31 | 32 | ![code gen](media/build.gif) 33 | 34 | ### Have build runner watch the JSONSerializable annotated classes and generate code on changes 35 | 36 | ![code gen & watch](media/watch.gif) 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vscode-flutter-helper", 3 | "displayName": "Flutter Helpers", 4 | "description": "Helper utilities for flutter projects", 5 | "version": "0.2.5", 6 | "publisher": "aksharpatel47", 7 | "icon": "media/flutter.png", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/aksharpatel47/vscode_flutter_helper" 11 | }, 12 | "engines": { 13 | "vscode": "^1.36.0" 14 | }, 15 | "categories": [ 16 | "Other" 17 | ], 18 | "activationEvents": [ 19 | "onCommand:flutterHelper.genModel", 20 | "onCommand:flutterHelper.genModelWatch" 21 | ], 22 | "main": "./out/extension.js", 23 | "contributes": { 24 | "commands": [ 25 | { 26 | "command": "flutterHelper.genModel", 27 | "title": "Flutter Helper: Code gen for JSONSerializable Classes" 28 | }, 29 | { 30 | "command": "flutterHelper.genModelWatch", 31 | "title": "Flutter Helper: Toggle Watch mode for Code gen for JSONSerializable Classes" 32 | } 33 | ], 34 | "snippets": [ 35 | { 36 | "language": "dart", 37 | "path": "./dart.json" 38 | } 39 | ] 40 | }, 41 | "scripts": { 42 | "vscode:prepublish": "npm run compile", 43 | "compile": "tsc -p ./", 44 | "watch": "tsc -watch -p ./", 45 | "pretest": "npm run compile", 46 | "test": "node ./out/test/runTest.js" 47 | }, 48 | "devDependencies": { 49 | "@types/glob": "^7.1.1", 50 | "@types/mocha": "^5.2.6", 51 | "@types/node": "^10.12.21", 52 | "@types/vscode": "^1.36.0", 53 | "glob": "^7.1.4", 54 | "mocha": "^6.1.4", 55 | "typescript": "^3.3.1", 56 | "tslint": "^5.12.1", 57 | "vscode-test": "^1.0.0-next.0" 58 | }, 59 | "dependencies": { 60 | "tree-kill": "^1.2.1" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /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 | ## Get up and running straight away 13 | 14 | * Press `F5` to open a new window with your extension loaded. 15 | * Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. 16 | * Set breakpoints in your code inside `src/extension.ts` to debug your extension. 17 | * Find output from your extension in the debug console. 18 | 19 | ## Make changes 20 | 21 | * You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. 22 | * You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. 23 | 24 | ## Explore the API 25 | 26 | * You can open the full set of our API when you open the file `node_modules/vscode/vscode.d.ts`. 27 | 28 | ## Run tests 29 | 30 | * Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`. 31 | * Press `F5` to run the tests in a new window with your extension loaded. 32 | * See the output of the test result in the debug console. 33 | * Make changes to `test/extension.test.ts` or create new test files inside the `test` folder. 34 | * By convention, the test runner will only consider files matching the name pattern `**.test.ts`. 35 | * You can create folders inside the `test` folder to structure your tests any way you want. 36 | 37 | ## Go further 38 | 39 | * Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/testing-extension). 40 | * [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace. 41 | * Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration). 42 | -------------------------------------------------------------------------------- /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 { spawn, ChildProcess } from "child_process"; 5 | import * as kill from "tree-kill"; 6 | 7 | let _channel: vscode.OutputChannel; 8 | let _watchProcess: ChildProcess; 9 | 10 | function getOutputChannel(): vscode.OutputChannel { 11 | if (!_channel) { 12 | _channel = vscode.window.createOutputChannel("Flutter Helper Logs"); 13 | } 14 | 15 | return _channel; 16 | } 17 | 18 | // this method is called when your extension is activated 19 | // your extension is activated the very first time the command is executed 20 | export function activate(context: vscode.ExtensionContext) { 21 | // Use the console to output diagnostic information (console.log) and errors (console.error) 22 | // This line of code will only be executed once when your extension is activated 23 | console.log( 24 | 'Congratulations, your extension "vscode-flutter-helper" is now active!' 25 | ); 26 | 27 | // The command has been defined in the package.json file 28 | // Now provide the implementation of the command with registerCommand 29 | // The commandId parameter must match the command field in package.json 30 | let disposable = vscode.commands.registerCommand( 31 | "flutterHelper.genModel", 32 | () => { 33 | // The code you place here will be executed every time your command is executed 34 | 35 | let process = spawn( 36 | "flutter", 37 | [ 38 | "packages", 39 | "pub", 40 | "run", 41 | "build_runner", 42 | "build", 43 | "--delete-conflicting-outputs" 44 | ], 45 | { 46 | shell: true, 47 | cwd: vscode.workspace.rootPath 48 | // detached: true 49 | } 50 | ); 51 | 52 | process.stdout.on("data", data => { 53 | console.log(`stdout: ${data}`); 54 | getOutputChannel().appendLine(data); 55 | }); 56 | 57 | process.stderr.on("data", data => { 58 | console.error(`stderr: ${data}`); 59 | getOutputChannel().appendLine(data); 60 | }); 61 | 62 | process.on("close", code => { 63 | console.log(`child process exited with code ${code}`); 64 | getOutputChannel().appendLine(`child process exited with code ${code}`); 65 | }); 66 | 67 | // Display a message box to the user 68 | // vscode.window.showInformationMessage("Hello World!"); 69 | } 70 | ); 71 | 72 | context.subscriptions.push(disposable); 73 | 74 | context.subscriptions.push( 75 | vscode.commands.registerCommand("flutterHelper.genModelWatch", () => { 76 | if (_watchProcess && !_watchProcess.killed) { 77 | vscode.window.showInformationMessage("Stopped Codegen Process"); 78 | kill(_watchProcess.pid); 79 | _watchProcess.kill(); 80 | } else { 81 | vscode.window.showInformationMessage("Started Codegen Process"); 82 | _watchProcess = spawn( 83 | "flutter", 84 | [ 85 | "packages", 86 | "pub", 87 | "run", 88 | "build_runner", 89 | "watch", 90 | "--delete-conflicting-outputs" 91 | ], 92 | { 93 | shell: true, 94 | cwd: vscode.workspace.rootPath 95 | // detached: true 96 | } 97 | ); 98 | 99 | _watchProcess.stdout.on("data", data => { 100 | console.log(`stdout: ${data}`); 101 | getOutputChannel().appendLine(data); 102 | }); 103 | 104 | _watchProcess.stderr.on("data", data => { 105 | console.error(`stderr: ${data}`); 106 | getOutputChannel().appendLine(data); 107 | }); 108 | 109 | _watchProcess.on("close", code => { 110 | console.log(`child process exited with code ${code}`); 111 | getOutputChannel().appendLine( 112 | `child process exited with code ${code}` 113 | ); 114 | }); 115 | } 116 | }) 117 | ); 118 | } 119 | 120 | // this method is called when your extension is deactivated 121 | export function deactivate() { 122 | if (_watchProcess && !_watchProcess.killed) { 123 | kill(_watchProcess.pid); 124 | _watchProcess.kill(); 125 | } 126 | } 127 | --------------------------------------------------------------------------------