├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── extension.toml └── src └── superhtml.rs /.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | 3 | # git files 4 | !.gitignore 5 | 6 | # rust files 7 | !Cargo.toml 8 | !Cargo.lock 9 | !extension.toml 10 | 11 | !src 12 | !src/*.rs 13 | 14 | # other files 15 | !LICENSE 16 | !README.md 17 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "anyhow" 7 | version = "1.0.89" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" 10 | 11 | [[package]] 12 | name = "bitflags" 13 | version = "2.6.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" 16 | 17 | [[package]] 18 | name = "equivalent" 19 | version = "1.0.1" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 22 | 23 | [[package]] 24 | name = "hashbrown" 25 | version = "0.14.5" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" 28 | 29 | [[package]] 30 | name = "heck" 31 | version = "0.4.1" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" 34 | dependencies = [ 35 | "unicode-segmentation", 36 | ] 37 | 38 | [[package]] 39 | name = "id-arena" 40 | version = "2.2.1" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" 43 | 44 | [[package]] 45 | name = "indexmap" 46 | version = "2.5.0" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" 49 | dependencies = [ 50 | "equivalent", 51 | "hashbrown", 52 | "serde", 53 | ] 54 | 55 | [[package]] 56 | name = "itoa" 57 | version = "1.0.11" 58 | source = "registry+https://github.com/rust-lang/crates.io-index" 59 | checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" 60 | 61 | [[package]] 62 | name = "leb128" 63 | version = "0.2.5" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" 66 | 67 | [[package]] 68 | name = "log" 69 | version = "0.4.22" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" 72 | 73 | [[package]] 74 | name = "memchr" 75 | version = "2.7.4" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 78 | 79 | [[package]] 80 | name = "proc-macro2" 81 | version = "1.0.86" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" 84 | dependencies = [ 85 | "unicode-ident", 86 | ] 87 | 88 | [[package]] 89 | name = "quote" 90 | version = "1.0.37" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" 93 | dependencies = [ 94 | "proc-macro2", 95 | ] 96 | 97 | [[package]] 98 | name = "ryu" 99 | version = "1.0.18" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" 102 | 103 | [[package]] 104 | name = "semver" 105 | version = "1.0.23" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" 108 | 109 | [[package]] 110 | name = "serde" 111 | version = "1.0.210" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" 114 | dependencies = [ 115 | "serde_derive", 116 | ] 117 | 118 | [[package]] 119 | name = "serde_derive" 120 | version = "1.0.210" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" 123 | dependencies = [ 124 | "proc-macro2", 125 | "quote", 126 | "syn", 127 | ] 128 | 129 | [[package]] 130 | name = "serde_json" 131 | version = "1.0.128" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" 134 | dependencies = [ 135 | "itoa", 136 | "memchr", 137 | "ryu", 138 | "serde", 139 | ] 140 | 141 | [[package]] 142 | name = "smallvec" 143 | version = "1.13.2" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 146 | 147 | [[package]] 148 | name = "spdx" 149 | version = "0.10.6" 150 | source = "registry+https://github.com/rust-lang/crates.io-index" 151 | checksum = "47317bbaf63785b53861e1ae2d11b80d6b624211d42cb20efcd210ee6f8a14bc" 152 | dependencies = [ 153 | "smallvec", 154 | ] 155 | 156 | [[package]] 157 | name = "syn" 158 | version = "2.0.79" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" 161 | dependencies = [ 162 | "proc-macro2", 163 | "quote", 164 | "unicode-ident", 165 | ] 166 | 167 | [[package]] 168 | name = "unicode-ident" 169 | version = "1.0.13" 170 | source = "registry+https://github.com/rust-lang/crates.io-index" 171 | checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" 172 | 173 | [[package]] 174 | name = "unicode-segmentation" 175 | version = "1.12.0" 176 | source = "registry+https://github.com/rust-lang/crates.io-index" 177 | checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" 178 | 179 | [[package]] 180 | name = "unicode-xid" 181 | version = "0.2.6" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" 184 | 185 | [[package]] 186 | name = "wasm-encoder" 187 | version = "0.201.0" 188 | source = "registry+https://github.com/rust-lang/crates.io-index" 189 | checksum = "b9c7d2731df60006819b013f64ccc2019691deccf6e11a1804bc850cd6748f1a" 190 | dependencies = [ 191 | "leb128", 192 | ] 193 | 194 | [[package]] 195 | name = "wasm-metadata" 196 | version = "0.201.0" 197 | source = "registry+https://github.com/rust-lang/crates.io-index" 198 | checksum = "0fd83062c17b9f4985d438603cde0a5e8c5c8198201a6937f778b607924c7da2" 199 | dependencies = [ 200 | "anyhow", 201 | "indexmap", 202 | "serde", 203 | "serde_derive", 204 | "serde_json", 205 | "spdx", 206 | "wasm-encoder", 207 | "wasmparser", 208 | ] 209 | 210 | [[package]] 211 | name = "wasmparser" 212 | version = "0.201.0" 213 | source = "registry+https://github.com/rust-lang/crates.io-index" 214 | checksum = "84e5df6dba6c0d7fafc63a450f1738451ed7a0b52295d83e868218fa286bf708" 215 | dependencies = [ 216 | "bitflags", 217 | "indexmap", 218 | "semver", 219 | ] 220 | 221 | [[package]] 222 | name = "wit-bindgen" 223 | version = "0.22.0" 224 | source = "registry+https://github.com/rust-lang/crates.io-index" 225 | checksum = "288f992ea30e6b5c531b52cdd5f3be81c148554b09ea416f058d16556ba92c27" 226 | dependencies = [ 227 | "bitflags", 228 | "wit-bindgen-rt", 229 | "wit-bindgen-rust-macro", 230 | ] 231 | 232 | [[package]] 233 | name = "wit-bindgen-core" 234 | version = "0.22.0" 235 | source = "registry+https://github.com/rust-lang/crates.io-index" 236 | checksum = "e85e72719ffbccf279359ad071497e47eb0675fe22106dea4ed2d8a7fcb60ba4" 237 | dependencies = [ 238 | "anyhow", 239 | "wit-parser", 240 | ] 241 | 242 | [[package]] 243 | name = "wit-bindgen-rt" 244 | version = "0.22.0" 245 | source = "registry+https://github.com/rust-lang/crates.io-index" 246 | checksum = "fcb8738270f32a2d6739973cbbb7c1b6dd8959ce515578a6e19165853272ee64" 247 | 248 | [[package]] 249 | name = "wit-bindgen-rust" 250 | version = "0.22.0" 251 | source = "registry+https://github.com/rust-lang/crates.io-index" 252 | checksum = "d8a39a15d1ae2077688213611209849cad40e9e5cccf6e61951a425850677ff3" 253 | dependencies = [ 254 | "anyhow", 255 | "heck", 256 | "indexmap", 257 | "wasm-metadata", 258 | "wit-bindgen-core", 259 | "wit-component", 260 | ] 261 | 262 | [[package]] 263 | name = "wit-bindgen-rust-macro" 264 | version = "0.22.0" 265 | source = "registry+https://github.com/rust-lang/crates.io-index" 266 | checksum = "d376d3ae5850526dfd00d937faea0d81a06fa18f7ac1e26f386d760f241a8f4b" 267 | dependencies = [ 268 | "anyhow", 269 | "proc-macro2", 270 | "quote", 271 | "syn", 272 | "wit-bindgen-core", 273 | "wit-bindgen-rust", 274 | ] 275 | 276 | [[package]] 277 | name = "wit-component" 278 | version = "0.201.0" 279 | source = "registry+https://github.com/rust-lang/crates.io-index" 280 | checksum = "421c0c848a0660a8c22e2fd217929a0191f14476b68962afd2af89fd22e39825" 281 | dependencies = [ 282 | "anyhow", 283 | "bitflags", 284 | "indexmap", 285 | "log", 286 | "serde", 287 | "serde_derive", 288 | "serde_json", 289 | "wasm-encoder", 290 | "wasm-metadata", 291 | "wasmparser", 292 | "wit-parser", 293 | ] 294 | 295 | [[package]] 296 | name = "wit-parser" 297 | version = "0.201.0" 298 | source = "registry+https://github.com/rust-lang/crates.io-index" 299 | checksum = "196d3ecfc4b759a8573bf86a9b3f8996b304b3732e4c7de81655f875f6efdca6" 300 | dependencies = [ 301 | "anyhow", 302 | "id-arena", 303 | "indexmap", 304 | "log", 305 | "semver", 306 | "serde", 307 | "serde_derive", 308 | "serde_json", 309 | "unicode-xid", 310 | "wasmparser", 311 | ] 312 | 313 | [[package]] 314 | name = "zed_extension_api" 315 | version = "0.1.0" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | checksum = "594fd10dd0f2f853eb243e2425e7c95938cef49adb81d9602921d002c5e6d9d9" 318 | dependencies = [ 319 | "serde", 320 | "serde_json", 321 | "wit-bindgen", 322 | ] 323 | 324 | [[package]] 325 | name = "zed_superhtml" 326 | version = "0.1.0" 327 | dependencies = [ 328 | "zed_extension_api", 329 | ] 330 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zed_superhtml" 3 | version = "0.1.0" 4 | edition = "2021" 5 | publish = false 6 | license = "Apache-2.0" 7 | 8 | [lib] 9 | path = "src/superhtml.rs" 10 | crate-type = ["cdylib"] 11 | 12 | [dependencies] 13 | zed_extension_api = "0.1.0" 14 | -------------------------------------------------------------------------------- /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 | # SuperHTML support for Zed 2 | 3 | This extension provides support for [SuperHTML](https://github.com/kristoff-it/superhtml) language server. 4 | 5 | ## Installation 6 | 7 | 1. Install extension 8 | 2. Add the following to your `settings.json`: 9 | 10 | ```json 11 | { 12 | "languages": { 13 | "HTML": { 14 | "language_servers": ["vscode-html-language-server", "superhtml"], 15 | "formatter": { "language_server": { "name": "superhtml" } } 16 | } 17 | } 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /extension.toml: -------------------------------------------------------------------------------- 1 | id = "superhtml" 2 | name = "Superhtml" 3 | description = "Superhtml support." 4 | version = "0.1.0" 5 | schema_version = 1 6 | authors = ["WeetHet "] 7 | repository = "https://github.com/WeetHet/superhtml-zed" 8 | 9 | [language_servers.superhtml] 10 | name = "superhtml" 11 | languages = ["HTML"] 12 | -------------------------------------------------------------------------------- /src/superhtml.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use zed_extension_api::{self as zed, Result}; 3 | 4 | struct SuperHtmlExtension { 5 | cached_binary_path: Option, 6 | } 7 | 8 | #[derive(Clone)] 9 | struct SuperHtmlBinary(String); 10 | 11 | impl SuperHtmlExtension { 12 | fn language_server_binary( 13 | &mut self, 14 | language_server_id: &zed::LanguageServerId, 15 | worktree: &zed::Worktree, 16 | ) -> Result { 17 | if let Some(path) = worktree.which("superhtml") { 18 | return Ok(SuperHtmlBinary(path)); 19 | } 20 | 21 | if let Some(path) = &self.cached_binary_path { 22 | if fs::metadata(path).map_or(false, |stat| stat.is_file()) { 23 | return Ok(SuperHtmlBinary(path.clone())); 24 | } 25 | } 26 | 27 | zed::set_language_server_installation_status( 28 | language_server_id, 29 | &zed::LanguageServerInstallationStatus::CheckingForUpdate, 30 | ); 31 | let release = zed::latest_github_release( 32 | "kristoff-it/superhtml", 33 | zed::GithubReleaseOptions { 34 | require_assets: true, 35 | pre_release: false, 36 | }, 37 | )?; 38 | 39 | let (platform, arch) = zed::current_platform(); 40 | let asset_without_ext = format!( 41 | "{arch}-{os}", 42 | arch = match arch { 43 | zed::Architecture::Aarch64 => "aarch64", 44 | zed::Architecture::X8664 => "x86_64", 45 | zed::Architecture::X86 => return Err("unsupported architecture".into()), 46 | }, 47 | os = match platform { 48 | zed::Os::Mac => "macos", 49 | zed::Os::Linux => "linux-musl", 50 | zed::Os::Windows => "windows", 51 | } 52 | ); 53 | let asset_name = format!( 54 | "{asset_without_ext}.{ext}", 55 | ext = match platform { 56 | zed::Os::Mac | zed::Os::Linux => "tar.gz", 57 | zed_extension_api::Os::Windows => "zip", 58 | } 59 | ); 60 | 61 | let asset = release 62 | .assets 63 | .iter() 64 | .find(|asset| asset.name == asset_name) 65 | .ok_or_else(|| format!("no asset found matching {:?}", asset_name))?; 66 | 67 | let version_dir = format!("superhtml-{}", release.version); 68 | fs::create_dir_all(&version_dir).map_err(|e| format!("failed to create directory: {e}"))?; 69 | 70 | let binary_path = format!( 71 | "{version_dir}/{asset_without_ext}/{binary}", 72 | binary = match platform { 73 | zed::Os::Mac | zed::Os::Linux => "superhtml", 74 | zed::Os::Windows => "superhtml.exe", 75 | } 76 | ); 77 | 78 | if !fs::metadata(&binary_path).map_or(false, |stat| stat.is_file()) { 79 | zed::set_language_server_installation_status( 80 | language_server_id, 81 | &zed::LanguageServerInstallationStatus::Downloading, 82 | ); 83 | 84 | zed::download_file( 85 | &asset.download_url, 86 | &version_dir, 87 | match platform { 88 | zed_extension_api::Os::Mac | zed_extension_api::Os::Linux => { 89 | zed::DownloadedFileType::GzipTar 90 | } 91 | zed_extension_api::Os::Windows => zed::DownloadedFileType::Zip, 92 | }, 93 | ) 94 | .map_err(|e| format!("failed to download file: {e}"))?; 95 | 96 | zed::make_file_executable(&binary_path)?; 97 | 98 | let entries = 99 | fs::read_dir(".").map_err(|e| format!("failed to list working directory {e}"))?; 100 | for entry in entries { 101 | let entry = entry.map_err(|e| format!("failed to load directory entry {e}"))?; 102 | if entry.file_name().to_str() != Some(&version_dir) { 103 | fs::remove_dir_all(entry.path()).ok(); 104 | } 105 | } 106 | } 107 | 108 | self.cached_binary_path = Some(binary_path.clone()); 109 | Ok(SuperHtmlBinary(binary_path)) 110 | } 111 | } 112 | 113 | impl zed::Extension for SuperHtmlExtension { 114 | fn new() -> Self { 115 | Self { 116 | cached_binary_path: None, 117 | } 118 | } 119 | 120 | fn language_server_command( 121 | &mut self, 122 | language_server_id: &zed::LanguageServerId, 123 | worktree: &zed::Worktree, 124 | ) -> Result { 125 | let SuperHtmlBinary(path) = self.language_server_binary(language_server_id, worktree)?; 126 | Ok(zed::Command { 127 | command: path, 128 | args: vec!["lsp".to_string()], 129 | env: worktree.shell_env(), 130 | }) 131 | } 132 | } 133 | 134 | zed::register_extension!(SuperHtmlExtension); 135 | --------------------------------------------------------------------------------