├── .eslintrc.json ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── .vscodeignore ├── CHANGELOG.md ├── DEVELOPMENT.md ├── LICENSE ├── Makefile ├── README.md ├── package-lock.json ├── package.json ├── resources ├── dark │ └── add.svg ├── images │ ├── deploy-lambda.gif │ ├── deploy-lambda.png │ ├── invoke-lambda.gif │ └── invoke-lambda.png ├── light │ └── add.svg └── localstack-icon-256x256.png ├── src ├── extension.ts ├── lambda │ ├── deployCommand.ts │ ├── infoCommand.ts │ ├── invokeCommand.ts │ └── myCodeLensProvider.ts ├── test │ ├── runTest.ts │ └── suite │ │ ├── extension.test.ts │ │ └── index.ts └── utils │ ├── multiStepInput.ts │ ├── outputChannel.ts │ ├── shell.ts │ └── templateFinder.ts ├── tsconfig.json ├── vsc-extension-quickstart.md └── webpack.config.js /.eslintrc.json: -------------------------------------------------------------------------------- 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 | } 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | dist 3 | node_modules 4 | .vscode-test/ 5 | *.vsix 6 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 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 | } 6 | -------------------------------------------------------------------------------- /.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 | "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 | } 36 | -------------------------------------------------------------------------------- /.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 | "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: -------------------------------------------------------------------------------- 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 | } 41 | -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 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 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | **Documents all notable changes to the LocalStack VSCode Extension.** 4 | 5 | ## 0.1.1 (2023-07-13) 6 | 7 | - Update readme with marketplace link 8 | - Add animated gifs for features 9 | 10 | ## 0.1.0 (2023-07-13) 11 | 12 | Initial preview release. 13 | 14 | - Add feature deploy Lambda to LocalStack 15 | - Add feature invoke Lambda in LocalStack 16 | - Add Python CodeLens for triggering deploy and invoke commands 17 | -------------------------------------------------------------------------------- /DEVELOPMENT.md: -------------------------------------------------------------------------------- 1 | # Development 2 | 3 | **Describes how to develop the LocalStack VSCode Extension.** 4 | 5 | ## Quicklinks 6 | 7 | * [Extension API](https://code.visualstudio.com/api) 8 | * [UX Guidelines](https://code.visualstudio.com/api/ux-guidelines/overview) 9 | 10 | ## Requirements 11 | 12 | * Node.js (e.g., `16.x`) 13 | * [VSCode](https://code.visualstudio.com/) with the recommended extensions [amodio.tsl-problem-matcher](https://marketplace.visualstudio.com/items?itemName=amodio.tsl-problem-matcher) and [dbaeumer.vscode-eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) 14 | * The [requirements](./README.md#requirements) of the LocalStack extension itself 15 | 16 | ## Getting Started 17 | 18 | 1. Install dependencies `npm install` 19 | 2. Start auto-recompile `npm run watch` 20 | 3. Launch `"Run Extension"` in the `"Run and Debug"` window 21 | 22 | ## Publish 23 | 24 | 1. Bump version in `package.json` and run `npm install` to update `package-lock.json` as well 25 | 2. Add changelog to `CHANGELOG.md` 26 | 3. Package using `vsce package` 27 | 4. Publish using `vsce publish` 28 | 29 | For more details, refer to [Publishing Extensions](https://code.visualstudio.com/api/working-with-extensions/publishing-extension). 30 | 31 | 32 | 33 | ## Known Issues 34 | 35 | * Compile warning `Module not found: Error: Can't resolve 'aws-crt'` 36 | 37 | ```log 38 | WARNING in ./node_modules/@aws-sdk/util-user-agent-node/dist-es/is-crt-available.js 3:78-96 39 | Module not found: Error: Can't resolve 'aws-crt' in '/Users/joe/Projects/LocalStack/localstack-vscode-extension/node_modules/@aws-sdk/util-user-agent-node/dist-es' 40 | @ ./node_modules/@aws-sdk/util-user-agent-node/dist-es/index.js 4:0-52 15:25-39 41 | @ ./node_modules/@aws-sdk/client-cloudformation/dist-es/runtimeConfig.js 4:0-65 29:12-28 42 | @ ./node_modules/@aws-sdk/client-cloudformation/dist-es/CloudFormationClient.js 12:0-73 16:26-44 43 | @ ./node_modules/@aws-sdk/client-cloudformation/dist-es/index.js 1:0-39 1:0-39 44 | @ ./src/lambda/invokeCommand.ts 6:32-73 45 | @ ./src/extension.ts 9:24-57 46 | ``` 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2023+ LocalStack contributors 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: watch 2 | 3 | install: 4 | npm install 5 | 6 | watch: 7 | npm run watch 8 | 9 | package: 10 | vsce package 11 | 12 | publish: 13 | vsce publish 14 | 15 | .PHONY: install watch package publish 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LocalStack VSCode Extension (Preview) 2 | 3 | ![Marketplace Version](https://img.shields.io/vscode-marketplace/v/LocalStack.localstack.svg) 4 | 5 | **Deploy and invoke Lambda functions in LocalStack directly from VSCode.** 6 | 7 | 👉 Get our [LocalStack VSCode Extension](https://marketplace.visualstudio.com/items?itemName=LocalStack.localstack) from the Visual Studio Marketplace. 8 | 9 | > 🧪 We encourage you to test the current preview version and share your feedback with us. 10 | 11 | ## Features 12 | 13 | Deploy Python Lambda function directly from your code using an [AWS SAM](https://github.com/aws/serverless-application-model) or [AWS CloudFormation](https://aws.amazon.com/cloudformation/resources/templates/) template: 14 | ![Deploy Lambda function](resources/images/deploy-lambda.gif) 15 | 16 | Invoke Lambda function: 17 | ![Invoke Lambda function](resources/images/invoke-lambda.gif) 18 | 19 | ## Requirements 20 | 21 | * [samlocal](https://github.com/localstack/aws-sam-cli-local) command line wrapper around the [AWS SAM CLI](https://github.com/aws/aws-sam-cli) for use with [LocalStack](https://github.com/localstack/localstack). 22 | * [LocalStack](https://docs.localstack.cloud/getting-started/) running in the background. 23 | 24 | ## Known Issues 25 | 26 | * Limitations 27 | * The CodeLens for "Deploy Lambda function" always appears at the first line of each Python file 28 | * "Invoke Lambda function" currently only works in the region `us-east-1` and with an empty payload. 29 | 30 | ## Feedback 31 | 32 | 33 | 34 | We are looking forward to your feedback in our Community Slack [slack.localstack.cloud](https://slack.localstack.cloud/). 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "localstack", 3 | "displayName": "LocalStack", 4 | "description": "Deploy Lambda functions to LocalStack", 5 | "version": "0.1.1", 6 | "preview": true, 7 | "publisher": "LocalStack", 8 | "engines": { 9 | "vscode": "^1.78.0" 10 | }, 11 | "categories": [ 12 | "Other" 13 | ], 14 | "keywords": ["LocalStack", "Lambda", "python", "AWS SAM", "CloudFormation"], 15 | "icon": "resources/localstack-icon-256x256.png", 16 | "galleryBanner": { 17 | "color": "#39227A", 18 | "theme": "dark" 19 | }, 20 | "license": "Apache-2.0", 21 | "homepage": "https://github.com/localstack/localstack-vscode-extension/blob/main/README.md", 22 | "bugs": { 23 | "url": "https://github.com/localstack/localstack-vscode-extension/issues", 24 | "email": "sean@contoso.com" 25 | }, 26 | "repository": { 27 | "type": "git", 28 | "url": "https://github.com/localstack/localstack-vscode-extension.git" 29 | }, 30 | "activationEvents": [ 31 | "onLanguage:python" 32 | ], 33 | "main": "./dist/extension.js", 34 | "contributes": { 35 | "commands": [ 36 | { 37 | "command": "localstack.deploy", 38 | "title": "Deploy Lambda function", 39 | "category": "LocalStack" 40 | }, 41 | { 42 | "command": "localstack.invoke", 43 | "title": "Invoke Lambda function", 44 | "category": "LocalStack" 45 | }, 46 | { 47 | "command": "localstack.info", 48 | "title": "Print samlocal version", 49 | "category": "LocalStack" 50 | } 51 | ] 52 | }, 53 | "scripts": { 54 | "vscode:prepublish": "npm run package", 55 | "compile": "webpack", 56 | "watch": "webpack --watch", 57 | "package": "webpack --mode production --devtool hidden-source-map", 58 | "compile-tests": "tsc -p . --outDir out", 59 | "watch-tests": "tsc -p . -w --outDir out", 60 | "pretest": "npm run compile-tests && npm run compile && npm run lint", 61 | "lint": "eslint src --ext ts", 62 | "test": "node ./out/test/runTest.js" 63 | }, 64 | "devDependencies": { 65 | "@types/glob": "^8.1.0", 66 | "@types/mocha": "^10.0.1", 67 | "@types/node": "16.x", 68 | "@types/vscode": "^1.78.0", 69 | "@typescript-eslint/eslint-plugin": "^5.59.1", 70 | "@typescript-eslint/parser": "^5.59.1", 71 | "@vscode/test-electron": "^2.3.0", 72 | "eslint": "^8.39.0", 73 | "mocha": "^10.2.0", 74 | "ts-loader": "^9.4.2", 75 | "typescript": "^5.0.4", 76 | "webpack": "^5.81.0", 77 | "webpack-cli": "^5.0.2" 78 | }, 79 | "dependencies": { 80 | "@aws-sdk/client-cloudformation": "^3.352.0", 81 | "@aws-sdk/client-lambda": "^3.352.0", 82 | "glob": "^8.1.0" 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /resources/dark/add.svg: -------------------------------------------------------------------------------- 1 | Layer 1 -------------------------------------------------------------------------------- /resources/images/deploy-lambda.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/localstack/localstack-vscode-extension/50ab76a2e7252036dbbfa2e8b5dd5d0b5d86e7c4/resources/images/deploy-lambda.gif -------------------------------------------------------------------------------- /resources/images/deploy-lambda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/localstack/localstack-vscode-extension/50ab76a2e7252036dbbfa2e8b5dd5d0b5d86e7c4/resources/images/deploy-lambda.png -------------------------------------------------------------------------------- /resources/images/invoke-lambda.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/localstack/localstack-vscode-extension/50ab76a2e7252036dbbfa2e8b5dd5d0b5d86e7c4/resources/images/invoke-lambda.gif -------------------------------------------------------------------------------- /resources/images/invoke-lambda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/localstack/localstack-vscode-extension/50ab76a2e7252036dbbfa2e8b5dd5d0b5d86e7c4/resources/images/invoke-lambda.png -------------------------------------------------------------------------------- /resources/light/add.svg: -------------------------------------------------------------------------------- 1 | Layer 1 -------------------------------------------------------------------------------- /resources/localstack-icon-256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/localstack/localstack-vscode-extension/50ab76a2e7252036dbbfa2e8b5dd5d0b5d86e7c4/resources/localstack-icon-256x256.png -------------------------------------------------------------------------------- /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 | 5 | import { showInformationMessage } from './lambda/infoCommand'; 6 | import { deployLambda } from './lambda/deployCommand'; 7 | import { invokeLambda } from './lambda/invokeCommand'; 8 | import MyCodeLensProvider from './lambda/myCodeLensProvider'; 9 | 10 | // This method is called when your extension is activated 11 | // Your extension is activated the very first time the command is executed 12 | export function activate(context: vscode.ExtensionContext) { 13 | 14 | // Use the console to output diagnostic information (console.log) and errors (console.error) 15 | // This line of code will only be executed once when your extension is activated 16 | console.log('Congratulations, your extension "localstack" is now active!'); 17 | 18 | context.subscriptions.push( 19 | // The command has been defined in the package.json file 20 | // Now provide the implementation of the command with registerCommand 21 | // The commandId parameter must match the command field in package.json 22 | vscode.commands.registerCommand('localstack.info', async () => { 23 | await showInformationMessage(); 24 | }), 25 | vscode.commands.registerCommand('localstack.deploy', async (handlerUri: vscode.Uri | undefined) => { 26 | await deployLambda(handlerUri, context); 27 | }), 28 | vscode.commands.registerCommand('localstack.invoke', async () => { 29 | await invokeLambda(); 30 | }), 31 | ); 32 | 33 | // Get a document selector for the CodeLens provider 34 | // This one is any file that has the language of python 35 | const docSelector = { 36 | language: "python", 37 | scheme: "file" 38 | }; 39 | 40 | // Register our CodeLens provider 41 | const codeLensProviderDisposable = vscode.languages.registerCodeLensProvider(docSelector, new MyCodeLensProvider()); 42 | 43 | // Push the command and CodeLens provider to the context so it can be disposed of later 44 | context.subscriptions.push(codeLensProviderDisposable); 45 | } 46 | 47 | // This method is called when your extension is deactivated 48 | export function deactivate() {} 49 | -------------------------------------------------------------------------------- /src/lambda/deployCommand.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from "vscode"; 2 | import { execShell } from "../utils/shell"; 3 | import { CancellationToken, QuickInputButton, QuickPickItem, Uri, window } from "vscode"; 4 | import { MultiStepInput } from "../utils/multiStepInput"; 5 | import { findCFNTemplates } from "../utils/templateFinder"; 6 | 7 | export async function deployLambda(handlerUri: vscode.Uri | undefined, context: vscode.ExtensionContext) { 8 | // Based on VSCode multi-step sample: 9 | // https://github.com/microsoft/vscode-extension-samples/blob/main/quickinput-sample/src/multiStepInput.ts 10 | class MyButton implements QuickInputButton { 11 | constructor(public iconPath: { light: Uri; dark: Uri; }, public tooltip: string) { } 12 | } 13 | 14 | const createDeploymentConfigButton = new MyButton({ 15 | dark: Uri.file(context.asAbsolutePath('resources/dark/add.svg')), 16 | light: Uri.file(context.asAbsolutePath('resources/light/add.svg')), 17 | }, 'Create Deployment Configuration ...'); 18 | 19 | if (!handlerUri) { 20 | vscode.window.showErrorMessage('Handler undefined. Please use a CodeLens to invoke the deploy command.'); 21 | return undefined; 22 | } 23 | const workspaceFolder = vscode.workspace.getWorkspaceFolder(handlerUri); 24 | if (!workspaceFolder) { 25 | vscode.window.showErrorMessage('Workspace undefined. Please open a workspace.'); 26 | return undefined; 27 | } 28 | const templates = await findCFNTemplates(workspaceFolder.uri.fsPath); 29 | 30 | // MAYBE: implement Quick Deploy 31 | // MAYBE: implement custom deployment configuration ... 32 | const staticItems = [ 33 | "template.yaml", 34 | "output/template.yaml", 35 | "template.yaml:HelloWorldFunction (goal)", 36 | "Quick Deploy (extension)", 37 | "Create Deployment Configuration ... (manual)", 38 | ]; 39 | const deploymentConfigs: QuickPickItem[] = templates.map((label) => ({ label })); 40 | 41 | interface State { 42 | title: string; 43 | step: number; 44 | totalSteps: number; 45 | deploymentConfig: QuickPickItem | string; 46 | stackName: string; 47 | runtime: QuickPickItem; 48 | } 49 | 50 | async function collectInputs() { 51 | const state = {} as Partial; 52 | await MultiStepInput.run(input => pickDeploymentConfig(input, state)); 53 | return state as State; 54 | } 55 | 56 | const title = 'Deploy a Lambda Function'; 57 | 58 | async function pickDeploymentConfig(input: MultiStepInput, state: Partial) { 59 | const pick = await input.showQuickPick({ 60 | title, 61 | step: 1, 62 | totalSteps: 2, 63 | placeholder: 'Pick a deployment configuration', 64 | items: deploymentConfigs, 65 | activeItem: typeof state.deploymentConfig !== 'string' ? state.deploymentConfig : undefined, 66 | buttons: [createDeploymentConfigButton], 67 | shouldResume: shouldResume 68 | }); 69 | // TODO: handle custom creation of deployment configuration 70 | if (pick instanceof MyButton) { 71 | return (input: MultiStepInput) => inputDeploymentConfigName(input, state); 72 | } 73 | state.deploymentConfig = pick; 74 | if (pick.label === 'Quick Deploy') { 75 | return (input: MultiStepInput) => pickRuntime(input, state); 76 | } else { 77 | return (input: MultiStepInput) => inputStackName(input, state); 78 | } 79 | } 80 | 81 | // TODO: handle creation of custom deployment configuration 82 | async function inputDeploymentConfigName(input: MultiStepInput, state: Partial) { 83 | state.deploymentConfig = await input.showInputBox({ 84 | title, 85 | step: 2, 86 | totalSteps: 4, 87 | value: typeof state.deploymentConfig === 'string' ? state.deploymentConfig : '', 88 | prompt: 'Choose a unique name for the deployment configuration', 89 | validate: validateNameIsUnique, 90 | shouldResume: shouldResume 91 | }); 92 | return (input: MultiStepInput) => inputStackName(input, state); 93 | } 94 | 95 | async function inputStackName(input: MultiStepInput, state: Partial) { 96 | const additionalSteps = typeof state.deploymentConfig === 'string' ? 1 : 0; 97 | // TODO: Remember current value when navigating back. 98 | state.stackName = await input.showInputBox({ 99 | title, 100 | step: 2 + additionalSteps, 101 | totalSteps: 2 + additionalSteps, 102 | value: state.stackName || '', 103 | prompt: 'Choose a unique name for the CloudFormation Stack', 104 | validate: validateNameIsUnique, 105 | shouldResume: shouldResume 106 | }); 107 | } 108 | 109 | async function pickRuntime(input: MultiStepInput, state: Partial) { 110 | const additionalSteps = typeof state.deploymentConfig === 'string' ? 1 : 0; 111 | const runtimes = await getAvailableRuntimes(undefined /* TODO: token */); 112 | // TODO: Remember currently active item when navigating back. 113 | state.runtime = await input.showQuickPick({ 114 | title, 115 | step: 3 + additionalSteps, 116 | totalSteps: 3 + additionalSteps, 117 | placeholder: 'Pick a runtime', 118 | items: runtimes, 119 | activeItem: state.runtime, 120 | shouldResume: shouldResume 121 | }); 122 | } 123 | 124 | function shouldResume() { 125 | // Could show a notification with the option to resume. 126 | return new Promise((resolve, reject) => { 127 | // noop 128 | }); 129 | } 130 | 131 | async function validateNameIsUnique(name: string) { 132 | // ...validate... 133 | await new Promise(resolve => setTimeout(resolve, 1000)); 134 | return name === 'vscode' ? 'Name not unique' : undefined; 135 | } 136 | 137 | async function getAvailableRuntimes(token?: CancellationToken): Promise { 138 | // await new Promise(resolve => setTimeout(resolve, 1000)); 139 | // Source: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html 140 | return ['python3.7', 'python3.8', 'python3.9', 'python3.10'] 141 | .map(label => ({ label })); 142 | } 143 | 144 | const state = await collectInputs(); 145 | 146 | // The code you place here will be executed every time your command is executed 147 | vscode.window.showInformationMessage(`Deploying Lambda function to LocalStack using ${state.stackName} ...`); 148 | // HACK: workaround type checking 149 | const deploymentConfig: any = state.deploymentConfig; 150 | const deployCmd = `samlocal deploy --template ${deploymentConfig.label} --stack-name ${state.stackName} --resolve-s3 --no-confirm-changeset` 151 | const stdout = await execShell(`cd ${workspaceFolder.uri.fsPath} && ${deployCmd}`); 152 | vscode.window.showInformationMessage(`Lambda function deployed to LocalStack.`); 153 | } 154 | -------------------------------------------------------------------------------- /src/lambda/infoCommand.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import { execShell } from '../utils/shell'; 3 | 4 | export async function showInformationMessage() { 5 | const stdout = await execShell('samlocal --version'); 6 | vscode.window.showInformationMessage(`samlocal version: ${stdout}`); 7 | } 8 | -------------------------------------------------------------------------------- /src/lambda/invokeCommand.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import { logOutputChannel, showLogOutputChannel } from '../utils/outputChannel'; 3 | import { CloudFormationClient, DescribeStackResourcesCommand, DescribeStacksCommand } from "@aws-sdk/client-cloudformation"; 4 | import { LambdaClient, InvokeCommand, InvocationRequest } from "@aws-sdk/client-lambda"; 5 | import { QuickPickItem } from 'vscode'; 6 | import { MultiStepInput } from '../utils/multiStepInput'; 7 | 8 | export async function invokeLambda() { 9 | const clientConfig = { 10 | region: "us-east-1", 11 | endpoint: "http://localhost:4566", 12 | credentials: { 13 | accessKeyId: 'test', 14 | secretAccessKey: 'test' 15 | } 16 | }; 17 | const cloudformationClient = new CloudFormationClient(clientConfig); 18 | const lambdaClient = new LambdaClient(clientConfig); 19 | 20 | interface State { 21 | title: string; 22 | step: number; 23 | totalSteps: number; 24 | stackName: QuickPickItem; 25 | functionName: QuickPickItem; 26 | } 27 | 28 | async function collectInputs() { 29 | const state = {} as Partial; 30 | await MultiStepInput.run(input => pickStackName(input, state)); 31 | return state as State; 32 | } 33 | 34 | const title = 'Invoke a Lambda Function'; 35 | 36 | async function pickStackName(input: MultiStepInput, state: Partial) { 37 | const describeStacksCommand = new DescribeStacksCommand({}); 38 | try { 39 | const stacksResponse = await cloudformationClient.send(describeStacksCommand); 40 | const stackNames = stacksResponse.Stacks?.map(stack => stack.StackName!); 41 | // TODO: fix typings mess 42 | if (stackNames === undefined) { 43 | return undefined; 44 | } 45 | const stackNamesPicks: QuickPickItem[] = stackNames.map((label) => ({ label })); 46 | state.stackName = await input.showQuickPick({ 47 | title, 48 | step: 1, 49 | totalSteps: 2, 50 | placeholder: 'Pick a CloudFormation stack name', 51 | items: stackNamesPicks, 52 | activeItem: typeof state.stackName !== 'string' ? state.stackName : undefined, 53 | shouldResume: shouldResume 54 | }); 55 | 56 | return (input: MultiStepInput) => pickFunctionName(input, state); 57 | } catch (error) { 58 | console.error(error); 59 | } 60 | } 61 | 62 | async function pickFunctionName(input: MultiStepInput, state: Partial) { 63 | const stackName = state.stackName?.label; 64 | const params = { StackName: stackName }; 65 | const describeStackResourcesCommand = new DescribeStackResourcesCommand(params); 66 | try { 67 | const resourcesResponse = await cloudformationClient.send(describeStackResourcesCommand); 68 | const functionNames = resourcesResponse.StackResources?.filter(resource => resource.ResourceType === 'AWS::Lambda::Function').map(resource => resource.PhysicalResourceId!); 69 | // TODO: fix typings mess 70 | if (functionNames === undefined) { 71 | return undefined; 72 | } 73 | const functionNamesPicks: QuickPickItem[] = functionNames.map((label) => ({ label })); 74 | state.functionName = await input.showQuickPick({ 75 | title, 76 | step: 2, 77 | totalSteps: 2, 78 | placeholder: 'Pick a function name', 79 | items: functionNamesPicks, 80 | activeItem: typeof state.functionName !== 'string' ? state.functionName : undefined, 81 | shouldResume: shouldResume 82 | }); 83 | } catch (error) { 84 | console.error(error); 85 | } 86 | } 87 | 88 | function shouldResume() { 89 | // Could show a notification with the option to resume. 90 | return new Promise((resolve, reject) => { 91 | // noop 92 | }); 93 | } 94 | 95 | const state = await collectInputs(); 96 | 97 | const functionName = state.functionName.label; 98 | const payload = {}; 99 | const invokeInput: InvocationRequest = { 100 | FunctionName: functionName, 101 | InvocationType: 'RequestResponse', 102 | LogType: 'Tail', 103 | Payload: Buffer.from(JSON.stringify(payload), "utf8"), 104 | // Qualifier: 'VERSION|ALIAS', 105 | }; 106 | const invokeCommand = new InvokeCommand(invokeInput); 107 | vscode.window.showInformationMessage(`Invoke Lambda function ${functionName} in LocalStack.`); 108 | try { 109 | const invocationResponse = await lambdaClient.send(invokeCommand); 110 | if (invocationResponse.LogResult) { 111 | const invocationLogs = Buffer.from(invocationResponse.LogResult, "base64").toString("utf8"); 112 | logOutputChannel.appendLine(invocationLogs); 113 | } 114 | if (invocationResponse.Payload) { 115 | const payloadResponseString = Buffer.from(invocationResponse.Payload).toString(); 116 | try { 117 | const payloadJson = JSON.parse(payloadResponseString); 118 | const prettyPayload = JSON.stringify(payloadJson, null, 2); 119 | logOutputChannel.appendLine(prettyPayload); 120 | } catch { 121 | logOutputChannel.appendLine(payloadResponseString); 122 | } 123 | } 124 | showLogOutputChannel(); 125 | } catch (error) { 126 | console.error(error); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/lambda/myCodeLensProvider.ts: -------------------------------------------------------------------------------- 1 | // Initially based on: https://github.com/lannonbr/vscode-codelens-example/blob/master/src/myCodeLensProvider.ts 2 | 3 | import { 4 | CodeLensProvider, 5 | TextDocument, 6 | CodeLens, 7 | Range, 8 | Command, 9 | } from "vscode"; 10 | 11 | class MyCodeLensProvider implements CodeLensProvider { 12 | // Each provider requires a provideCodeLenses function which will give the various documents 13 | // the code lenses 14 | async provideCodeLenses(document: TextDocument): Promise { 15 | // Define where the CodeLens will exist 16 | // TODO: show directly at lambda handler 17 | const topOfDocument = new Range(0, 0, 0, 0); 18 | 19 | // Define what command we want to trigger when activating the CodeLens 20 | const deployCommand: Command = { 21 | command: "localstack.deploy", 22 | title: "LocalStack: Deploy Lambda function", 23 | // TODO: add arguments with document.uri 24 | arguments: [document.uri] 25 | }; 26 | 27 | const invokeCommand: Command = { 28 | command: "localstack.invoke", 29 | title: "LocalStack: Invoke Lambda function", 30 | }; 31 | 32 | const deployCodeLens = new CodeLens(topOfDocument, deployCommand); 33 | const invokeCodeLens = new CodeLens(topOfDocument, invokeCommand); 34 | 35 | return [deployCodeLens, invokeCodeLens]; 36 | } 37 | } 38 | 39 | export default MyCodeLensProvider; 40 | -------------------------------------------------------------------------------- /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', err); 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 | -------------------------------------------------------------------------------- /src/utils/multiStepInput.ts: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------------------- 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. 4 | *--------------------------------------------------------------------------------------------*/ 5 | 6 | // Source: https://github.com/microsoft/vscode-extension-samples/blob/main/quickinput-sample/src/multiStepInput.ts#L24 7 | 8 | // ------------------------------------------------------- 9 | // Helper code that wraps the API for the multi-step case. 10 | // ------------------------------------------------------- 11 | 12 | import { Disposable, QuickInput, QuickInputButton, QuickInputButtons, QuickPickItem, window } from "vscode"; 13 | 14 | 15 | export class InputFlowAction { 16 | static back = new InputFlowAction(); 17 | static cancel = new InputFlowAction(); 18 | static resume = new InputFlowAction(); 19 | } 20 | 21 | export type InputStep = (input: MultiStepInput) => Thenable; 22 | 23 | export interface QuickPickParameters { 24 | title: string; 25 | step: number; 26 | totalSteps: number; 27 | items: T[]; 28 | activeItem?: T; 29 | ignoreFocusOut?: boolean; 30 | placeholder: string; 31 | buttons?: QuickInputButton[]; 32 | shouldResume: () => Thenable; 33 | } 34 | 35 | export interface InputBoxParameters { 36 | title: string; 37 | step: number; 38 | totalSteps: number; 39 | value: string; 40 | prompt: string; 41 | validate: (value: string) => Promise; 42 | buttons?: QuickInputButton[]; 43 | ignoreFocusOut?: boolean; 44 | placeholder?: string; 45 | shouldResume: () => Thenable; 46 | } 47 | 48 | export class MultiStepInput { 49 | 50 | static async run(start: InputStep) { 51 | const input = new MultiStepInput(); 52 | return input.stepThrough(start); 53 | } 54 | 55 | private current?: QuickInput; 56 | private steps: InputStep[] = []; 57 | 58 | private async stepThrough(start: InputStep) { 59 | let step: InputStep | void = start; 60 | while (step) { 61 | this.steps.push(step); 62 | if (this.current) { 63 | this.current.enabled = false; 64 | this.current.busy = true; 65 | } 66 | try { 67 | step = await step(this); 68 | } catch (err) { 69 | if (err === InputFlowAction.back) { 70 | this.steps.pop(); 71 | step = this.steps.pop(); 72 | } else if (err === InputFlowAction.resume) { 73 | step = this.steps.pop(); 74 | } else if (err === InputFlowAction.cancel) { 75 | step = undefined; 76 | } else { 77 | throw err; 78 | } 79 | } 80 | } 81 | if (this.current) { 82 | this.current.dispose(); 83 | } 84 | } 85 | 86 | async showQuickPick>({ title, step, totalSteps, items, activeItem, ignoreFocusOut, placeholder, buttons, shouldResume }: P) { 87 | const disposables: Disposable[] = []; 88 | try { 89 | return await new Promise((resolve, reject) => { 90 | const input = window.createQuickPick(); 91 | input.title = title; 92 | input.step = step; 93 | input.totalSteps = totalSteps; 94 | input.ignoreFocusOut = ignoreFocusOut ?? false; 95 | input.placeholder = placeholder; 96 | input.items = items; 97 | if (activeItem) { 98 | input.activeItems = [activeItem]; 99 | } 100 | input.buttons = [ 101 | ...(this.steps.length > 1 ? [QuickInputButtons.Back] : []), 102 | ...(buttons || []) 103 | ]; 104 | disposables.push( 105 | input.onDidTriggerButton(item => { 106 | if (item === QuickInputButtons.Back) { 107 | reject(InputFlowAction.back); 108 | } else { 109 | resolve(item); 110 | } 111 | }), 112 | input.onDidChangeSelection(items => resolve(items[0])), 113 | input.onDidHide(() => { 114 | (async () => { 115 | reject(shouldResume && await shouldResume() ? InputFlowAction.resume : InputFlowAction.cancel); 116 | })() 117 | .catch(reject); 118 | }) 119 | ); 120 | if (this.current) { 121 | this.current.dispose(); 122 | } 123 | this.current = input; 124 | this.current.show(); 125 | }); 126 | } finally { 127 | disposables.forEach(d => d.dispose()); 128 | } 129 | } 130 | 131 | async showInputBox

