├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── extension.toml ├── languages ├── php │ ├── brackets.scm │ ├── config.toml │ ├── embedding.scm │ ├── highlights.scm │ ├── indents.scm │ ├── injections.scm │ ├── outline.scm │ ├── runnables.scm │ ├── tags.scm │ ├── tasks.json │ └── textobjects.scm └── phpdoc │ ├── config.toml │ └── highlights.scm └── src ├── language_servers.rs ├── language_servers ├── intelephense.rs └── phpactor.rs └── php.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | grammars/ 3 | *.wasm 4 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "anyhow" 7 | version = "1.0.95" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" 10 | 11 | [[package]] 12 | name = "bitflags" 13 | version = "2.8.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" 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.15.2" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" 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.7.1" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" 49 | dependencies = [ 50 | "equivalent", 51 | "hashbrown", 52 | "serde", 53 | ] 54 | 55 | [[package]] 56 | name = "itoa" 57 | version = "1.0.14" 58 | source = "registry+https://github.com/rust-lang/crates.io-index" 59 | checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" 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.25" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" 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.93" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" 84 | dependencies = [ 85 | "unicode-ident", 86 | ] 87 | 88 | [[package]] 89 | name = "quote" 90 | version = "1.0.38" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" 93 | dependencies = [ 94 | "proc-macro2", 95 | ] 96 | 97 | [[package]] 98 | name = "ryu" 99 | version = "1.0.19" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" 102 | 103 | [[package]] 104 | name = "semver" 105 | version = "1.0.25" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03" 108 | 109 | [[package]] 110 | name = "serde" 111 | version = "1.0.217" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" 114 | dependencies = [ 115 | "serde_derive", 116 | ] 117 | 118 | [[package]] 119 | name = "serde_derive" 120 | version = "1.0.217" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" 123 | dependencies = [ 124 | "proc-macro2", 125 | "quote", 126 | "syn", 127 | ] 128 | 129 | [[package]] 130 | name = "serde_json" 131 | version = "1.0.138" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" 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.8" 150 | source = "registry+https://github.com/rust-lang/crates.io-index" 151 | checksum = "58b69356da67e2fc1f542c71ea7e654a361a79c938e4424392ecf4fa065d2193" 152 | dependencies = [ 153 | "smallvec", 154 | ] 155 | 156 | [[package]] 157 | name = "syn" 158 | version = "2.0.98" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" 161 | dependencies = [ 162 | "proc-macro2", 163 | "quote", 164 | "unicode-ident", 165 | ] 166 | 167 | [[package]] 168 | name = "unicode-ident" 169 | version = "1.0.16" 170 | source = "registry+https://github.com/rust-lang/crates.io-index" 171 | checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" 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_php" 326 | version = "0.2.8" 327 | dependencies = [ 328 | "zed_extension_api", 329 | ] 330 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zed_php" 3 | version = "0.2.8" 4 | edition = "2021" 5 | publish = false 6 | license = "Apache-2.0" 7 | 8 | [lib] 9 | path = "src/php.rs" 10 | crate-type = ["cdylib"] 11 | 12 | [dependencies] 13 | zed_extension_api = "0.1.0" 14 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Copyright 2022 - 2025 Zed Industries, Inc. 2 | 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | 18 | 19 | 20 | 21 | Apache License 22 | Version 2.0, January 2004 23 | http://www.apache.org/licenses/ 24 | 25 | 26 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 27 | 28 | 29 | 1. Definitions. 30 | 31 | 32 | "License" shall mean the terms and conditions for use, reproduction, 33 | and distribution as defined by Sections 1 through 9 of this document. 34 | 35 | 36 | "Licensor" shall mean the copyright owner or entity authorized by 37 | the copyright owner that is granting the License. 38 | 39 | 40 | "Legal Entity" shall mean the union of the acting entity and all 41 | other entities that control, are controlled by, or are under common 42 | control with that entity. For the purposes of this definition, 43 | "control" means (i) the power, direct or indirect, to cause the 44 | direction or management of such entity, whether by contract or 45 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 46 | outstanding shares, or (iii) beneficial ownership of such entity. 47 | 48 | 49 | "You" (or "Your") shall mean an individual or Legal Entity 50 | exercising permissions granted by this License. 51 | 52 | 53 | "Source" form shall mean the preferred form for making modifications, 54 | including but not limited to software source code, documentation 55 | source, and configuration files. 56 | 57 | 58 | "Object" form shall mean any form resulting from mechanical 59 | transformation or translation of a Source form, including but 60 | not limited to compiled object code, generated documentation, 61 | and conversions to other media types. 62 | 63 | 64 | "Work" shall mean the work of authorship, whether in Source or 65 | Object form, made available under the License, as indicated by a 66 | copyright notice that is included in or attached to the work 67 | (an example is provided in the Appendix below). 68 | 69 | 70 | "Derivative Works" shall mean any work, whether in Source or Object 71 | form, that is based on (or derived from) the Work and for which the 72 | editorial revisions, annotations, elaborations, or other modifications 73 | represent, as a whole, an original work of authorship. For the purposes 74 | of this License, Derivative Works shall not include works that remain 75 | separable from, or merely link (or bind by name) to the interfaces of, 76 | the Work and Derivative Works thereof. 77 | 78 | 79 | "Contribution" shall mean any work of authorship, including 80 | the original version of the Work and any modifications or additions 81 | to that Work or Derivative Works thereof, that is intentionally 82 | submitted to Licensor for inclusion in the Work by the copyright owner 83 | or by an individual or Legal Entity authorized to submit on behalf of 84 | the copyright owner. For the purposes of this definition, "submitted" 85 | means any form of electronic, verbal, or written communication sent 86 | to the Licensor or its representatives, including but not limited to 87 | communication on electronic mailing lists, source code control systems, 88 | and issue tracking systems that are managed by, or on behalf of, the 89 | Licensor for the purpose of discussing and improving the Work, but 90 | excluding communication that is conspicuously marked or otherwise 91 | designated in writing by the copyright owner as "Not a Contribution." 92 | 93 | 94 | "Contributor" shall mean Licensor and any individual or Legal Entity 95 | on behalf of whom a Contribution has been received by Licensor and 96 | subsequently incorporated within the Work. 97 | 98 | 99 | 2. Grant of Copyright License. Subject to the terms and conditions of 100 | this License, each Contributor hereby grants to You a perpetual, 101 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 102 | copyright license to reproduce, prepare Derivative Works of, 103 | publicly display, publicly perform, sublicense, and distribute the 104 | Work and such Derivative Works in Source or Object form. 105 | 106 | 107 | 3. Grant of Patent License. Subject to the terms and conditions of 108 | this License, each Contributor hereby grants to You a perpetual, 109 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 110 | (except as stated in this section) patent license to make, have made, 111 | use, offer to sell, sell, import, and otherwise transfer the Work, 112 | where such license applies only to those patent claims licensable 113 | by such Contributor that are necessarily infringed by their 114 | Contribution(s) alone or by combination of their Contribution(s) 115 | with the Work to which such Contribution(s) was submitted. If You 116 | institute patent litigation against any entity (including a 117 | cross-claim or counterclaim in a lawsuit) alleging that the Work 118 | or a Contribution incorporated within the Work constitutes direct 119 | or contributory patent infringement, then any patent licenses 120 | granted to You under this License for that Work shall terminate 121 | as of the date such litigation is filed. 122 | 123 | 124 | 4. Redistribution. You may reproduce and distribute copies of the 125 | Work or Derivative Works thereof in any medium, with or without 126 | modifications, and in Source or Object form, provided that You 127 | meet the following conditions: 128 | 129 | 130 | (a) You must give any other recipients of the Work or 131 | Derivative Works a copy of this License; and 132 | 133 | 134 | (b) You must cause any modified files to carry prominent notices 135 | stating that You changed the files; and 136 | 137 | 138 | (c) You must retain, in the Source form of any Derivative Works 139 | that You distribute, all copyright, patent, trademark, and 140 | attribution notices from the Source form of the Work, 141 | excluding those notices that do not pertain to any part of 142 | the Derivative Works; and 143 | 144 | 145 | (d) If the Work includes a "NOTICE" text file as part of its 146 | distribution, then any Derivative Works that You distribute must 147 | include a readable copy of the attribution notices contained 148 | within such NOTICE file, excluding those notices that do not 149 | pertain to any part of the Derivative Works, in at least one 150 | of the following places: within a NOTICE text file distributed 151 | as part of the Derivative Works; within the Source form or 152 | documentation, if provided along with the Derivative Works; or, 153 | within a display generated by the Derivative Works, if and 154 | wherever such third-party notices normally appear. The contents 155 | of the NOTICE file are for informational purposes only and 156 | do not modify the License. You may add Your own attribution 157 | notices within Derivative Works that You distribute, alongside 158 | or as an addendum to the NOTICE text from the Work, provided 159 | that such additional attribution notices cannot be construed 160 | as modifying the License. 161 | 162 | 163 | You may add Your own copyright statement to Your modifications and 164 | may provide additional or different license terms and conditions 165 | for use, reproduction, or distribution of Your modifications, or 166 | for any such Derivative Works as a whole, provided Your use, 167 | reproduction, and distribution of the Work otherwise complies with 168 | the conditions stated in this License. 169 | 170 | 171 | 5. Submission of Contributions. Unless You explicitly state otherwise, 172 | any Contribution intentionally submitted for inclusion in the Work 173 | by You to the Licensor shall be under the terms and conditions of 174 | this License, without any additional terms or conditions. 175 | Notwithstanding the above, nothing herein shall supersede or modify 176 | the terms of any separate license agreement you may have executed 177 | with Licensor regarding such Contributions. 178 | 179 | 180 | 6. Trademarks. This License does not grant permission to use the trade 181 | names, trademarks, service marks, or product names of the Licensor, 182 | except as required for reasonable and customary use in describing the 183 | origin of the Work and reproducing the content of the NOTICE file. 184 | 185 | 186 | 7. Disclaimer of Warranty. Unless required by applicable law or 187 | agreed to in writing, Licensor provides the Work (and each 188 | Contributor provides its Contributions) on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 190 | implied, including, without limitation, any warranties or conditions 191 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 192 | PARTICULAR PURPOSE. You are solely responsible for determining the 193 | appropriateness of using or redistributing the Work and assume any 194 | risks associated with Your exercise of permissions under this License. 195 | 196 | 197 | 8. Limitation of Liability. In no event and under no legal theory, 198 | whether in tort (including negligence), contract, or otherwise, 199 | unless required by applicable law (such as deliberate and grossly 200 | negligent acts) or agreed to in writing, shall any Contributor be 201 | liable to You for damages, including any direct, indirect, special, 202 | incidental, or consequential damages of any character arising as a 203 | result of this License or out of the use or inability to use the 204 | Work (including but not limited to damages for loss of goodwill, 205 | work stoppage, computer failure or malfunction, or any and all 206 | other commercial damages or losses), even if such Contributor 207 | has been advised of the possibility of such damages. 208 | 209 | 210 | 9. Accepting Warranty or Additional Liability. While redistributing 211 | the Work or Derivative Works thereof, You may choose to offer, 212 | and charge a fee for, acceptance of support, warranty, indemnity, 213 | or other liability obligations and/or rights consistent with this 214 | License. However, in accepting such obligations, You may act only 215 | on Your own behalf and on Your sole responsibility, not on behalf 216 | of any other Contributor, and only if You agree to indemnify, 217 | defend, and hold each Contributor harmless for any liability 218 | incurred by, or claims asserted against, such Contributor by reason 219 | of your accepting any such warranty or additional liability. 220 | 221 | 222 | END OF TERMS AND CONDITIONS 223 | -------------------------------------------------------------------------------- /extension.toml: -------------------------------------------------------------------------------- 1 | id = "php" 2 | name = "PHP" 3 | description = "PHP support." 4 | version = "0.2.8" 5 | schema_version = 1 6 | authors = ["Piotr Osiewicz "] 7 | repository = "https://github.com/zed-extensions/php" 8 | 9 | [language_servers.intelephense] 10 | name = "Intelephense" 11 | language = "PHP" 12 | language_ids = { PHP = "php" } 13 | 14 | [language_servers.phpactor] 15 | name = "Phpactor" 16 | language = "PHP" 17 | 18 | [grammars.php] 19 | repository = "https://github.com/tree-sitter/tree-sitter-php" 20 | commit = "8ab93274065cbaf529ea15c24360cfa3348ec9e4" 21 | path = "php" 22 | 23 | [grammars.phpdoc] 24 | repository = "https://github.com/claytonrcarter/tree-sitter-phpdoc" 25 | commit = "03bb10330704b0b371b044e937d5cc7cd40b4999" 26 | -------------------------------------------------------------------------------- /languages/php/brackets.scm: -------------------------------------------------------------------------------- 1 | ("{" @open "}" @close) 2 | ("(" @open ")" @close) 3 | ("[" @open "]" @close) 4 | ("\"" @open "\"" @close) 5 | -------------------------------------------------------------------------------- /languages/php/config.toml: -------------------------------------------------------------------------------- 1 | name = "PHP" 2 | grammar = "php" 3 | path_suffixes = ["php"] 4 | first_line_pattern = '^#!.*php' 5 | line_comments = ["// ", "# "] 6 | documentation = { start = "/**", end = "*/", prefix = "* ", tab_size = 1 } 7 | autoclose_before = ";:.,=}])>" 8 | brackets = [ 9 | { start = "{", end = "}", close = true, newline = true }, 10 | { start = "[", end = "]", close = true, newline = true }, 11 | { start = "(", end = ")", close = true, newline = true }, 12 | { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] }, 13 | { start = "'", end = "'", close = true, newline = false, not_in = ["string"] }, 14 | { start = "/*", end = " */", close = true, newline = false, not_in = ["comment", "string"] }, 15 | ] 16 | collapsed_placeholder = "/* ... */" 17 | scope_opt_in_language_servers = ["tailwindcss-language-server"] 18 | prettier_parser_name = "php" 19 | prettier_plugins = ["@prettier/plugin-php"] 20 | -------------------------------------------------------------------------------- /languages/php/embedding.scm: -------------------------------------------------------------------------------- 1 | ( 2 | (comment)* @context 3 | . 4 | [ 5 | (function_definition 6 | "function" @name 7 | name: (_) @name 8 | body: (_ 9 | "{" @keep 10 | "}" @keep) @collapse 11 | ) 12 | 13 | (trait_declaration 14 | "trait" @name 15 | name: (_) @name) 16 | 17 | (method_declaration 18 | "function" @name 19 | name: (_) @name 20 | body: (_ 21 | "{" @keep 22 | "}" @keep) @collapse 23 | ) 24 | 25 | (interface_declaration 26 | "interface" @name 27 | name: (_) @name 28 | ) 29 | 30 | (enum_declaration 31 | "enum" @name 32 | name: (_) @name 33 | ) 34 | 35 | ] @item 36 | ) 37 | -------------------------------------------------------------------------------- /languages/php/highlights.scm: -------------------------------------------------------------------------------- 1 | (php_tag) @tag 2 | "?>" @tag 3 | 4 | ; Types 5 | 6 | (primitive_type) @type.builtin 7 | (cast_type) @type.builtin 8 | (named_type (name) @type) @type 9 | (named_type (qualified_name) @type) @type 10 | 11 | ; Functions 12 | 13 | (array_creation_expression "array" @function.builtin) 14 | (list_literal "list" @function.builtin) 15 | 16 | (method_declaration 17 | name: (name) @function.method) 18 | 19 | (function_call_expression 20 | function: [(qualified_name (name)) (name)] @function) 21 | 22 | (scoped_call_expression 23 | name: (name) @function) 24 | 25 | (member_call_expression 26 | name: (name) @function.method) 27 | 28 | (function_definition 29 | name: (name) @function) 30 | 31 | ; Member 32 | 33 | (property_element 34 | (variable_name) @property) 35 | 36 | (member_access_expression 37 | name: (variable_name (name)) @property) 38 | (member_access_expression 39 | name: (name) @property) 40 | (nullsafe_member_access_expression 41 | name: (variable_name (name)) @property) 42 | (nullsafe_member_access_expression 43 | name: (name) @property) 44 | 45 | ; Variables 46 | 47 | (relative_scope) @variable.builtin 48 | 49 | ((name) @constant 50 | (#match? @constant "^_?[A-Z][A-Z\\d_]+$")) 51 | ((name) @constant.builtin 52 | (#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) 53 | 54 | ((name) @constructor 55 | (#match? @constructor "^[A-Z]")) 56 | 57 | ((name) @variable.builtin 58 | (#eq? @variable.builtin "this")) 59 | 60 | (variable_name) @variable 61 | 62 | ; Basic tokens 63 | [ 64 | (string) 65 | (string_value) 66 | (encapsed_string) 67 | (heredoc) 68 | (heredoc_body) 69 | (nowdoc_body) 70 | ] @string 71 | (boolean) @constant.builtin 72 | (null) @constant.builtin 73 | (integer) @number 74 | (float) @number 75 | (comment) @comment 76 | 77 | "$" @operator 78 | 79 | ; Keywords 80 | 81 | "abstract" @keyword 82 | "and" @keyword 83 | "as" @keyword 84 | "break" @keyword 85 | "callable" @keyword 86 | "case" @keyword 87 | "catch" @keyword 88 | "class" @keyword 89 | "clone" @keyword 90 | "const" @keyword 91 | "continue" @keyword 92 | "declare" @keyword 93 | "default" @keyword 94 | "do" @keyword 95 | "echo" @keyword 96 | "else" @keyword 97 | "elseif" @keyword 98 | "enum" @keyword 99 | "enddeclare" @keyword 100 | "endfor" @keyword 101 | "endforeach" @keyword 102 | "endif" @keyword 103 | "endswitch" @keyword 104 | "endwhile" @keyword 105 | "extends" @keyword 106 | "final" @keyword 107 | "readonly" @keyword 108 | "finally" @keyword 109 | "for" @keyword 110 | "foreach" @keyword 111 | "fn" @keyword 112 | "from" @keyword 113 | "function" @keyword 114 | "global" @keyword 115 | "goto" @keyword 116 | "if" @keyword 117 | "implements" @keyword 118 | "include_once" @keyword 119 | "include" @keyword 120 | "instanceof" @keyword 121 | "insteadof" @keyword 122 | "interface" @keyword 123 | "match" @keyword 124 | "namespace" @keyword 125 | "new" @keyword 126 | "or" @keyword 127 | "print" @keyword 128 | "private" @keyword 129 | "protected" @keyword 130 | "public" @keyword 131 | "readonly" @keyword 132 | "require_once" @keyword 133 | "require" @keyword 134 | "return" @keyword 135 | "static" @keyword 136 | "switch" @keyword 137 | "throw" @keyword 138 | "trait" @keyword 139 | "try" @keyword 140 | "use" @keyword 141 | "while" @keyword 142 | "xor" @keyword 143 | "yield" @keyword 144 | -------------------------------------------------------------------------------- /languages/php/indents.scm: -------------------------------------------------------------------------------- 1 | (_ "{" "}" @end) @indent 2 | -------------------------------------------------------------------------------- /languages/php/injections.scm: -------------------------------------------------------------------------------- 1 | ((text) @injection.content 2 | (#set! injection.language "html") 3 | (#set! injection.combined)) 4 | 5 | ((comment) @injection.content 6 | (#match? @injection.content "^/\\*\\*[^*]") 7 | (#set! injection.language "phpdoc")) 8 | 9 | ((heredoc_body) (heredoc_end) @injection.language) @injection.content 10 | 11 | ((nowdoc_body) (heredoc_end) @injection.language) @injection.content 12 | -------------------------------------------------------------------------------- /languages/php/outline.scm: -------------------------------------------------------------------------------- 1 | (class_declaration 2 | "class" @context 3 | name: (name) @name 4 | ) @item 5 | 6 | (function_definition 7 | "function" @context 8 | name: (_) @name 9 | ) @item 10 | 11 | (method_declaration 12 | "function" @context 13 | name: (_) @name 14 | ) @item 15 | 16 | (interface_declaration 17 | "interface" @context 18 | name: (_) @name 19 | ) @item 20 | 21 | (enum_declaration 22 | "enum" @context 23 | name: (_) @name 24 | ) @item 25 | 26 | (trait_declaration 27 | "trait" @context 28 | name: (_) @name 29 | ) @item 30 | 31 | ; Add support for Pest runnable 32 | (function_call_expression 33 | function: (_) @context 34 | (#any-of? @context "it" "test" "describe") 35 | arguments: (arguments 36 | . 37 | (argument 38 | [ 39 | (encapsed_string (string_value) @name) 40 | (string (string_value) @name) 41 | ] 42 | ) 43 | ) 44 | ) @item 45 | 46 | (comment) @annotation 47 | -------------------------------------------------------------------------------- /languages/php/runnables.scm: -------------------------------------------------------------------------------- 1 | ; Class that follow the naming convention of PHPUnit test classes 2 | ; and that doesn't have the abstract modifier 3 | ; and have a method that follow the naming convention of PHPUnit test methods 4 | ; and the method is public 5 | ( 6 | (class_declaration 7 | modifier: (_)? @_modifier 8 | (#not-eq? @_modifier "abstract") 9 | name: (_) @_name 10 | (#match? @_name ".*Test$") 11 | body: (declaration_list 12 | (method_declaration 13 | (visibility_modifier)? @_visibility 14 | (#eq? @_visibility "public") 15 | name: (_) @run 16 | (#match? @run "^test.*") 17 | ) 18 | ) 19 | ) @_phpunit-test 20 | (#set! tag phpunit-test) 21 | ) 22 | 23 | ; Class that follow the naming convention of PHPUnit test classes 24 | ; and that doesn't have the abstract modifier 25 | ; and have a method that has the @test annotation 26 | ; and the method is public 27 | ( 28 | (class_declaration 29 | modifier: (_)? @_modifier 30 | (#not-eq? @_modifier "abstract") 31 | name: (_) @_name 32 | (#match? @_name ".*Test$") 33 | body: (declaration_list 34 | ((comment) @_comment 35 | (#match? @_comment ".*@test\\b.*") 36 | . 37 | (method_declaration 38 | (visibility_modifier)? @_visibility 39 | (#eq? @_visibility "public") 40 | name: (_) @run 41 | (#not-match? @run "^test.*") 42 | )) 43 | ) 44 | ) @_phpunit-test 45 | (#set! tag phpunit-test) 46 | ) 47 | 48 | ; Class that follow the naming convention of PHPUnit test classes 49 | ; and that doesn't have the abstract modifier 50 | ; and have a method that has the #[Test] attribute 51 | ; and the method is public 52 | ( 53 | (class_declaration 54 | modifier: (_)? @_modifier 55 | (#not-eq? @_modifier "abstract") 56 | name: (_) @_name 57 | (#match? @_name ".*Test$") 58 | body: (declaration_list 59 | (method_declaration 60 | (attribute_list 61 | (attribute_group 62 | (attribute (name) @_attribute) 63 | ) 64 | ) 65 | (#eq? @_attribute "Test") 66 | (visibility_modifier)? @_visibility 67 | (#eq? @_visibility "public") 68 | name: (_) @run 69 | (#not-match? @run "^test.*") 70 | ) 71 | ) 72 | ) @_phpunit-test 73 | (#set! tag phpunit-test) 74 | ) 75 | 76 | ; Class that follow the naming convention of PHPUnit test classes 77 | ; and that doesn't have the abstract modifier 78 | ( 79 | (class_declaration 80 | modifier: (_)? @_modifier 81 | (#not-eq? @_modifier "abstract") 82 | name: (_) @run 83 | (#match? @run ".*Test$") 84 | ) @_phpunit-test 85 | (#set! tag phpunit-test) 86 | ) 87 | 88 | ; Add support for Pest runnable 89 | ; Function expression that has `it`, `test` or `describe` as the function name 90 | ( 91 | (function_call_expression 92 | function: (_) @_name 93 | (#any-of? @_name "it" "test" "describe") 94 | arguments: (arguments 95 | . 96 | (argument 97 | [ 98 | (encapsed_string (string_value) @run) 99 | (string (string_value) @run) 100 | ] 101 | ) 102 | ) 103 | ) @_pest-test 104 | (#set! tag pest-test) 105 | ) 106 | -------------------------------------------------------------------------------- /languages/php/tags.scm: -------------------------------------------------------------------------------- 1 | (namespace_definition 2 | name: (namespace_name) @name) @module 3 | 4 | (interface_declaration 5 | name: (name) @name) @definition.interface 6 | 7 | (trait_declaration 8 | name: (name) @name) @definition.interface 9 | 10 | (class_declaration 11 | name: (name) @name) @definition.class 12 | 13 | (class_interface_clause [(name) (qualified_name)] @name) @impl 14 | 15 | (property_declaration 16 | (property_element (variable_name (name) @name))) @definition.field 17 | 18 | (function_definition 19 | name: (name) @name) @definition.function 20 | 21 | (method_declaration 22 | name: (name) @name) @definition.function 23 | 24 | (object_creation_expression 25 | [ 26 | (qualified_name (name) @name) 27 | (variable_name (name) @name) 28 | ]) @reference.class 29 | 30 | (function_call_expression 31 | function: [ 32 | (qualified_name (name) @name) 33 | (variable_name (name)) @name 34 | ]) @reference.call 35 | 36 | (scoped_call_expression 37 | name: (name) @name) @reference.call 38 | 39 | (member_call_expression 40 | name: (name) @name) @reference.call 41 | -------------------------------------------------------------------------------- /languages/php/tasks.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "label": "phpunit test $ZED_SYMBOL", 4 | "command": "./vendor/bin/phpunit", 5 | "args": ["--filter $ZED_SYMBOL $ZED_FILE"], 6 | "tags": ["phpunit-test"] 7 | }, 8 | { 9 | "label": "pest test $ZED_SYMBOL", 10 | "command": "./vendor/bin/pest", 11 | "args": ["--filter \"$ZED_SYMBOL\" $ZED_FILE"], 12 | "tags": ["pest-test"] 13 | }, 14 | { 15 | "label": "execute selection $ZED_SELECTED_TEXT", 16 | "command": "php", 17 | "args": ["-r", "$ZED_SELECTED_TEXT"] 18 | } 19 | ] 20 | -------------------------------------------------------------------------------- /languages/php/textobjects.scm: -------------------------------------------------------------------------------- 1 | (function_definition 2 | body: (_ 3 | "{" 4 | (_)* @function.inside 5 | "}" )) @function.around 6 | 7 | (method_declaration 8 | body: (_ 9 | "{" 10 | (_)* @function.inside 11 | "}" )) @function.around 12 | 13 | (method_declaration) @function.around 14 | 15 | (class_declaration 16 | body: (_ 17 | "{" 18 | (_)* @class.inside 19 | "}")) @class.around 20 | 21 | (interface_declaration 22 | body: (_ 23 | "{" 24 | (_)* @class.inside 25 | "}")) @class.around 26 | 27 | (trait_declaration 28 | body: (_ 29 | "{" 30 | (_)* @class.inside 31 | "}")) @class.around 32 | 33 | (enum_declaration 34 | body: (_ 35 | "{" 36 | (_)* @class.inside 37 | "}")) @class.around 38 | 39 | (namespace_definition 40 | body: (_ 41 | "{" 42 | (_)* @class.inside 43 | "}")) @class.around 44 | 45 | (comment)+ @comment.around 46 | -------------------------------------------------------------------------------- /languages/phpdoc/config.toml: -------------------------------------------------------------------------------- 1 | name = "PHPDoc" 2 | grammar = "phpdoc" 3 | autoclose_before = "]})>" 4 | brackets = [ 5 | { start = "{", end = "}", close = true, newline = false }, 6 | { start = "[", end = "]", close = true, newline = false }, 7 | { start = "(", end = ")", close = true, newline = false }, 8 | { start = "<", end = ">", close = true, newline = false }, 9 | ] 10 | hidden = true 11 | -------------------------------------------------------------------------------- /languages/phpdoc/highlights.scm: -------------------------------------------------------------------------------- 1 | (tag_name) @keyword 2 | 3 | (tag (variable_name) @variable) 4 | (variable_name "$" @operator) 5 | 6 | (tag 7 | (tag_name) @keyword 8 | (#eq? @keyword "@method") 9 | (name) @function.method) 10 | 11 | (primitive_type) @type.builtin 12 | (named_type (name) @type) @type 13 | (named_type (qualified_name) @type) @type 14 | -------------------------------------------------------------------------------- /src/language_servers.rs: -------------------------------------------------------------------------------- 1 | mod intelephense; 2 | mod phpactor; 3 | 4 | pub use intelephense::*; 5 | pub use phpactor::*; 6 | -------------------------------------------------------------------------------- /src/language_servers/intelephense.rs: -------------------------------------------------------------------------------- 1 | use std::{env, fs}; 2 | 3 | use zed::{CodeLabel, CodeLabelSpan}; 4 | use zed_extension_api::settings::LspSettings; 5 | use zed_extension_api::{self as zed, serde_json, LanguageServerId, Result}; 6 | 7 | const SERVER_PATH: &str = "node_modules/intelephense/lib/intelephense.js"; 8 | const PACKAGE_NAME: &str = "intelephense"; 9 | 10 | pub struct Intelephense { 11 | did_find_server: bool, 12 | } 13 | 14 | impl Intelephense { 15 | pub const LANGUAGE_SERVER_ID: &'static str = "intelephense"; 16 | 17 | pub fn new() -> Self { 18 | Self { 19 | did_find_server: false, 20 | } 21 | } 22 | 23 | pub fn language_server_command( 24 | &mut self, 25 | language_server_id: &LanguageServerId, 26 | worktree: &zed::Worktree, 27 | ) -> Result { 28 | if let Some(path) = worktree.which("intelephense") { 29 | return Ok(zed::Command { 30 | command: path, 31 | args: vec!["--stdio".to_string()], 32 | env: Default::default(), 33 | }); 34 | } 35 | 36 | let server_path = self.server_script_path(language_server_id)?; 37 | Ok(zed::Command { 38 | command: zed::node_binary_path()?, 39 | args: vec![ 40 | env::current_dir() 41 | .unwrap() 42 | .join(&server_path) 43 | .to_string_lossy() 44 | .to_string(), 45 | "--stdio".to_string(), 46 | ], 47 | env: Default::default(), 48 | }) 49 | } 50 | 51 | fn server_exists(&self) -> bool { 52 | fs::metadata(SERVER_PATH).map_or(false, |stat| stat.is_file()) 53 | } 54 | 55 | fn server_script_path(&mut self, language_server_id: &LanguageServerId) -> Result { 56 | let server_exists = self.server_exists(); 57 | if self.did_find_server && server_exists { 58 | return Ok(SERVER_PATH.to_string()); 59 | } 60 | 61 | zed::set_language_server_installation_status( 62 | language_server_id, 63 | &zed::LanguageServerInstallationStatus::CheckingForUpdate, 64 | ); 65 | let version = zed::npm_package_latest_version(PACKAGE_NAME)?; 66 | 67 | if !server_exists 68 | || zed::npm_package_installed_version(PACKAGE_NAME)?.as_ref() != Some(&version) 69 | { 70 | zed::set_language_server_installation_status( 71 | language_server_id, 72 | &zed::LanguageServerInstallationStatus::Downloading, 73 | ); 74 | let result = zed::npm_install_package(PACKAGE_NAME, &version); 75 | match result { 76 | Ok(()) => { 77 | if !self.server_exists() { 78 | Err(format!( 79 | "installed package '{PACKAGE_NAME}' did not contain expected path '{SERVER_PATH}'", 80 | ))?; 81 | } 82 | } 83 | Err(error) => { 84 | if !self.server_exists() { 85 | Err(error)?; 86 | } 87 | } 88 | } 89 | } 90 | 91 | self.did_find_server = true; 92 | Ok(SERVER_PATH.to_string()) 93 | } 94 | 95 | pub fn language_server_workspace_configuration( 96 | &mut self, 97 | worktree: &zed::Worktree, 98 | ) -> Result> { 99 | let settings = LspSettings::for_worktree("intelephense", worktree) 100 | .ok() 101 | .and_then(|lsp_settings| lsp_settings.settings.clone()) 102 | .unwrap_or_default(); 103 | 104 | Ok(Some(serde_json::json!({ 105 | "intelephense": settings 106 | }))) 107 | } 108 | 109 | pub fn label_for_completion(&self, completion: zed::lsp::Completion) -> Option { 110 | let label = &completion.label; 111 | 112 | match completion.kind? { 113 | zed::lsp::CompletionKind::Method => { 114 | // __construct method doesn't have a detail 115 | if let Some(ref detail) = completion.detail { 116 | if detail.is_empty() { 117 | return Some(CodeLabel { 118 | spans: vec![ 119 | CodeLabelSpan::literal(label, Some("function.method".to_string())), 120 | CodeLabelSpan::literal("()", None), 121 | ], 122 | filter_range: (0..label.len()).into(), 123 | code: completion.label, 124 | }); 125 | } 126 | } 127 | 128 | let mut parts = completion.detail.as_ref()?.split(":"); 129 | // E.g., `foo(string $var)` 130 | let name_and_params = parts.next()?; 131 | let return_type = parts.next()?.trim(); 132 | 133 | let (_, params) = name_and_params.split_once("(")?; 134 | let params = params.trim_end_matches(")"); 135 | 136 | Some(CodeLabel { 137 | spans: vec![ 138 | CodeLabelSpan::literal(label, Some("function.method".to_string())), 139 | CodeLabelSpan::literal("(", None), 140 | CodeLabelSpan::literal(params, Some("comment".to_string())), 141 | CodeLabelSpan::literal("): ", None), 142 | CodeLabelSpan::literal(return_type, Some("type".to_string())), 143 | ], 144 | filter_range: (0..label.len()).into(), 145 | code: completion.label, 146 | }) 147 | } 148 | zed::lsp::CompletionKind::Constant | zed::lsp::CompletionKind::EnumMember => { 149 | if let Some(ref detail) = completion.detail { 150 | if !detail.is_empty() { 151 | return Some(CodeLabel { 152 | spans: vec![ 153 | CodeLabelSpan::literal(label, Some("constant".to_string())), 154 | CodeLabelSpan::literal(" ", None), 155 | CodeLabelSpan::literal(detail, Some("comment".to_string())), 156 | ], 157 | filter_range: (0..label.len()).into(), 158 | code: completion.label, 159 | }); 160 | } 161 | } 162 | 163 | Some(CodeLabel { 164 | spans: vec![CodeLabelSpan::literal(label, Some("constant".to_string()))], 165 | filter_range: (0..label.len()).into(), 166 | code: completion.label, 167 | }) 168 | } 169 | zed::lsp::CompletionKind::Property => { 170 | let return_type = completion.detail?; 171 | Some(CodeLabel { 172 | spans: vec![ 173 | CodeLabelSpan::literal(label, Some("attribute".to_string())), 174 | CodeLabelSpan::literal(": ", None), 175 | CodeLabelSpan::literal(return_type, Some("type".to_string())), 176 | ], 177 | filter_range: (0..label.len()).into(), 178 | code: completion.label, 179 | }) 180 | } 181 | zed::lsp::CompletionKind::Variable => { 182 | // See https://www.php.net/manual/en/reserved.variables.php 183 | const SYSTEM_VAR_NAMES: &[&str] = 184 | &["argc", "argv", "php_errormsg", "http_response_header"]; 185 | 186 | let var_name = completion.label.trim_start_matches("$"); 187 | let is_uppercase = var_name 188 | .chars() 189 | .filter(|c| c.is_alphabetic()) 190 | .all(|c| c.is_uppercase()); 191 | let is_system_constant = var_name.starts_with("_"); 192 | let is_reserved = SYSTEM_VAR_NAMES.contains(&var_name); 193 | 194 | let highlight = if is_uppercase || is_system_constant || is_reserved { 195 | Some("comment".to_string()) 196 | } else { 197 | None 198 | }; 199 | 200 | Some(CodeLabel { 201 | spans: vec![CodeLabelSpan::literal(label, highlight)], 202 | filter_range: (0..label.len()).into(), 203 | code: completion.label, 204 | }) 205 | } 206 | _ => None, 207 | } 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/language_servers/phpactor.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | use zed_extension_api::{self as zed, LanguageServerId, Result}; 4 | 5 | pub struct Phpactor { 6 | cached_binary_path: Option, 7 | } 8 | 9 | impl Phpactor { 10 | pub const LANGUAGE_SERVER_ID: &'static str = "phpactor"; 11 | 12 | pub fn new() -> Self { 13 | Self { 14 | cached_binary_path: None, 15 | } 16 | } 17 | 18 | pub fn language_server_binary_path( 19 | &mut self, 20 | language_server_id: &LanguageServerId, 21 | worktree: &zed::Worktree, 22 | ) -> Result { 23 | if let Some(path) = worktree.which("phpactor") { 24 | return Ok(path); 25 | } 26 | 27 | if let Some(path) = &self.cached_binary_path { 28 | if fs::metadata(path).map_or(false, |stat| stat.is_file()) { 29 | return Ok(path.clone()); 30 | } 31 | } 32 | 33 | zed::set_language_server_installation_status( 34 | language_server_id, 35 | &zed::LanguageServerInstallationStatus::CheckingForUpdate, 36 | ); 37 | let release = zed::latest_github_release( 38 | "phpactor/phpactor", 39 | zed::GithubReleaseOptions { 40 | require_assets: true, 41 | pre_release: false, 42 | }, 43 | )?; 44 | 45 | let asset_name = "phpactor.phar"; 46 | let asset = release 47 | .assets 48 | .iter() 49 | .find(|asset| asset.name == asset_name) 50 | .ok_or_else(|| format!("no asset found matching {:?}", asset_name))?; 51 | 52 | let version_dir = format!("phpactor-{}", release.version); 53 | fs::create_dir_all(&version_dir).map_err(|e| format!("failed to create directory: {e}"))?; 54 | 55 | let binary_path = format!("{version_dir}/phpactor.phar"); 56 | 57 | if !fs::metadata(&binary_path).map_or(false, |stat| stat.is_file()) { 58 | zed::set_language_server_installation_status( 59 | language_server_id, 60 | &zed::LanguageServerInstallationStatus::Downloading, 61 | ); 62 | 63 | zed::download_file( 64 | &asset.download_url, 65 | &binary_path, 66 | zed::DownloadedFileType::Uncompressed, 67 | ) 68 | .map_err(|e| format!("failed to download file: {e}"))?; 69 | 70 | zed::make_file_executable(&binary_path)?; 71 | 72 | let entries = 73 | fs::read_dir(".").map_err(|e| format!("failed to list working directory {e}"))?; 74 | for entry in entries { 75 | let entry = entry.map_err(|e| format!("failed to load directory entry {e}"))?; 76 | if entry.file_name().to_str() != Some(&version_dir) { 77 | fs::remove_dir_all(entry.path()).ok(); 78 | } 79 | } 80 | } 81 | 82 | self.cached_binary_path = Some(binary_path.clone()); 83 | Ok(binary_path) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/php.rs: -------------------------------------------------------------------------------- 1 | mod language_servers; 2 | 3 | use zed::CodeLabel; 4 | use zed_extension_api::{self as zed, serde_json, LanguageServerId, Result}; 5 | 6 | use crate::language_servers::{Intelephense, Phpactor}; 7 | 8 | struct PhpExtension { 9 | intelephense: Option, 10 | phpactor: Option, 11 | } 12 | 13 | impl zed::Extension for PhpExtension { 14 | fn new() -> Self { 15 | Self { 16 | intelephense: None, 17 | phpactor: None, 18 | } 19 | } 20 | 21 | fn language_server_command( 22 | &mut self, 23 | language_server_id: &LanguageServerId, 24 | worktree: &zed::Worktree, 25 | ) -> Result { 26 | match language_server_id.as_ref() { 27 | Intelephense::LANGUAGE_SERVER_ID => { 28 | let intelephense = self.intelephense.get_or_insert_with(Intelephense::new); 29 | intelephense.language_server_command(language_server_id, worktree) 30 | } 31 | Phpactor::LANGUAGE_SERVER_ID => { 32 | let phpactor = self.phpactor.get_or_insert_with(Phpactor::new); 33 | 34 | Ok(zed::Command { 35 | command: phpactor.language_server_binary_path(language_server_id, worktree)?, 36 | args: vec!["language-server".into()], 37 | env: Default::default(), 38 | }) 39 | } 40 | language_server_id => Err(format!("unknown language server: {language_server_id}")), 41 | } 42 | } 43 | 44 | fn language_server_workspace_configuration( 45 | &mut self, 46 | language_server_id: &LanguageServerId, 47 | worktree: &zed::Worktree, 48 | ) -> Result> { 49 | if language_server_id.as_ref() == Intelephense::LANGUAGE_SERVER_ID { 50 | if let Some(intelephense) = self.intelephense.as_mut() { 51 | return intelephense.language_server_workspace_configuration(worktree); 52 | } 53 | } 54 | 55 | Ok(None) 56 | } 57 | 58 | fn label_for_completion( 59 | &self, 60 | language_server_id: &zed::LanguageServerId, 61 | completion: zed::lsp::Completion, 62 | ) -> Option { 63 | match language_server_id.as_ref() { 64 | Intelephense::LANGUAGE_SERVER_ID => { 65 | self.intelephense.as_ref()?.label_for_completion(completion) 66 | } 67 | _ => None, 68 | } 69 | } 70 | } 71 | 72 | zed::register_extension!(PhpExtension); 73 | --------------------------------------------------------------------------------