├── .cargo └── config.toml ├── .editorconfig ├── .lapce └── settings.toml ├── .rustfmt.toml ├── .vscode ├── extensions.json └── settings.json ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── Makefile.toml ├── README.md ├── bin └── lapce-cpp-clangd.wasm ├── src └── main.rs └── volt.toml /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [alias] 2 | m = "make" 3 | i = ["install", "--path", "."] 4 | 5 | [install] 6 | root = "." 7 | 8 | [build] 9 | target = "wasm32-wasi" 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset = utf-8 3 | end_of_line = lf 4 | insert_final_newline = true 5 | 6 | [*.{toml,json,rs}] 7 | indent_size = 2 8 | indent_style = space 9 | -------------------------------------------------------------------------------- /.lapce/settings.toml: -------------------------------------------------------------------------------- 1 | [lapce-rust.checkOnSave] 2 | command = "clippy" 3 | -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | reorder_imports = true 2 | match_arm_leading_pipes = "always" 3 | newline_style = "unix" 4 | tab_spaces = 2 5 | # imports_granularity = "Crate" 6 | # group_imports = "StdExternalCrate" 7 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "zerotaskx.rust-extension-pack", 4 | "Swellaby.rust-pack" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.checkOnSave.command": "clippy", 3 | "files.exclude": { 4 | "**/.crates.toml": true, 5 | "**/.crates2.json": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /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 = "adler" 7 | version = "1.0.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 10 | 11 | [[package]] 12 | name = "anyhow" 13 | version = "1.0.65" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" 16 | 17 | [[package]] 18 | name = "bitflags" 19 | version = "1.3.2" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 22 | 23 | [[package]] 24 | name = "byteorder" 25 | version = "1.4.3" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" 28 | 29 | [[package]] 30 | name = "bytes" 31 | version = "1.2.1" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" 34 | 35 | [[package]] 36 | name = "cfg-if" 37 | version = "1.0.0" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 40 | 41 | [[package]] 42 | name = "crc32fast" 43 | version = "1.3.2" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" 46 | dependencies = [ 47 | "cfg-if", 48 | ] 49 | 50 | [[package]] 51 | name = "crossbeam-channel" 52 | version = "0.5.6" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" 55 | dependencies = [ 56 | "cfg-if", 57 | "crossbeam-utils", 58 | ] 59 | 60 | [[package]] 61 | name = "crossbeam-utils" 62 | version = "0.8.12" 63 | source = "registry+https://github.com/rust-lang/crates.io-index" 64 | checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" 65 | dependencies = [ 66 | "cfg-if", 67 | ] 68 | 69 | [[package]] 70 | name = "flate2" 71 | version = "1.0.24" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" 74 | dependencies = [ 75 | "crc32fast", 76 | "miniz_oxide", 77 | ] 78 | 79 | [[package]] 80 | name = "fnv" 81 | version = "1.0.7" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 84 | 85 | [[package]] 86 | name = "form_urlencoded" 87 | version = "1.1.0" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" 90 | dependencies = [ 91 | "percent-encoding", 92 | ] 93 | 94 | [[package]] 95 | name = "http" 96 | version = "0.2.8" 97 | source = "registry+https://github.com/rust-lang/crates.io-index" 98 | checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" 99 | dependencies = [ 100 | "bytes", 101 | "fnv", 102 | "itoa", 103 | ] 104 | 105 | [[package]] 106 | name = "idna" 107 | version = "0.3.0" 108 | source = "registry+https://github.com/rust-lang/crates.io-index" 109 | checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" 110 | dependencies = [ 111 | "unicode-bidi", 112 | "unicode-normalization", 113 | ] 114 | 115 | [[package]] 116 | name = "itoa" 117 | version = "1.0.4" 118 | source = "registry+https://github.com/rust-lang/crates.io-index" 119 | checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" 120 | 121 | [[package]] 122 | name = "jsonrpc-lite" 123 | version = "0.5.0" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | checksum = "a98d245f26984add78277a5306ca0cf774863d4eddb4912b31d94ee3fa1a22d4" 126 | dependencies = [ 127 | "serde", 128 | "serde_derive", 129 | "serde_json", 130 | ] 131 | 132 | [[package]] 133 | name = "lapce-cpp-clangd" 134 | version = "1.0.0" 135 | dependencies = [ 136 | "anyhow", 137 | "lapce-plugin", 138 | "serde", 139 | "serde_json", 140 | "zip", 141 | ] 142 | 143 | [[package]] 144 | name = "lapce-plugin" 145 | version = "0.1.0" 146 | source = "git+https://github.com/lapce/lapce-plugin-rust.git#768bb44edf5ca3d777a5ba13ec8d2de10b80cdae" 147 | dependencies = [ 148 | "anyhow", 149 | "bytes", 150 | "crossbeam-channel", 151 | "http", 152 | "jsonrpc-lite", 153 | "once_cell", 154 | "psp-types", 155 | "serde", 156 | "serde_json", 157 | "wasi-experimental-http", 158 | ] 159 | 160 | [[package]] 161 | name = "log" 162 | version = "0.4.17" 163 | source = "registry+https://github.com/rust-lang/crates.io-index" 164 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" 165 | dependencies = [ 166 | "cfg-if", 167 | ] 168 | 169 | [[package]] 170 | name = "lsp-types" 171 | version = "0.93.1" 172 | source = "registry+https://github.com/rust-lang/crates.io-index" 173 | checksum = "a3bcfee315dde785ba887edb540b08765fd7df75a7d948844be6bf5712246734" 174 | dependencies = [ 175 | "bitflags", 176 | "serde", 177 | "serde_json", 178 | "serde_repr", 179 | "url", 180 | ] 181 | 182 | [[package]] 183 | name = "miniz_oxide" 184 | version = "0.5.4" 185 | source = "registry+https://github.com/rust-lang/crates.io-index" 186 | checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" 187 | dependencies = [ 188 | "adler", 189 | ] 190 | 191 | [[package]] 192 | name = "once_cell" 193 | version = "1.15.0" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" 196 | 197 | [[package]] 198 | name = "percent-encoding" 199 | version = "2.2.0" 200 | source = "registry+https://github.com/rust-lang/crates.io-index" 201 | checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" 202 | 203 | [[package]] 204 | name = "pin-project-lite" 205 | version = "0.2.9" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" 208 | 209 | [[package]] 210 | name = "proc-macro2" 211 | version = "1.0.46" 212 | source = "registry+https://github.com/rust-lang/crates.io-index" 213 | checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" 214 | dependencies = [ 215 | "unicode-ident", 216 | ] 217 | 218 | [[package]] 219 | name = "psp-types" 220 | version = "0.1.0" 221 | source = "git+https://github.com/lapce/psp-types?branch=master#b7680c844e8faa1b79c800210b4d5526771e7de0" 222 | dependencies = [ 223 | "lsp-types", 224 | "serde", 225 | "serde_json", 226 | ] 227 | 228 | [[package]] 229 | name = "quote" 230 | version = "1.0.21" 231 | source = "registry+https://github.com/rust-lang/crates.io-index" 232 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 233 | dependencies = [ 234 | "proc-macro2", 235 | ] 236 | 237 | [[package]] 238 | name = "ryu" 239 | version = "1.0.11" 240 | source = "registry+https://github.com/rust-lang/crates.io-index" 241 | checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" 242 | 243 | [[package]] 244 | name = "serde" 245 | version = "1.0.145" 246 | source = "registry+https://github.com/rust-lang/crates.io-index" 247 | checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" 248 | dependencies = [ 249 | "serde_derive", 250 | ] 251 | 252 | [[package]] 253 | name = "serde_derive" 254 | version = "1.0.145" 255 | source = "registry+https://github.com/rust-lang/crates.io-index" 256 | checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" 257 | dependencies = [ 258 | "proc-macro2", 259 | "quote", 260 | "syn", 261 | ] 262 | 263 | [[package]] 264 | name = "serde_json" 265 | version = "1.0.86" 266 | source = "registry+https://github.com/rust-lang/crates.io-index" 267 | checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074" 268 | dependencies = [ 269 | "itoa", 270 | "ryu", 271 | "serde", 272 | ] 273 | 274 | [[package]] 275 | name = "serde_repr" 276 | version = "0.1.9" 277 | source = "registry+https://github.com/rust-lang/crates.io-index" 278 | checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" 279 | dependencies = [ 280 | "proc-macro2", 281 | "quote", 282 | "syn", 283 | ] 284 | 285 | [[package]] 286 | name = "syn" 287 | version = "1.0.102" 288 | source = "registry+https://github.com/rust-lang/crates.io-index" 289 | checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1" 290 | dependencies = [ 291 | "proc-macro2", 292 | "quote", 293 | "unicode-ident", 294 | ] 295 | 296 | [[package]] 297 | name = "thiserror" 298 | version = "1.0.37" 299 | source = "registry+https://github.com/rust-lang/crates.io-index" 300 | checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" 301 | dependencies = [ 302 | "thiserror-impl", 303 | ] 304 | 305 | [[package]] 306 | name = "thiserror-impl" 307 | version = "1.0.37" 308 | source = "registry+https://github.com/rust-lang/crates.io-index" 309 | checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" 310 | dependencies = [ 311 | "proc-macro2", 312 | "quote", 313 | "syn", 314 | ] 315 | 316 | [[package]] 317 | name = "tinyvec" 318 | version = "1.6.0" 319 | source = "registry+https://github.com/rust-lang/crates.io-index" 320 | checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" 321 | dependencies = [ 322 | "tinyvec_macros", 323 | ] 324 | 325 | [[package]] 326 | name = "tinyvec_macros" 327 | version = "0.1.0" 328 | source = "registry+https://github.com/rust-lang/crates.io-index" 329 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" 330 | 331 | [[package]] 332 | name = "tracing" 333 | version = "0.1.37" 334 | source = "registry+https://github.com/rust-lang/crates.io-index" 335 | checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" 336 | dependencies = [ 337 | "cfg-if", 338 | "log", 339 | "pin-project-lite", 340 | "tracing-attributes", 341 | "tracing-core", 342 | ] 343 | 344 | [[package]] 345 | name = "tracing-attributes" 346 | version = "0.1.23" 347 | source = "registry+https://github.com/rust-lang/crates.io-index" 348 | checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" 349 | dependencies = [ 350 | "proc-macro2", 351 | "quote", 352 | "syn", 353 | ] 354 | 355 | [[package]] 356 | name = "tracing-core" 357 | version = "0.1.30" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" 360 | dependencies = [ 361 | "once_cell", 362 | ] 363 | 364 | [[package]] 365 | name = "unicode-bidi" 366 | version = "0.3.8" 367 | source = "registry+https://github.com/rust-lang/crates.io-index" 368 | checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" 369 | 370 | [[package]] 371 | name = "unicode-ident" 372 | version = "1.0.5" 373 | source = "registry+https://github.com/rust-lang/crates.io-index" 374 | checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 375 | 376 | [[package]] 377 | name = "unicode-normalization" 378 | version = "0.1.22" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" 381 | dependencies = [ 382 | "tinyvec", 383 | ] 384 | 385 | [[package]] 386 | name = "url" 387 | version = "2.3.1" 388 | source = "registry+https://github.com/rust-lang/crates.io-index" 389 | checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" 390 | dependencies = [ 391 | "form_urlencoded", 392 | "idna", 393 | "percent-encoding", 394 | "serde", 395 | ] 396 | 397 | [[package]] 398 | name = "wasi-experimental-http" 399 | version = "0.9.0" 400 | source = "git+https://github.com/lapce/wasi-experimental-http#3685f0893ef19c1cca5b16a11ba01ff7ade14a5f" 401 | dependencies = [ 402 | "anyhow", 403 | "bytes", 404 | "http", 405 | "thiserror", 406 | "tracing", 407 | ] 408 | 409 | [[package]] 410 | name = "zip" 411 | version = "0.6.3" 412 | source = "registry+https://github.com/rust-lang/crates.io-index" 413 | checksum = "537ce7411d25e54e8ae21a7ce0b15840e7bfcff15b51d697ec3266cc76bdf080" 414 | dependencies = [ 415 | "byteorder", 416 | "crc32fast", 417 | "crossbeam-utils", 418 | "flate2", 419 | ] 420 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | edition = "2021" 3 | name = "lapce-cpp-clangd" 4 | version = "1.0.0" 5 | resolver = "2" 6 | 7 | [target.'cfg(target_os = "wasi")'.dependencies] 8 | zip = { version = "0.6", default-features = false, features = ["deflate"] } 9 | 10 | 11 | # default deps for all lapce plugins 12 | anyhow = "1.0" 13 | serde_json = "1.0" 14 | serde = { version = "1.0", features = ["derive"] } 15 | lapce-plugin = { git = "https://github.com/lapce/lapce-plugin-rust.git" } 16 | 17 | [profile.release] 18 | opt-level = 3 19 | lto = true 20 | codegen-units = 1 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Makefile.toml: -------------------------------------------------------------------------------- 1 | [tasks.default] 2 | clear = true 3 | dependencies = [ 4 | "fmt", 5 | "check", 6 | "clippy", 7 | "release", 8 | ] 9 | 10 | [tasks.fmt] 11 | command = "cargo" 12 | args = ["fmt"] 13 | 14 | [tasks.release] 15 | dependencies = ["build-release"] 16 | 17 | [tasks.dev] 18 | dependencies = ["build-dev"] 19 | 20 | [tasks.check] 21 | command = "cargo" 22 | args = ["check"] 23 | 24 | [tasks.clippy] 25 | command = "cargo" 26 | args = ["clippy"] 27 | 28 | [tasks.build-dev] 29 | command = "cargo" 30 | args = ["install", "--path", ".", "--debug"] 31 | 32 | [tasks.build-release] 33 | command = "cargo" 34 | args = ["install", "--path", "."] 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C/C++ (clangd) for Lapce 2 | 3 | ## Configuration 4 | 5 | In `settings.toml`: 6 | 7 | ```toml 8 | [lapce-cpp-clangd.volt] 9 | clangdVersion = "15.0.0" # git tag from https://github.com/clangd/clangd 10 | serverPath = "" 11 | serverArgs = [ 12 | #custom args 13 | ] 14 | ``` 15 | 16 | ## Platforms 17 | 18 | Plugin will automatically download `clangd` for below architectures 19 | 20 | | Platform | x86_64 (amd64) | aarch64 (arm64) | 21 | | -------- | -------------- | --------------- | 22 | | Linux | ✔️ | ❌ | 23 | | Windows | ✔️ | ❌ | 24 | | macOS | ✔️ | ❌ | 25 | -------------------------------------------------------------------------------- /bin/lapce-cpp-clangd.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/panekj/lapce-cpp-clangd/bf47542fdd9804745f62759252845548f3e645ab/bin/lapce-cpp-clangd.wasm -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fs::{self, File}, 3 | io::{self, Read, Write}, 4 | path::PathBuf, 5 | }; 6 | 7 | use anyhow::{anyhow, Result}; 8 | use lapce_plugin::{ 9 | psp_types::{ 10 | lsp_types::{ 11 | request::Initialize, DocumentFilter, DocumentSelector, InitializeParams, MessageType, Url, 12 | }, 13 | Request, 14 | }, 15 | register_plugin, Http, LapcePlugin, VoltEnvironment, PLUGIN_RPC, 16 | }; 17 | use serde_json::Value; 18 | use zip::ZipArchive; 19 | 20 | #[derive(Default)] 21 | struct State {} 22 | 23 | register_plugin!(State); 24 | 25 | macro_rules! string { 26 | ( $x:expr ) => { 27 | String::from($x) 28 | }; 29 | } 30 | 31 | macro_rules! ok { 32 | ( $x:expr ) => { 33 | match ($x) { 34 | | Ok(v) => v, 35 | | Err(e) => return Err(anyhow!(e)), 36 | } 37 | }; 38 | } 39 | 40 | const CLANGD_VERSION: &str = "15.0.1"; 41 | 42 | fn initialize(params: InitializeParams) -> Result<()> { 43 | let document_selector: DocumentSelector = vec![ 44 | DocumentFilter { 45 | language: Some(string!("cpp")), 46 | pattern: Some(string!("**/*.{H,hh,hpp,h++,C,cc,cpp,c++}")), 47 | scheme: None, 48 | }, 49 | DocumentFilter { 50 | language: Some(string!("c")), 51 | pattern: Some(string!("**/*.{h,c}")), 52 | scheme: None, 53 | }, 54 | ]; 55 | let mut clangd_version = string!(CLANGD_VERSION); 56 | let mut server_args = vec![]; 57 | 58 | if let Some(options) = params.initialization_options.as_ref() { 59 | if let Some(volt) = options.get("volt") { 60 | if let Some(args) = volt.get("serverArgs") { 61 | if let Some(args) = args.as_array() { 62 | for arg in args { 63 | if let Some(arg) = arg.as_str() { 64 | server_args.push(string!(arg)); 65 | } 66 | } 67 | } 68 | } 69 | if let Some(server_path) = volt.get("serverPath") { 70 | if let Some(server_path) = server_path.as_str() { 71 | if !server_path.is_empty() { 72 | let server_uri = ok!(Url::parse(&format!("urn:{}", server_path))); 73 | PLUGIN_RPC.start_lsp( 74 | server_uri, 75 | server_args, 76 | document_selector, 77 | params.initialization_options, 78 | ); 79 | return Ok(()); 80 | } 81 | } 82 | } 83 | if let Some(clangd_ver) = options.get("clangdVersion") { 84 | if let Some(clangd_ver) = clangd_ver.as_str() { 85 | let clangd_ver = clangd_ver.trim(); 86 | if !clangd_ver.is_empty() { 87 | clangd_version = string!(clangd_ver) 88 | } 89 | } 90 | } 91 | } 92 | } 93 | 94 | PLUGIN_RPC.stderr(&format!("clangd: {clangd_version}")); 95 | 96 | let _ = match VoltEnvironment::architecture().as_deref() { 97 | | Ok("x86_64") => "x86_64", 98 | | Ok(v) => return Err(anyhow!("Unsupported ARCH: {}", v)), 99 | | Err(e) => return Err(anyhow!("Error ARCH: {}", e)), 100 | }; 101 | 102 | let mut last_ver = ok!(fs::OpenOptions::new() 103 | .create(true) 104 | .write(true) 105 | .read(true) 106 | .open(".clangd_ver")); 107 | let mut buf = String::new(); 108 | ok!(last_ver.read_to_string(&mut buf)); 109 | 110 | let mut server_path = PathBuf::from(format!("clangd_{clangd_version}")); 111 | server_path = server_path.join("bin"); 112 | 113 | // if buf.trim().is_empty() || buf.trim() != clangd_version { 114 | // if buf.trim() != clangd_version { 115 | // ok!(fs::remove_dir_all(&server_path)); 116 | // } 117 | 118 | let zip_file = match VoltEnvironment::operating_system().as_deref() { 119 | | Ok("macos") => PathBuf::from(format!("clangd-mac-{clangd_version}.zip")), 120 | | Ok("linux") => PathBuf::from(format!("clangd-linux-{clangd_version}.zip")), 121 | | Ok("windows") => PathBuf::from(format!("clangd-windows-{clangd_version}.zip")), 122 | | Ok(v) => return Err(anyhow!("Unsupported OS: {}", v)), 123 | | Err(e) => return Err(anyhow!("Error OS: {}", e)), 124 | }; 125 | 126 | let download_url = format!( 127 | "https://github.com/clangd/clangd/releases/download/{clangd_version}/{}", 128 | zip_file.display() 129 | ); 130 | 131 | let mut resp = ok!(Http::get(&download_url)); 132 | PLUGIN_RPC.stderr(&format!("STATUS_CODE: {:?}", resp.status_code)); 133 | let body = ok!(resp.body_read_all()); 134 | ok!(fs::write(&zip_file, body)); 135 | 136 | let mut zip = ok!(ZipArchive::new(ok!(File::open(&zip_file)))); 137 | 138 | for i in 0..zip.len() { 139 | let mut file = ok!(zip.by_index(i)); 140 | let outpath = match file.enclosed_name() { 141 | | Some(path) => path.to_owned(), 142 | | None => continue, 143 | }; 144 | 145 | if (*file.name()).ends_with('/') { 146 | ok!(fs::create_dir_all(&outpath)); 147 | } else { 148 | if let Some(p) = outpath.parent() { 149 | if !p.exists() { 150 | ok!(fs::create_dir_all(&p)); 151 | } 152 | } 153 | let mut outfile = ok!(File::create(&outpath)); 154 | ok!(io::copy(&mut file, &mut outfile)); 155 | } 156 | 157 | ok!(fs::remove_file(&zip_file)); 158 | } 159 | // } 160 | 161 | ok!(last_ver.write_all(clangd_version.as_bytes())); 162 | 163 | match VoltEnvironment::operating_system().as_deref() { 164 | | Ok("windows") => { 165 | server_path = server_path.join("clangd.exe"); 166 | } 167 | | _ => { 168 | server_path = server_path.join("clangd"); 169 | } 170 | }; 171 | 172 | let volt_uri = ok!(VoltEnvironment::uri()); 173 | let server_path = match server_path.to_str() { 174 | | Some(v) => v, 175 | | None => return Err(anyhow!("server_path.to_str() failed")), 176 | }; 177 | let server_uri = ok!(ok!(Url::parse(&volt_uri)).join(server_path)); 178 | 179 | PLUGIN_RPC.start_lsp( 180 | server_uri, 181 | server_args, 182 | document_selector, 183 | params.initialization_options, 184 | ); 185 | 186 | Ok(()) 187 | } 188 | 189 | impl LapcePlugin for State { 190 | fn handle_request(&mut self, _id: u64, method: String, params: Value) { 191 | #[allow(clippy::single_match)] 192 | match method.as_str() { 193 | | Initialize::METHOD => { 194 | let params: InitializeParams = serde_json::from_value(params).unwrap(); 195 | if let Err(e) = initialize(params) { 196 | PLUGIN_RPC.window_log_message(MessageType::ERROR, e.to_string()); 197 | PLUGIN_RPC.window_show_message(MessageType::ERROR, e.to_string()); 198 | }; 199 | } 200 | | _ => {} 201 | } 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /volt.toml: -------------------------------------------------------------------------------- 1 | author = "panekj" 2 | description = "C/C++ for Lapce: powered by clangd" 3 | display-name = "C/C++ (clangd)" 4 | name = "lapce-cpp-clangd" 5 | version = "1.0.0" 6 | wasm = "bin/lapce-cpp-clangd.wasm" 7 | 8 | [activation] 9 | language = ["c", "cpp"] 10 | workspace-contains = [ 11 | "*/*.c", 12 | "*/*.h", 13 | "*/*.cpp", 14 | "*/*.hpp", 15 | ] 16 | 17 | [config."volt.serverPath"] 18 | default = "" 19 | description = "Path to clangd" 20 | --------------------------------------------------------------------------------