├── .circleci └── config.yml ├── .gitattributes ├── .gitignore ├── .prettierrc.toml ├── .vscode ├── launch.json └── tasks.json ├── .vscodeignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── assets ├── tilt-transparent.png └── vscode-extension.gif ├── package-lock.json ├── package.json ├── src ├── config.ts ├── error-handlers.ts ├── extension.ts ├── tilt-link.ts ├── tilt-version.ts ├── tiltfile-error-parser.test.ts ├── tiltfile-error-parser.ts ├── tiltfile-error-watcher.ts └── tiltfile-lsp-client.ts ├── syntaxes ├── tiltfile.configuration.json ├── tiltfile.tmLanguage.json └── tiltfile.tmLanguage.license ├── tsconfig.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | orbs: 3 | slack: circleci/slack@3.4.0 4 | jobs: 5 | test: 6 | docker: 7 | - image: node:16-alpine 8 | steps: 9 | - checkout 10 | - run: npm install 11 | - run: npm run check 12 | publish: 13 | docker: 14 | - image: node:16-alpine 15 | steps: 16 | - checkout 17 | - run: npm install 18 | - run: npm install -g vsce 19 | - run: npx vsce publish 20 | workflows: 21 | build: 22 | jobs: 23 | - test 24 | test-publish: 25 | jobs: 26 | - test: 27 | filters: 28 | branches: 29 | only: never-release-on-a-branch 30 | tags: 31 | only: /v[0-9]+.[0-9]+.[0-9]+/ 32 | - publish: 33 | context: 34 | - Tilt VSCE Context 35 | - Tilt Slack Context 36 | filters: 37 | branches: 38 | only: never-release-on-a-branch 39 | tags: 40 | only: /v[0-9]+.[0-9]+.[0-9]+/ 41 | requires: 42 | - test 43 | 44 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set default behavior to automatically normalize line endings. 2 | * text=auto 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.vsix 3 | .vscode-test 4 | 5 | out/ 6 | -------------------------------------------------------------------------------- /.prettierrc.toml: -------------------------------------------------------------------------------- 1 | trailingComma = "es5" 2 | semi = false 3 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that launches the extension 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": "Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--disable-extensions", 15 | "--extensionDevelopmentPath=${workspaceFolder}" 16 | ], 17 | "outFiles": [ 18 | "${workspaceFolder}/out/**/*.js" 19 | ], 20 | "preLaunchTask": "npm: esbuild" 21 | }, 22 | { 23 | "name": "Extension Tests", 24 | "type": "extensionHost", 25 | "request": "launch", 26 | "runtimeExecutable": "${execPath}", 27 | "args": [ 28 | "--extensionDevelopmentPath=${workspaceFolder}", 29 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" 30 | ], 31 | "outFiles": ["${workspaceFolder}/out/test/**/*.js"] 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "npm", 6 | "script": "watch", 7 | "problemMatcher": "$tsc-watch", 8 | "isBackground": true, 9 | "presentation": { 10 | "reveal": "never" 11 | }, 12 | "group": { 13 | "kind": "build", 14 | "isDefault": true 15 | } 16 | }, 17 | { 18 | "type": "npm", 19 | "script": "install", 20 | "problemMatcher": [], 21 | "label": "npm: install", 22 | "detail": "install dependencies from package" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | .gitignore 4 | vsc-extension-quickstart.md 5 | node_modules/ 6 | src/ 7 | tsconfig.json 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### 0.0.2 | 4/1/2022 [VSIX](https://marketplace.visualstudio.com/_apis/public/gallery/publishers/tilt-dev/vsextensions/tiltfile/0.0.2/vspackage) | [open-vsx.org](https://open-vsx.org/extension/tilt-dev/tiltfile) 4 | 5 | * [Bundle extension](https://github.com/tilt-dev/vscode-tilt/pull/11) as per [VS Code documentation](https://code.visualstudio.com/api/working-with-extensions/bundling-extension) 6 | 7 | ### 0.0.1 | 3/24/2022 [VSIX](https://marketplace.visualstudio.com/_apis/public/gallery/publishers/tilt-dev/vsextensions/tiltfile/0.0.1/vspackage) | [open-vsx.org](https://open-vsx.org/extension/tilt-dev/tiltfile) 8 | 9 | * `Tiltfile` syntax highlighting 10 | * Signature help for built-in functions as well as functions in scope from current file 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Development 4 | 5 | 1. [Install Tilt](https://docs.tilt.dev/install.html) 6 | 2. Open this project (`vscode-tilt`) in Visual Studio Code 7 | 3. Press `F5` or `Run > Start Debugging` 8 | 9 | To reload the extension, use `Ctrl-R` (`⌘-R`). To reload the language server process only, use the command palette and run the "Restart Tiltfile LSP Server" command. 10 | 11 | ### Language server 12 | 13 | The language server functionality is built into Tilt itself via the `tilt lsp` command. If you want to work on the language server, most of it is implemented by the [tilt-dev/starlark-lsp][starlark-lsp] library. To develop the language server: 14 | 15 | 1. Configure the Tiltfile VS Code extension to communicate with a development LSP server by setting the port in the Tiltfile extension settings (`tiltfile.server.port`) to `8760` 16 | 2. Ensure you have Go 1.17 or higher installed 17 | 3. Clone [tilt-dev/starlark-lsp][starlark-lsp] and run `tilt up` in the repository directory 18 | 19 | [starlark-lsp]: https://github.com/tilt-dev/starlark-lsp 20 | 21 | The [`Tiltfile` in the starlark-lsp repository](/tilt-dev/starlark-lsp/blob/main/Tiltfile) is set up to run the language server and automatically recompile on changes. The VS Code extension has extra handling to detect when the language server stops or disconnects and automatically reconnects to it. If it fails to reconnect (for example, due to a compile error), use the "Restart Tiltfile LSP Server" command (mentioned above) to reconnect to your development language server. 22 | 23 | ## Publishing the extension to the VSCode Marketplace 24 | 25 | The extension is published via CircleCI. 26 | 27 | To create a new release $VERSION (e.g., v0.0.3): 28 | 1. Edit package.json and bump the "version" field to $VERSION. Commit that change to master. 29 | 2. `git tag -a $VERSION -m $VERSION && git push origin $VERSION` 30 | 3. A CircleCI job will detect the tag and build and publish the new version of the extension. You can observe that here: https://app.circleci.com/pipelines/github/tilt-dev/vscode-tilt 31 | 32 | ### Updating the token used for CI publishing 33 | 34 | CI authenticates via a VSCode Personal Access Token (PAT). These have a max lifetime of 1 year. When authentication fails due to expiry (nb: the auth error probably won't specify it's due to expiry), to update the token: 35 | 36 | 1. Make sure you're a member of the Tilt Dev org. Go 37 | [here](https://dev.azure.com/tilt-dev/_usersSettings/tokens). If you get an 38 | error, your account needs to be added by email address. 39 | 40 | 2. Make sure you're a member of the Tilt Dev publisher. Go 41 | [here](https://marketplace.visualstudio.com/manage/publishers/tilt-dev). If 42 | you get an error, your account needs to be added by account id. 43 | Go to https://marketplace.visualstudio.com/vs and 44 | mouse over your name/email in the upper right to get your account id. 45 | 46 | 3. Generate a new token 47 | [here](https://dev.azure.com/tilt-dev/_usersSettings/tokens) using [these 48 | instructions](https://code.visualstudio.com/api/working-with-extensions/publishing-extension#get-a-personal-access-token). 49 | 50 | 4. Update the value of the `VSCE_PAT` environment variable in 51 | [circleci](https://app.circleci.com/settings/organization/github/tilt-dev/contexts/e2b4fe60-602e-4bcb-8be9-b7865ee6af95) 52 | -------------------------------------------------------------------------------- /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 [yyyy] [name of copyright owner] 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Official Tiltfile VSCode Extension 2 | 3 | The `Tiltfile` extension provides an improved editing experience for `Tiltfile` authors. 4 | 5 | ![](assets/vscode-extension.gif) 6 | 7 | This extension is currently in alpha state and might feel a bit buggy here and there. If you've encountered any issues, please check the [known issues](https://github.com/tilt-dev/vscode-tilt/issues) first and give the appropriate one a 👍‍. If your issue has not previously been reported, please [add a new one](https://github.com/tilt-dev/vscode-tilt). 8 | 9 | ## Features 10 | 11 | - Starlark syntax highlighting 12 | - Autocomplete for `Tiltfile` functions 13 | - Signature support for `Tiltfile` functions 14 | - Hover support for docstrings 15 | - When Tilt is running, highlight Tiltfile execution errors in VSCode 16 | - VSCode status bar button to open the Tilt UI in a browser 17 | 18 | ## Requirements 19 | 20 | - Tilt version >[v0.26.0](https://github.com/tilt-dev/tilt/releases/tag/v0.26.0) 21 | 22 | ## Dev Mode 23 | 24 | - To run the VSCode extension locally, check out our [CONTRIBUTING][contributing] guide 25 | 26 | ## Extension Settings 27 | 28 | This extension contributes the following settings: 29 | 30 | ### Tiltfile 31 | 32 | - `tiltfile.trace.server`: Control the logging level for language server requests/responses (valid values: `off` (default), `verbose`, `debug`). 33 | - `tiltfile.server.port`: Set the number of the port where an existing Tilt language server is running. For use while [developing the Tiltfile extension][contributing]. 34 | - `tiltfile.tilt.path`: Set the path of the Tilt executable to use as the language server. Defaults to using the `tilt` binary that is found in the environment. 35 | - `tiltfile.showStatusBarButton`: Show a button in the VSCode status bar to open the Tilt WebUI. (default true) 36 | - `tiltfile.tilt.webui.port`: When opening the Tilt WebUI, the port to use (default 10350) 37 | 38 | [contributing]: https://github.com/tilt-dev/vscode-tilt/blob/main/CONTRIBUTING.md 39 | -------------------------------------------------------------------------------- /assets/tilt-transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tilt-dev/vscode-tilt/a22dc9e72fed2061a41606cc11070caae21cd40f/assets/tilt-transparent.png -------------------------------------------------------------------------------- /assets/vscode-extension.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tilt-dev/vscode-tilt/a22dc9e72fed2061a41606cc11070caae21cd40f/assets/vscode-extension.gif -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tiltfile", 3 | "displayName": "Tiltfile", 4 | "description": "Provides an improved editing experience for `Tiltfile` authors.", 5 | "publisher": "tilt-dev", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/tilt-dev/vscode-tilt" 9 | }, 10 | "icon": "assets/tilt-transparent.png", 11 | "preview": true, 12 | "version": "0.0.4", 13 | "engines": { 14 | "vscode": "^1.63.0" 15 | }, 16 | "categories": [ 17 | "Programming Languages" 18 | ], 19 | "keywords": [ 20 | "Tiltfile", 21 | "Tilt", 22 | "tilt", 23 | "Kubernetes", 24 | "kubernetes", 25 | "k8s", 26 | "development", 27 | "dev env", 28 | "docker" 29 | ], 30 | "contributes": { 31 | "languages": [ 32 | { 33 | "id": "tiltfile", 34 | "aliases": [ 35 | "Tiltfile", 36 | "tiltfile" 37 | ], 38 | "extensions": [ 39 | "Tiltfile", 40 | ".tiltfile", 41 | ".tilt" 42 | ], 43 | "configuration": "./syntaxes/tiltfile.configuration.json" 44 | } 45 | ], 46 | "grammars": [ 47 | { 48 | "language": "tiltfile", 49 | "scopeName": "source.tiltfile", 50 | "path": "./syntaxes/tiltfile.tmLanguage.json" 51 | } 52 | ], 53 | "configuration": [ 54 | { 55 | "type": "object", 56 | "title": "Tiltfile", 57 | "properties": { 58 | "tiltfile.trace.server": { 59 | "type": [ 60 | "string", 61 | "null" 62 | ], 63 | "default": "off", 64 | "description": "Log requests and responses to Tiltfile LSP", 65 | "enum": [ 66 | "off", 67 | "verbose", 68 | "debug" 69 | ], 70 | "pattern": "off|verbose|debug", 71 | "patternErrorMessage": "Invalid log level" 72 | }, 73 | "tiltfile.server.port": { 74 | "type": [ 75 | "number", 76 | "null" 77 | ], 78 | "default": null, 79 | "description": "Port (on localhost) of running language server", 80 | "scope": "machine-overridable" 81 | }, 82 | "tiltfile.tilt.path": { 83 | "type": [ 84 | "string", 85 | "null" 86 | ], 87 | "default": null, 88 | "description": "File path of Tilt program to run the language server", 89 | "scope": "machine-overridable" 90 | }, 91 | "tiltfile.showStatusBarButton": { 92 | "type": "boolean", 93 | "default": true, 94 | "description": "Whether to show a button for this extension in the VSCode StatusBar", 95 | "scope": "machine-overridable" 96 | }, 97 | "tiltfile.tilt.webui.port": { 98 | "type": "number", 99 | "default": 10350, 100 | "description": "Port to open the Tilt Web UI on", 101 | "scope": "machine-overridable" 102 | } 103 | } 104 | } 105 | ], 106 | "commands": [ 107 | { 108 | "command": "tiltfile.restartServer", 109 | "title": "Restart Tiltfile LSP Server" 110 | } 111 | ] 112 | }, 113 | "main": "./out/extension.js", 114 | "activationEvents": [ 115 | "onLanguage:tiltfile" 116 | ], 117 | "scripts": { 118 | "vscode:prepublish": "npm run clean && npm run esbuild-base -- --minify", 119 | "esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node", 120 | "esbuild": "npm run esbuild-base -- --sourcemap", 121 | "esbuild-watch": "npm run esbuild-base -- --sourcemap --watch", 122 | "compile": "npm run esbuild", 123 | "watch": "npm run esbuild-watch", 124 | "clean": "rm -rf out", 125 | "prettier": "prettier --write \"src/**/*.ts\"", 126 | "check": "prettier --check \"src/**/*.ts*\" && tsc -p .", 127 | "test": "jest" 128 | }, 129 | "dependencies": { 130 | "@types/glob": "^7.2.0", 131 | "@types/jest": "^27.4.1", 132 | "@types/split2": "^3.2.1", 133 | "glob": "^7.2.0", 134 | "jest": "^27.5.1", 135 | "split2": "^4.1.0", 136 | "ts-jest": "^27.1.4", 137 | "vscode-languageclient": "^7.0.0" 138 | }, 139 | "devDependencies": { 140 | "@types/node": "^17.0.13", 141 | "@types/vscode": "^1.63.0", 142 | "@vscode/test-electron": "^1.6.2", 143 | "esbuild": "^0.25.0", 144 | "prettier": "2.6.2", 145 | "typescript": "^4.4.3" 146 | }, 147 | "jest": { 148 | "preset": "ts-jest" 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/config.ts: -------------------------------------------------------------------------------- 1 | import { Uri, window, workspace } from "vscode" 2 | 3 | export const TILT = "tilt" 4 | const SECTION = "tiltfile" 5 | 6 | export function getConfig(uri?: Uri) { 7 | if (!uri) { 8 | if (window.activeTextEditor) { 9 | uri = window.activeTextEditor.document.uri 10 | } else { 11 | uri = null 12 | } 13 | } 14 | return workspace.getConfiguration(SECTION, uri) 15 | } 16 | 17 | export type Port = number | null 18 | export function getServerPort(): Port { 19 | return getConfig().get("server.port") 20 | } 21 | 22 | export function getTrace(): string { 23 | return getConfig().get("trace.server") 24 | } 25 | 26 | export function getTiltPath(): string { 27 | const path = getConfig().get("tilt.path") 28 | if (path === null) return TILT 29 | return path 30 | } 31 | 32 | export function getShowStatusBarButton(): boolean { 33 | return getConfig().get("showStatusBarButton") 34 | } 35 | 36 | export function getTiltWebUIPort(): number { 37 | return getConfig().get("tilt.webui.port") 38 | } 39 | -------------------------------------------------------------------------------- /src/error-handlers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CloseAction, 3 | ErrorAction, 4 | ErrorHandler, 5 | Message, 6 | } from "vscode-languageclient" 7 | import { TiltfileLspClient } from "./tiltfile-lsp-client" 8 | 9 | export class PlaceholderErrorHandler implements ErrorHandler { 10 | public delegate: ErrorHandler 11 | 12 | error(error: Error, message: Message, count: number): ErrorAction { 13 | return this.delegate.error(error, message, count) 14 | } 15 | 16 | closed(): CloseAction { 17 | return this.delegate.closed() 18 | } 19 | } 20 | 21 | export class TiltfileErrorHandler extends PlaceholderErrorHandler { 22 | constructor(private client: TiltfileLspClient, maxRestartCount: number) { 23 | super() 24 | this.delegate = this.client.createDefaultErrorHandler(maxRestartCount) 25 | } 26 | 27 | closed(): CloseAction { 28 | // default error handler backs off after several restarts; 29 | // always restart when using the debug server 30 | if (this.client.usingDebugServer) { 31 | return CloseAction.Restart 32 | } 33 | return this.delegate.closed() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import { ExtensionContext, window } from "vscode" 2 | import { addTiltLinkToStatusBar } from "./tilt-link" 3 | import { TiltfileErrorWatcher } from "./tiltfile-error-watcher" 4 | import { TiltfileLspClient } from "./tiltfile-lsp-client" 5 | 6 | const extensionName = "tiltfile" 7 | 8 | let client: TiltfileLspClient 9 | let tiltfileErrorWatcher: TiltfileErrorWatcher 10 | 11 | export function activate(context: ExtensionContext) { 12 | const ch = window.createOutputChannel(extensionName) 13 | client = new TiltfileLspClient(context, ch) 14 | client.start() 15 | tiltfileErrorWatcher = new TiltfileErrorWatcher(context, ch) 16 | tiltfileErrorWatcher.start() 17 | addTiltLinkToStatusBar(context) 18 | } 19 | 20 | export function deactivate(): Thenable | undefined { 21 | if (!client) { 22 | return undefined 23 | } 24 | return client.stop() 25 | } 26 | -------------------------------------------------------------------------------- /src/tilt-link.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from "vscode" 2 | import { getShowStatusBarButton, getTiltWebUIPort } from "./config" 3 | 4 | let statusBarItem: vscode.StatusBarItem 5 | 6 | export function addTiltLinkToStatusBar({ 7 | subscriptions, 8 | }: vscode.ExtensionContext) { 9 | const commandId = "tilt.openWebUI" 10 | subscriptions.push( 11 | vscode.commands.registerCommand(commandId, () => { 12 | console.log(`port: ${getTiltWebUIPort()}`) 13 | vscode.env.openExternal( 14 | vscode.Uri.parse(`http://localhost:${getTiltWebUIPort()}`) 15 | ) 16 | }) 17 | ) 18 | 19 | statusBarItem = vscode.window.createStatusBarItem( 20 | vscode.StatusBarAlignment.Right, 21 | 100 22 | ) 23 | statusBarItem.text = "$(globe) Tilt" 24 | statusBarItem.tooltip = "Open the Tilt WebUI" 25 | statusBarItem.command = commandId 26 | subscriptions.push(statusBarItem) 27 | subscriptions.push( 28 | vscode.workspace.onDidChangeConfiguration(() => { 29 | console.log("workspace configuration changed") 30 | updateStatusBarItem() 31 | }) 32 | ) 33 | updateStatusBarItem() 34 | } 35 | 36 | function updateStatusBarItem() { 37 | const b = getShowStatusBarButton() 38 | if (getShowStatusBarButton()) { 39 | statusBarItem.show() 40 | } else { 41 | statusBarItem.hide() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/tilt-version.ts: -------------------------------------------------------------------------------- 1 | import { spawn } from "child_process" 2 | import { getTiltPath } from "./config" 3 | 4 | type SemVersion = { 5 | major: number 6 | minor: number 7 | patch: number 8 | extra: string 9 | } 10 | 11 | function versionString(ver: SemVersion): string { 12 | return `${ver.major}.${ver.minor}.${ver.patch}${ver.extra}` 13 | } 14 | 15 | interface OutputChannelLog { 16 | info(message: string, data?: any, showNotification?: boolean): void 17 | warn(message: string, data?: any, showNotification?: boolean): void 18 | error(message: string, data?: any, showNotification?: boolean): void 19 | } 20 | 21 | const versionRegexp = /^v(\d+)\.(\d+)\.(\d+)([^ ,]*)/ 22 | 23 | export async function checkTiltVersion(log: OutputChannelLog): Promise { 24 | const tiltPath = getTiltPath() 25 | let error: Error 26 | try { 27 | const version = await tiltVersion(tiltPath, log) 28 | if (compatibleVersion(version)) { 29 | log.info(`Found Tilt version ${versionString(version)}`) 30 | return tiltPath 31 | } 32 | error = new Error( 33 | `Tilt version ${versionString( 34 | version 35 | )} is not compatible with the Tiltfile extension` 36 | ) 37 | } catch (e) { 38 | error = e 39 | } 40 | 41 | throw error 42 | } 43 | 44 | async function tiltVersion( 45 | path: string, 46 | log: OutputChannelLog 47 | ): Promise { 48 | return new Promise((res, rej) => { 49 | const proc = spawn(path, ["version"]) 50 | let hadError = false 51 | let output = "" 52 | proc.stdout.on("data", (data) => { 53 | output = output + data 54 | }) 55 | proc.on("error", (err) => { 56 | log.error(path + ": " + err.toString()) 57 | hadError = true 58 | rej(new Error("Tilt not found")) 59 | }) 60 | proc.on("close", (code) => { 61 | if (hadError) { 62 | return 63 | } 64 | const err = new Error("Tilt produced unexpected output") 65 | if (code !== 0) { 66 | log.error(`${path}: exited with non-zero status: ${code}`) 67 | rej(err) 68 | return 69 | } 70 | const version = output.match(versionRegexp) 71 | if (version === null) { 72 | log.error(`${path}: gave unexpected version output`) 73 | rej(err) 74 | return 75 | } 76 | res({ 77 | major: parseInt(version[1]), 78 | minor: parseInt(version[2]), 79 | patch: parseInt(version[3]), 80 | extra: version[4], 81 | }) 82 | }) 83 | }) 84 | } 85 | 86 | function compatibleVersion(version: SemVersion): boolean { 87 | return version.major > 0 || (version.major === 0 && version.minor >= 26) 88 | } 89 | -------------------------------------------------------------------------------- /src/tiltfile-error-parser.test.ts: -------------------------------------------------------------------------------- 1 | import { parseTiltfileError, Location } from "./tiltfile-error-parser" 2 | 3 | describe("tiltfileErrors", () => { 4 | const cases: [string, string, Location[]][] = [ 5 | // simple starlark parser error 6 | [ 7 | "/private/tmp/scope/Tiltfile:7:19: undefined: dc", 8 | "undefined: dc", 9 | [ 10 | { 11 | path: "/private/tmp/scope/Tiltfile", 12 | line: 7, 13 | col: 19, 14 | }, 15 | ], 16 | ], 17 | // runtime error with traceback 18 | [ 19 | `Traceback (most recent call last): 20 | /private/tmp/scope/Tiltfile:1:12: in 21 | : in dc_resource 22 | Error: no Docker Compose service found with name 'foo'. Found these instead:`, 23 | ` : in dc_resource 24 | Error: no Docker Compose service found with name 'foo'. Found these instead:`, 25 | [ 26 | { 27 | path: "/private/tmp/scope/Tiltfile", 28 | line: 1, 29 | col: 12, 30 | }, 31 | ], 32 | ], 33 | // static error with multi-file traceback 34 | [ 35 | `Traceback (most recent call last): 36 | /private/tmp/stringlit/Tiltfile:1:1: in 37 | Error: cannot load Tiltfile.inc: /private/tmp/stringlit/Tiltfile.inc:4:7: undefined: a`, 38 | `Error: cannot load Tiltfile.inc: /private/tmp/stringlit/Tiltfile.inc:4:7: undefined: a`, 39 | [ 40 | { 41 | path: "/private/tmp/stringlit/Tiltfile", 42 | line: 1, 43 | col: 1, 44 | }, 45 | { 46 | path: "/private/tmp/stringlit/Tiltfile.inc", 47 | line: 4, 48 | col: 7, 49 | }, 50 | ], 51 | ], 52 | // runtime error with multi-file traceback 53 | [ 54 | `Traceback (most recent call last): 55 | /private/tmp/stringlit/Tiltfile:2:2: in \u003ctoplevel\u003e 56 | /private/tmp/stringlit/Tiltfile.inc:4:7: in f 57 | Error: local variable a referenced before assignment`, 58 | `Error: local variable a referenced before assignment`, 59 | [ 60 | { 61 | path: "/private/tmp/stringlit/Tiltfile", 62 | line: 2, 63 | col: 2, 64 | }, 65 | { 66 | path: "/private/tmp/stringlit/Tiltfile.inc", 67 | line: 4, 68 | col: 7, 69 | }, 70 | ], 71 | ], 72 | // space in filename 73 | [ 74 | "/private/tmp/sco pe/Tiltfile:7:19: undefined: dc", 75 | "undefined: dc", 76 | [ 77 | { 78 | path: "/private/tmp/sco pe/Tiltfile", 79 | line: 7, 80 | col: 19, 81 | }, 82 | ], 83 | ], 84 | ] 85 | test.each(cases)( 86 | "parse %s", 87 | (tiltfileError, expectedMessage, expectedLocations) => { 88 | const { message, locations } = parseTiltfileError(tiltfileError) 89 | expect(message).toEqual(expectedMessage) 90 | expect(locations).toEqual(expectedLocations) 91 | } 92 | ) 93 | }) 94 | -------------------------------------------------------------------------------- /src/tiltfile-error-parser.ts: -------------------------------------------------------------------------------- 1 | const locationPattern = `(?[A-Za-z0-9\/ \\\._-]+):(?[1-9][0-9]*):(?[1-9][0-9]*)` 2 | const tracebackLocationRe = new RegExp(`^\\s*${locationPattern}`) 3 | const simpleErrorRe = new RegExp(`^${locationPattern}: (?.+)`) 4 | const loadErrorRe = new RegExp( 5 | `Error: cannot load \\S+: ${locationPattern}: .+` 6 | ) 7 | 8 | export type Location = { 9 | path: string 10 | line: number 11 | col: number 12 | } 13 | 14 | // m must be a match from `pathLineColPattern` 15 | function matchToLocation(m: RegExpMatchArray): Location { 16 | return { 17 | path: m.groups.file, 18 | line: parseInt(m.groups.line), 19 | col: parseInt(m.groups.col), 20 | } 21 | } 22 | 23 | export function parseTiltfileError(error: string): 24 | | { 25 | message: string 26 | locations: Location[] 27 | } 28 | | undefined { 29 | if (!error) { 30 | return undefined 31 | } 32 | if (error.startsWith("Traceback")) { 33 | const lines = error.split("\n") 34 | let locations = new Array() 35 | for (let i = 1; i < lines.length; i++) { 36 | const line = lines[i] 37 | let match = line.match(tracebackLocationRe) 38 | if (match) { 39 | locations.push(matchToLocation(match)) 40 | } else { 41 | match = line.match(loadErrorRe) 42 | if (match) { 43 | locations.push(matchToLocation(match)) 44 | } 45 | const message = lines.splice(i, lines.length - i).join("\n") 46 | return { 47 | message: message, 48 | locations: locations, 49 | } 50 | } 51 | } 52 | } 53 | 54 | const match = error.match(simpleErrorRe) 55 | if (match) { 56 | return { 57 | message: match.groups.message, 58 | locations: [matchToLocation(match)], 59 | } 60 | } 61 | return { message: "", locations: [] } 62 | } 63 | -------------------------------------------------------------------------------- /src/tiltfile-error-watcher.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from "vscode" 2 | import { spawn, ChildProcessWithoutNullStreams } from "child_process" 3 | import { Disposable, ExtensionContext } from "vscode" 4 | import split2 from "split2" 5 | import { parseTiltfileError, Location } from "./tiltfile-error-parser" 6 | 7 | // path to print tiltfile errors from the Tilt API Session object, one error per line 8 | const tiltfileErrorJsonPath = 9 | "{.status.targets[?(@.name=='tiltfile:update')].state.terminated}{'\\n'}" 10 | 11 | const reconnectIntervalMS = 5000 12 | 13 | // watches the Tilt session for errors in the (Tiltfile) resource and reports them to vscode as error diagnostics 14 | export class TiltfileErrorWatcher implements Disposable { 15 | private diagnostics: vscode.DiagnosticCollection 16 | private tiltWatch: ChildProcessWithoutNullStreams 17 | private reconnectTimeout: NodeJS.Timeout | undefined 18 | private output: vscode.OutputChannel 19 | private lastError: string | undefined 20 | 21 | public constructor( 22 | private context: ExtensionContext, 23 | ch: vscode.OutputChannel 24 | ) { 25 | this.output = ch 26 | this.diagnostics = vscode.languages.createDiagnosticCollection("tiltfile") 27 | context.subscriptions.push(this.diagnostics) 28 | } 29 | 30 | start() { 31 | const p = spawn("tilt", [ 32 | "get", 33 | `-ojsonpath=${tiltfileErrorJsonPath}`, 34 | "--watch", 35 | "session", 36 | "Tiltfile", 37 | ]) 38 | p.stderr.setEncoding("utf8") 39 | let stderr = "" 40 | p.stderr.on("data", (data) => { 41 | stderr += `${data}\n` 42 | }) 43 | p.stdout.setEncoding("utf8") 44 | 45 | p.stdout.pipe(split2()).on("data", (data) => { 46 | if (data.length > 0) { 47 | let terminated = { error: "" } 48 | try { 49 | terminated = JSON.parse(data) 50 | } catch (error) { 51 | this.output.appendLine(`tilt session watch: output: ${data}`) 52 | this.output.appendLine(`tilt session watch: parsing: ${error}`) 53 | return 54 | } 55 | 56 | try { 57 | const result = parseTiltfileError(terminated.error) 58 | this.diagnostics.clear() 59 | if (result) { 60 | const { message, locations } = result 61 | locations.forEach((location) => { 62 | const uri = vscode.Uri.file(location.path) 63 | this.diagnostics.set(uri, [ 64 | tiltfileErrorToDiagnostic(message, location), 65 | ]) 66 | }) 67 | } 68 | } catch (error) { 69 | this.output.appendLine( 70 | `tilt session watch: processing session: ${error}` 71 | ) 72 | } 73 | } 74 | }) 75 | p.on("close", (code) => { 76 | const error = `tilt session watch exited w/ code ${code}` 77 | if (error !== this.lastError) { 78 | if (stderr !== "") { 79 | this.output.append(stderr) 80 | if (stderr.includes("No tilt apiserver found")) { 81 | this.output.appendLine( 82 | `No running Tilt found. Tiltfile runtime error highlighting will work when Tilt is started.` 83 | ) 84 | } 85 | } 86 | this.output.appendLine(error) 87 | this.lastError = error 88 | } 89 | this.tiltWatch = null 90 | this.ensureReconnecting() 91 | }) 92 | p.on("error", (error) => { 93 | if (error.message !== this.lastError) { 94 | if (stderr !== "") { 95 | this.output.append(stderr) 96 | } 97 | this.output.appendLine(`tilt session watch errored: ${error}`) 98 | this.lastError = error.message 99 | } 100 | this.tiltWatch = null 101 | this.ensureReconnecting() 102 | }) 103 | this.tiltWatch = p 104 | } 105 | 106 | private ensureReconnecting() { 107 | if (!this.reconnectTimeout) { 108 | this.reconnectTimeout = setTimeout(() => { 109 | this.reconnectTimeout = null 110 | this.start() 111 | }, reconnectIntervalMS) 112 | } 113 | } 114 | 115 | dispose() { 116 | if (this.tiltWatch) { 117 | this.tiltWatch.kill("SIGINT") 118 | } 119 | } 120 | } 121 | 122 | function tiltfileErrorToDiagnostic( 123 | message: string, 124 | location: Location 125 | ): vscode.Diagnostic { 126 | const line = location.line 127 | const col = location.col 128 | return { 129 | message: message, 130 | range: new vscode.Range(line - 1, col - 1, line - 1, col - 1), 131 | severity: vscode.DiagnosticSeverity.Error, 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/tiltfile-lsp-client.ts: -------------------------------------------------------------------------------- 1 | import net = require("net") 2 | import { ChildProcess, spawn } from "child_process" 3 | import { 4 | commands, 5 | Disposable, 6 | ExtensionContext, 7 | OutputChannel, 8 | window, 9 | workspace, 10 | } from "vscode" 11 | import { 12 | LanguageClient, 13 | LanguageClientOptions, 14 | StreamInfo, 15 | } from "vscode-languageclient/node" 16 | 17 | import { PlaceholderErrorHandler, TiltfileErrorHandler } from "./error-handlers" 18 | import { getServerPort, getTrace, Port } from "./config" 19 | import { checkTiltVersion } from "./tilt-version" 20 | 21 | const extensionLang = "tiltfile" 22 | const extensionName = "Tiltfile" 23 | const maxRestartCount = 5 24 | const tiltUnavailableNotification = "Tilt language server could not be started" 25 | const tiltUnavailableMessage = 26 | "Could not find a version of Tilt to use with the Tiltfile extension. " + 27 | "Please visit https://docs.tilt.dev/install.html to install Tilt v0.26 or higher. " + 28 | "Autocomplete will not function without a compatible version of Tilt installed." 29 | 30 | export class TiltfileLspClient extends LanguageClient { 31 | private _usingDebugServer = false 32 | 33 | public constructor(private context: ExtensionContext, ch: OutputChannel) { 34 | super( 35 | extensionLang, 36 | extensionName, 37 | () => this.startServer(), 38 | TiltfileLspClient.clientOptions(ch) 39 | ) 40 | this.registerCommands() 41 | this.installErrorHandler() 42 | } 43 | 44 | static clientOptions(ch: OutputChannel): LanguageClientOptions { 45 | return { 46 | documentSelector: [{ scheme: "file", language: extensionLang }], 47 | synchronize: { 48 | // Notify the server about file changes to relevant files contained in the workspace 49 | fileEvents: workspace.createFileSystemWatcher("**/Tiltfile"), 50 | }, 51 | outputChannel: ch, 52 | traceOutputChannel: ch, 53 | errorHandler: new PlaceholderErrorHandler(), 54 | } 55 | } 56 | 57 | public get usingDebugServer() { 58 | return this._usingDebugServer 59 | } 60 | 61 | public start(): Disposable { 62 | const disp = super.start() 63 | this.info("Tiltfile LSP started") 64 | return disp 65 | } 66 | 67 | public registerCommands() { 68 | this.context.subscriptions.push( 69 | commands.registerCommand("tiltfile.restartServer", () => { 70 | this.info("Restarting server") 71 | this.restart() 72 | }) 73 | ) 74 | } 75 | 76 | public restart(): void { 77 | this.stop() 78 | .catch((e) => this.warn(e)) 79 | .then(() => this.start()) 80 | } 81 | 82 | private async startServer(): Promise { 83 | const port = await this.checkForDebugLspServer() 84 | if (port) { 85 | this.info("Connect to debug server") 86 | this._usingDebugServer = true 87 | this.outputChannel.show(true) 88 | const socket = net.connect({ host: "127.0.0.1", port }) 89 | return { writer: socket, reader: socket } 90 | } 91 | 92 | try { 93 | const tiltPath = await checkTiltVersion(this) 94 | const args = ["lsp", "start"] 95 | this.info("Starting child process") 96 | const trace = getTrace() 97 | switch (trace) { 98 | case "verbose": 99 | args.push("--verbose") 100 | break 101 | case "debug": 102 | this.outputChannel.show(true) 103 | args.push("--debug") 104 | break 105 | } 106 | return spawn(tiltPath, args) 107 | } catch (e) { 108 | this.warn(tiltUnavailableMessage) 109 | this.outputChannel.show() 110 | window.showErrorMessage(tiltUnavailableNotification) 111 | throw e.toString() 112 | } 113 | } 114 | 115 | private async checkForDebugLspServer(): Promise { 116 | const port = getServerPort() 117 | if (!port) { 118 | return null 119 | } 120 | return new Promise((resolve) => { 121 | const checkListen = () => { 122 | var server = net.createServer() 123 | server.on("error", () => resolve(port)) 124 | server.on("listening", () => { 125 | server.close() 126 | resolve(null) 127 | }) 128 | server.listen(port, "127.0.0.1") 129 | } 130 | 131 | if (this.usingDebugServer) { 132 | // wait for server to restart 133 | setTimeout(checkListen, 2500) 134 | } else { 135 | checkListen() 136 | } 137 | }) 138 | } 139 | 140 | private installErrorHandler() { 141 | const placeholder = this.clientOptions 142 | .errorHandler as PlaceholderErrorHandler 143 | placeholder.delegate = new TiltfileErrorHandler(this, maxRestartCount) 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /syntaxes/tiltfile.configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "comments": { 3 | "lineComment": "#" 4 | }, 5 | "brackets": [ 6 | ["{", "}"], 7 | ["[", "]"], 8 | ["(", ")"] 9 | ], 10 | "autoClosingPairs": [ 11 | ["{", "}"], 12 | ["[", "]"], 13 | ["(", ")"], 14 | { 15 | "open": "\"", 16 | "close": "\"", 17 | "notIn": ["string", "comment"] 18 | }, 19 | { 20 | "open": "'", 21 | "close": "'", 22 | "notIn": ["string", "comment"] 23 | } 24 | ], 25 | "surroundingPairs": [ 26 | ["{", "}"], 27 | ["[", "]"], 28 | ["(", ")"], 29 | ["\"", "\""], 30 | ["'", "'"] 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /syntaxes/tiltfile.tmLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", 3 | "name": "Tiltfile", 4 | "scopeName": "source.tiltfile", 5 | "fileTypes": [ 6 | "Tiltfile", 7 | "tiltfile" 8 | ], 9 | "patterns": [ 10 | { 11 | "include": "#statement" 12 | }, 13 | { 14 | "include": "#expression" 15 | } 16 | ], 17 | "repository": { 18 | "statement": { 19 | "patterns": [ 20 | { 21 | "include": "#function-definition" 22 | }, 23 | { 24 | "include": "#statement-keyword" 25 | }, 26 | { 27 | "include": "#assignment-operator" 28 | }, 29 | { 30 | "include": "#docstring-statement" 31 | }, 32 | { 33 | "include": "#discouraged-semicolon" 34 | } 35 | ] 36 | }, 37 | "docstring-statement": { 38 | "begin": "^(?=\\s*r?('''|\"\"\"|'|\"))", 39 | "end": "(?<='''|\"\"\"|'|\")", 40 | "patterns": [ 41 | { 42 | "include": "#docstring" 43 | } 44 | ] 45 | }, 46 | "docstring": { 47 | "patterns": [ 48 | { 49 | "name": "comment.block.documentation.starlark", 50 | "begin": "('''|\"\"\")", 51 | "end": "(\\1)", 52 | "beginCaptures": { 53 | "1": { 54 | "name": "punctuation.definition.string.begin.starlark" 55 | } 56 | }, 57 | "endCaptures": { 58 | "1": { 59 | "name": "punctuation.definition.string.end.starlark" 60 | } 61 | }, 62 | "patterns": [ 63 | { 64 | "include": "#code-tag" 65 | }, 66 | { 67 | "include": "#docstring-content" 68 | } 69 | ] 70 | }, 71 | { 72 | "name": "comment.block.documentation.starlark", 73 | "begin": "(r)('''|\"\"\")", 74 | "end": "(\\2)", 75 | "beginCaptures": { 76 | "1": { 77 | "name": "storage.type.string.starlark" 78 | }, 79 | "2": { 80 | "name": "punctuation.definition.string.begin.starlark" 81 | } 82 | }, 83 | "endCaptures": { 84 | "1": { 85 | "name": "punctuation.definition.string.end.starlark" 86 | } 87 | }, 88 | "patterns": [ 89 | { 90 | "include": "#string-consume-escape" 91 | }, 92 | { 93 | "include": "#code-tag" 94 | } 95 | ] 96 | }, 97 | { 98 | "name": "comment.line.documentation.starlark", 99 | "begin": "('|\")", 100 | "end": "(\\1)|((?=|<=|<|>)(?# 4)", 395 | "captures": { 396 | "1": { 397 | "name": "keyword.operator.logical.starlark" 398 | }, 399 | "2": { 400 | "name": "keyword.control.flow.starlark" 401 | }, 402 | "3": { 403 | "name": "keyword.operator.arithmetic.starlark" 404 | }, 405 | "4": { 406 | "name": "keyword.operator.comparison.starlark" 407 | } 408 | } 409 | }, 410 | "literal": { 411 | "patterns": [ 412 | { 413 | "name": "constant.language.starlark", 414 | "match": "\\b(True|False|None)\\b" 415 | }, 416 | { 417 | "include": "#number" 418 | } 419 | ] 420 | }, 421 | "number": { 422 | "patterns": [ 423 | { 424 | "include": "#number-decimal" 425 | }, 426 | { 427 | "include": "#number-hexadecimal" 428 | }, 429 | { 430 | "include": "#number-octal" 431 | }, 432 | { 433 | "name": "invalid.illegal.name.starlark", 434 | "match": "\\b[0-9]+\\w+" 435 | } 436 | ] 437 | }, 438 | "number-decimal": { 439 | "name": "constant.numeric.decimal.starlark", 440 | "match": "(?