├── .gitignore ├── languages └── comment │ ├── config.toml │ └── highlights.scm ├── static └── HighlightingExample.png ├── extension.toml ├── .github └── workflows │ └── release.yaml ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .zed/ 2 | grammars/ 3 | 4 | test.* 5 | -------------------------------------------------------------------------------- /languages/comment/config.toml: -------------------------------------------------------------------------------- 1 | name = "comment" 2 | grammar = "comment" 3 | hidden = true 4 | -------------------------------------------------------------------------------- /static/HighlightingExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedadams/zed-comment/HEAD/static/HighlightingExample.png -------------------------------------------------------------------------------- /extension.toml: -------------------------------------------------------------------------------- 1 | id = "comment" 2 | name = "Comments Highlighter" 3 | version = "0.4.1" 4 | schema_version = 1 5 | authors = ["Donnie Adams "] 6 | description = "Comment language extension for highlighting special comments" 7 | repository = "https://github.com/thedadams/zed-comment" 8 | 9 | [grammars.comment] 10 | repository = "https://github.com/thedadams/tree-sitter-comment" 11 | rev = "93b12e7b219d74fdbbb27e6671ca2f714738b253" 12 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | tags: 4 | - "v*" 5 | 6 | jobs: 7 | homebrew: 8 | name: Release Zed Extension 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout code 12 | uses: actions/checkout@v4 13 | 14 | - name: Validate version matches tag 15 | run: | 16 | TAG_VERSION=${GITHUB_REF#refs/tags/v} 17 | TOML_VERSION=$(grep '^version = ' extension.toml | sed 's/version = "\(.*\)"/\1/') 18 | 19 | if [ "$TAG_VERSION" != "$TOML_VERSION" ]; then 20 | echo "Error: Tag version (v$TAG_VERSION) does not match extension.toml version ($TOML_VERSION)" 21 | exit 1 22 | fi 23 | 24 | echo "Version validation passed: $TAG_VERSION" 25 | 26 | - uses: huacnlee/zed-extension-action@v1 27 | with: 28 | extension-name: comment 29 | push-to: thedadams/zed-extensions 30 | env: 31 | # the personal access token should have "repo" & "workflow" scopes 32 | COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }} 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Santos Gallegos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /languages/comment/highlights.scm: -------------------------------------------------------------------------------- 1 | ((tag 2 | (name) @_name @constant.comment.todo 3 | ("(" @constant.comment.todo.bracket 4 | (user) @constant.comment.todo.user 5 | ")" @constant.comment.todo.bracket)? 6 | (text)? @constant.comment.todo.text) 7 | (#match? @_name "^[/Library/Application Support/Zed/extensions/installed/` | 71 | | Linux | `~/.local/share/zed/extensions/installed/` | 72 | | Windows | `%APPDATA%\Zed\extensions\installed\` | 73 | 74 | ### 2. Find or create the `injections.scm` file for the desired language 75 | 76 | Navigate to the language's directory and locate or create an `injections.scm` file. Add the language injection snippet below. 77 | 78 | > [!NOTE] 79 | > In a single `injections.scm` file, only one of `@content` or `@injections.content` is allowed, never both. 80 | > Check which variant the existing file uses (if any) and use the same one. 81 | 82 | #### Using `@content`: 83 | 84 | ```scheme 85 | ((comment) @content 86 | (#set! injection.language "comment")) 87 | ``` 88 | 89 | #### Using `@injections.content`: 90 | 91 | ```scheme 92 | ((comment) @injections.content 93 | (#set! injection.language "comment")) 94 | ``` 95 | 96 | > [!IMPORTANT] 97 | > Replace `comment` in `((comment)` with the proper node name for the comment syntax in your target language. This varies per language (see examples below). 98 | 99 | ### 3. Examples 100 | 101 | | Language | Relative Path | Node Name | Snippet | 102 | | ------------- | ---------------------------------------- | --------- | ----------------------------------------------------------- | 103 | | Scheme (.scm) | `scheme/languages/scheme/injections.scm` | `comment` | `((comment) @content (#set! injection.language "comment"))` | 104 | 105 | --- 106 | 107 | > [!TIP] 108 | > You can add support for the built-in languages that don't inject the "comment" language yet by [building Zed](https://github.com/zed-industries/zed/tree/main) yourself after patching every language you want in `zed/crates/languages/src`. 109 | > See the [Rust](https://github.com/zed-industries/zed/blob/main/crates/languages/src/rust/injections.scm) language support built into Zed as an example. 110 | 111 | > [!NOTE] 112 | > You may have to restart the language server or Zed to get the injections to work properly. Also, you are likely to need to redo the edits made here any time the extension is updated. Because of this, it is highly recommended to submit a PR to the extension with the edits you are making. 113 | 114 | ### Supported languages 115 | 116 | The table below lists each language’s comment injection status: ✅ supported; ⚠️ not yet supported (PR submitted). 117 | 118 | | Language | Supported | Pull request | 119 | | ------------- | ---------------------------------------- | ---------------------------------------------------- | 120 | | Bash | ✅ | https://github.com/zed-industries/zed/pull/39884 | 121 | | C | ✅ | https://github.com/zed-industries/zed/pull/39884 | 122 | | Clojure | ✅ | https://github.com/zed-extensions/clojure/pull/13 | 123 | | C# | ✅ | N/A | 124 | | C++ | ✅ | https://github.com/zed-industries/zed/pull/39884 | 125 | | CSS | ✅ | https://github.com/zed-industries/zed/pull/41710 | 126 | | Dart | ✅ | https://github.com/zed-extensions/dart/pull/35 | 127 | | Diff | ✅ | https://github.com/zed-industries/zed/pull/41710 | 128 | | Dockerfile | ✅ | https://github.com/zed-extensions/dockerfile/pull/25 | 129 | | Elixir | ✅ | https://github.com/zed-extensions/elixir/pull/38 | 130 | | Git Commit | ✅ | https://github.com/zed-industries/zed/pull/39884 | 131 | | Gleam | ⚠️ | https://github.com/gleam-lang/zed-gleam/pull/20 | 132 | | Go | ✅ | https://github.com/zed-industries/zed/pull/39884 | 133 | | Haskell | ✅ | https://github.com/zed-extensions/haskell/pull/7 | 134 | | HTML | ✅ | https://github.com/zed-industries/zed/pull/39884 | 135 | | Java | ✅ | N/A | 136 | | Javascript | ✅ | https://github.com/zed-industries/zed/pull/39884 | 137 | | JSONC | ✅ | https://github.com/zed-industries/zed/pull/41710 | 138 | | Kotlin | ✅ | https://github.com/zed-extensions/kotlin/pull/51 | 139 | | Make | ⚠️ | https://github.com/caius/zed-make/pull/27 | 140 | | PHP | ✅ | https://github.com/zed-extensions/php/pull/66 | 141 | | Python | ✅ | https://github.com/zed-industries/zed/pull/39884 | 142 | | RBS | ✅ | https://github.com/zed-industries/zed/pull/15778 | 143 | | Ruby | ✅ | https://github.com/zed-extensions/ruby/pull/203 | 144 | | Rust | ✅ | https://github.com/zed-industries/zed/pull/39714 | 145 | | Scala | ✅ | N/A | 146 | | Scheme | ✅ | https://github.com/zed-extensions/scheme/pull/5 | 147 | | Svelte | ⚠️ | https://github.com/zed-extensions/svelte/pull/52 | 148 | | Swift | ✅ | https://github.com/zed-extensions/swift/pull/43 | 149 | | Terraform/HCL | ✅ | https://github.com/zed-extensions/terraform/pull/7 | 150 | | TOML | ✅ | https://github.com/zed-extensions/toml/pull/2 | 151 | | TSX | ✅ | https://github.com/zed-industries/zed/pull/39884 | 152 | | TypeScript | ✅ | https://github.com/zed-industries/zed/pull/39884 | 153 | | YAML | ✅ | https://github.com/zed-industries/zed/pull/39884 | 154 | | Zig | ✅ | N/A | 155 | 156 | ## Theme Overrides 157 | 158 | Ideally, the colors for comments would be defined in themes by the `comment.todo`, `comment.info`, `comment.warn`, `comment.error`, and `comment.user` properties. However, these are not officially supported by Zed. Until they are, `constant`, `string`, `property`, and `keyword` are used so that coloring works out of the box. There is really no rhyme or reason to these choices. 159 | 160 | This extension uses a small hack to allow users to customize the colors used in comments without affecting the rest of the syntax highlighting. You can access your settings file via the command palette ("zed: Open Settings" - `cmd-,` on macOS, `ctrl-,` on Linux) and add a `theme_overrides` section. 161 | 162 | Below is a complete example you can add to your Zed settings and modify to fit your needs. If your settings file already contains a `theme_overrides` object, you can add these entries to the appropriate theme. 163 | 164 | ```jsonc 165 | { 166 | "theme_overrides": { 167 | "YourThemeName": { 168 | "syntax": { 169 | "constant.comment.todo": { 170 | "color": "#4078f2ff" 171 | // "background_color": "#00000000", 172 | // "font_weight": "bold", 173 | // "font_style": "italic" 174 | }, 175 | "string.comment.info": { 176 | "color": "#50a14fff" 177 | // "background_color": "#00000000", 178 | // "font_weight": "bold", 179 | // "font_style": "italic" 180 | }, 181 | "keyword.comment.warn": { 182 | "color": "#c18401ff" 183 | // "background_color": "#00000000", 184 | // "font_weight": "bold", 185 | // "font_style": "italic" 186 | }, 187 | "property.comment.error": { 188 | "color": "#ca1243ff" 189 | // "background_color": "#00000000", 190 | // "font_weight": "bold", 191 | // "font_style": "italic" 192 | } 193 | } 194 | } 195 | } 196 | } 197 | ``` 198 | 199 | **Note:** Replace `YourThemeName` with the actual name of your active theme (e.g., "One Dark", "Ayu Light", etc.). 200 | 201 | To explain how and why this works, we'll use `constant.comment.todo` as an example. 202 | 203 | This extension defines the syntax color node as `constant.comment.todo`. Zed will look for a corresponding color in your theme or override for this name. If it finds one, it will use that color. If not, then it will use the color corresponding to `constant.comment`, if available. If that is not available, it will use the color corresponding to `constant`, which nearly every theme supports. 204 | 205 | Therefore, by defining coloring for `constant.comment.todo` in your overrides, you can change the color and style of just the `TODO` and `WIP` comments. 206 | 207 | The text after the `:` can also be customized by adding a `.text` after the corresponding color node. For example, if you want to change the color or style of the text corresponding to an `ERROR:` comment: 208 | 209 | ```jsonc 210 | { 211 | "theme_overrides": { 212 | "YourThemeName": { 213 | "syntax": { 214 | "property.comment.error.text": { 215 | "color": "#ff0000" 216 | // "background_color": "#00000000", 217 | // "font_weight": "bold", 218 | // "font_style": "italic" 219 | } 220 | } 221 | } 222 | } 223 | } 224 | ``` 225 | 226 | Similarly, the parenthesis and user corresponding to an `ERROR:` comment can be styled as follows: 227 | 228 | ```jsonc 229 | { 230 | "theme_overrides": { 231 | "YourThemeName": { 232 | "syntax": { 233 | "property.comment.error.bracket": { 234 | "color": "#000000dd" 235 | // "background_color": "#00000000", 236 | // "font_weight": "bold", 237 | // "font_style": "italic" 238 | }, 239 | "property.comment.error.user": { 240 | "color": "#000000dd" 241 | // "background_color": "#00000000", 242 | // "font_weight": "bold", 243 | // "font_style": "italic" 244 | } 245 | } 246 | } 247 | } 248 | } 249 | ``` 250 | 251 | ## Credits 252 | 253 | Thanks to [tree-sitter-comment](https://github.com/stsewd/tree-sitter-comment) grammar. 254 | --------------------------------------------------------------------------------