({ title, step, totalSteps, value, prompt, validate, buttons, ignoreFocusOut, placeholder, shouldResume }: P) { 132 | const disposables: Disposable[] = []; 133 | try { 134 | return await new Promise((resolve, reject) => { 135 | const input = window.createInputBox(); 136 | input.title = title; 137 | input.step = step; 138 | input.totalSteps = totalSteps; 139 | input.value = value || ''; 140 | input.prompt = prompt; 141 | input.ignoreFocusOut = ignoreFocusOut ?? false; 142 | input.placeholder = placeholder; 143 | input.buttons = [ 144 | ...(this.steps.length > 1 ? [QuickInputButtons.Back] : []), 145 | ...(buttons || []) 146 | ]; 147 | let validating = validate(''); 148 | disposables.push( 149 | input.onDidTriggerButton(item => { 150 | if (item === QuickInputButtons.Back) { 151 | reject(InputFlowAction.back); 152 | } else { 153 | resolve(item); 154 | } 155 | }), 156 | input.onDidAccept(async () => { 157 | const value = input.value; 158 | input.enabled = false; 159 | input.busy = true; 160 | if (!(await validate(value))) { 161 | resolve(value); 162 | } 163 | input.enabled = true; 164 | input.busy = false; 165 | }), 166 | input.onDidChangeValue(async text => { 167 | const current = validate(text); 168 | validating = current; 169 | const validationMessage = await current; 170 | if (current === validating) { 171 | input.validationMessage = validationMessage; 172 | } 173 | }), 174 | input.onDidHide(() => { 175 | (async () => { 176 | reject(shouldResume && await shouldResume() ? InputFlowAction.resume : InputFlowAction.cancel); 177 | })() 178 | .catch(reject); 179 | }) 180 | ); 181 | if (this.current) { 182 | this.current.dispose(); 183 | } 184 | this.current = input; 185 | this.current.show(); 186 | }); 187 | } finally { 188 | disposables.forEach(d => d.dispose()); 189 | } 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /src/utils/outputChannel.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * 5 | * Changes: 6 | * 2023-06-09: Change name of output channel 7 | */ 8 | // Source: https://github.com/aws/aws-toolkit-vscode/blob/master/src/shared/logger/outputChannel.ts 9 | 10 | import * as vscode from 'vscode' 11 | 12 | export const logOutputChannel: vscode.OutputChannel = vscode.window.createOutputChannel('LocalStack') 13 | 14 | /** 15 | * Shows the log output channel. 16 | */ 17 | export function showLogOutputChannel({ preserveFocus = true }: { preserveFocus?: boolean } = {}): void { 18 | logOutputChannel.show(preserveFocus) 19 | } 20 | -------------------------------------------------------------------------------- /src/utils/shell.ts: -------------------------------------------------------------------------------- 1 | import * as cp from "child_process"; 2 | 3 | // Alternatives: 4 | // a) Use child_process directly: https://stackoverflow.com/a/43008075 5 | // b) Some TerminalWrapper or the Terminal API: https://stackoverflow.com/a/62774501 6 | // c) Convenience childProcess used in AWS Toolkit VS Code extension: 7 | // https://github.com/aws/aws-toolkit-vscode/blob/master/src/shared/utilities/childProcess.ts 8 | // Basic helper to execute shell commands: https://stackoverflow.com/a/64598488 9 | export async function execShell(cmd: string) { 10 | return new Promise((resolve, reject) => { 11 | cp.exec(cmd, (err, out) => { 12 | if (err) { 13 | return reject(err); 14 | } 15 | return resolve(out); 16 | }); 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /src/utils/templateFinder.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | // import { CloudFormation } from '../cloudformation/cloudformation'; 3 | import { glob } from 'glob'; 4 | 5 | export async function findCFNTemplates(directoryPath: string): Promise { 6 | const templateCandidates = await findYamlFiles(directoryPath); 7 | const templates: string[] = []; 8 | templateCandidates.forEach(function (candidate) { 9 | // TODO: validate Cfn and add valid ones to templates 10 | templates.push(candidate); 11 | }); 12 | return templates; 13 | } 14 | 15 | 16 | // Limitation: could take a long time in directories with many yaml files 17 | // glob: https://github.com/isaacs/node-glob 18 | function findYamlFiles(directoryPath: string): Promise { 19 | return new Promise((resolve, reject) => { 20 | const pattern = '**/*.yaml'; 21 | const options = { 22 | cwd: directoryPath, 23 | nodir: true, 24 | ignore: 'node_modules/**', 25 | }; 26 | 27 | glob(pattern, options, (err: Error | null, files: string[]) => { 28 | if (err) { 29 | reject(err); 30 | return; 31 | } 32 | 33 | resolve(files); 34 | }); 35 | }); 36 | } 37 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 ]; --------------------------------------------------------------------------------