├── .cargo └── config.toml ├── .clippy.toml ├── .editorconfig ├── .gitignore ├── .lapce └── settings.toml ├── .rustfmt.toml ├── .vscode └── settings.json ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── Makefile.toml ├── README.md ├── dist ├── README.md ├── agent.js ├── agent.js.LICENSE.txt ├── agent.js.map ├── compiled │ ├── darwin │ │ ├── arm64 │ │ │ └── kerberos.node │ │ └── x64 │ │ │ └── kerberos.node │ ├── linux │ │ ├── arm64 │ │ │ └── kerberos.node │ │ └── x64 │ │ │ └── kerberos.node │ └── win32 │ │ └── x64 │ │ └── kerberos.node ├── crypt32.node ├── resources │ ├── cl100k │ │ ├── tokenizer_cushman002.json │ │ └── vocab_cushman002.bpe │ ├── cushman001 │ │ ├── tokenizer_cushman001.json │ │ └── vocab_cushman001.bpe │ └── cushman002 │ │ ├── tokenizer_cushman002.json │ │ └── vocab_cushman002.bpe ├── tree-sitter-go.wasm ├── tree-sitter-javascript.wasm ├── tree-sitter-python.wasm ├── tree-sitter-ruby.wasm ├── tree-sitter-tsx.wasm ├── tree-sitter-typescript.wasm └── tree-sitter.wasm ├── src ├── copilot.rs └── 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 | -------------------------------------------------------------------------------- /.clippy.toml: -------------------------------------------------------------------------------- 1 | # disallowed-macros = [ 2 | # { path = "std::print", reason = "won't work in WASI" }, 3 | # { path = "std::println", reason = "won't work in WASI" }, 4 | # { path = "std::eprint", reason = "won't work in WASI" }, 5 | # { path = "std::eprintln", reason = "won't work in WASI" }, 6 | # ] 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset = utf-8 3 | end_of_line = lf 4 | insert_final_newline = true 5 | 6 | [*.toml] 7 | indent_size = 2 8 | indent_style = space 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | copy.sh -------------------------------------------------------------------------------- /.lapce/settings.toml: -------------------------------------------------------------------------------- 1 | [lapce-rust.checkOnSave] 2 | command = "clippy" 3 | -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | reorder_imports = true 2 | newline_style = "unix" 3 | # uncomment once stable 4 | # imports_granularity = "Crate" 5 | # group_imports = "StdExternalCrate" 6 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.checkOnSave.command": "clippy" 3 | } 4 | -------------------------------------------------------------------------------- /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.75" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" 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.5.0" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" 28 | 29 | [[package]] 30 | name = "bytes" 31 | version = "1.5.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" 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.4.0" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" 46 | dependencies = [ 47 | "cfg-if", 48 | ] 49 | 50 | [[package]] 51 | name = "crossbeam-utils" 52 | version = "0.8.19" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" 55 | 56 | [[package]] 57 | name = "flate2" 58 | version = "1.0.28" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" 61 | dependencies = [ 62 | "crc32fast", 63 | "miniz_oxide", 64 | ] 65 | 66 | [[package]] 67 | name = "fnv" 68 | version = "1.0.7" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 71 | 72 | [[package]] 73 | name = "form_urlencoded" 74 | version = "1.2.1" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" 77 | dependencies = [ 78 | "percent-encoding", 79 | ] 80 | 81 | [[package]] 82 | name = "http" 83 | version = "0.2.11" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" 86 | dependencies = [ 87 | "bytes", 88 | "fnv", 89 | "itoa", 90 | ] 91 | 92 | [[package]] 93 | name = "idna" 94 | version = "0.5.0" 95 | source = "registry+https://github.com/rust-lang/crates.io-index" 96 | checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" 97 | dependencies = [ 98 | "unicode-bidi", 99 | "unicode-normalization", 100 | ] 101 | 102 | [[package]] 103 | name = "itoa" 104 | version = "1.0.9" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" 107 | 108 | [[package]] 109 | name = "jsonrpc-lite" 110 | version = "0.5.0" 111 | source = "registry+https://github.com/rust-lang/crates.io-index" 112 | checksum = "a98d245f26984add78277a5306ca0cf774863d4eddb4912b31d94ee3fa1a22d4" 113 | dependencies = [ 114 | "serde", 115 | "serde_derive", 116 | "serde_json", 117 | ] 118 | 119 | [[package]] 120 | name = "lapce-copilot" 121 | version = "1.0.0" 122 | dependencies = [ 123 | "anyhow", 124 | "lapce-plugin", 125 | "serde", 126 | "serde_json", 127 | "zip", 128 | ] 129 | 130 | [[package]] 131 | name = "lapce-plugin" 132 | version = "0.1.1" 133 | source = "git+https://github.com/lapce/lapce-plugin-rust.git#a529f3ab570889890db178622b6104ed17b2168d" 134 | dependencies = [ 135 | "anyhow", 136 | "bytes", 137 | "http", 138 | "jsonrpc-lite", 139 | "lapce-wasi-experimental-http", 140 | "once_cell", 141 | "psp-types", 142 | "serde", 143 | "serde_json", 144 | "thiserror", 145 | ] 146 | 147 | [[package]] 148 | name = "lapce-wasi-experimental-http" 149 | version = "0.10.0" 150 | source = "registry+https://github.com/rust-lang/crates.io-index" 151 | checksum = "caf7608ac13ab536e2481cdbe0cb4e6ecf34f19e0b3dcd6bcd002fe959ce810e" 152 | dependencies = [ 153 | "anyhow", 154 | "bytes", 155 | "http", 156 | "thiserror", 157 | "tracing", 158 | ] 159 | 160 | [[package]] 161 | name = "log" 162 | version = "0.4.20" 163 | source = "registry+https://github.com/rust-lang/crates.io-index" 164 | checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" 165 | 166 | [[package]] 167 | name = "lsp-types" 168 | version = "0.94.1" 169 | source = "git+https://github.com/lapce/lsp-types?rev=3031a76c4452f46ed265eb0154d6bb1d10ddb9f6#3031a76c4452f46ed265eb0154d6bb1d10ddb9f6" 170 | dependencies = [ 171 | "bitflags", 172 | "serde", 173 | "serde_json", 174 | "serde_repr", 175 | "url", 176 | ] 177 | 178 | [[package]] 179 | name = "miniz_oxide" 180 | version = "0.7.2" 181 | source = "registry+https://github.com/rust-lang/crates.io-index" 182 | checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" 183 | dependencies = [ 184 | "adler", 185 | ] 186 | 187 | [[package]] 188 | name = "once_cell" 189 | version = "1.19.0" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" 192 | 193 | [[package]] 194 | name = "percent-encoding" 195 | version = "2.3.1" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" 198 | 199 | [[package]] 200 | name = "pin-project-lite" 201 | version = "0.2.13" 202 | source = "registry+https://github.com/rust-lang/crates.io-index" 203 | checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" 204 | 205 | [[package]] 206 | name = "proc-macro2" 207 | version = "1.0.70" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" 210 | dependencies = [ 211 | "unicode-ident", 212 | ] 213 | 214 | [[package]] 215 | name = "psp-types" 216 | version = "0.1.1" 217 | source = "registry+https://github.com/rust-lang/crates.io-index" 218 | checksum = "d02f4927e711603ca3e881d4eb194bfd2b2b28ae2ac70fbd52ea34a58b659def" 219 | dependencies = [ 220 | "lsp-types", 221 | "serde", 222 | "serde_json", 223 | ] 224 | 225 | [[package]] 226 | name = "quote" 227 | version = "1.0.33" 228 | source = "registry+https://github.com/rust-lang/crates.io-index" 229 | checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" 230 | dependencies = [ 231 | "proc-macro2", 232 | ] 233 | 234 | [[package]] 235 | name = "ryu" 236 | version = "1.0.15" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" 239 | 240 | [[package]] 241 | name = "serde" 242 | version = "1.0.193" 243 | source = "registry+https://github.com/rust-lang/crates.io-index" 244 | checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" 245 | dependencies = [ 246 | "serde_derive", 247 | ] 248 | 249 | [[package]] 250 | name = "serde_derive" 251 | version = "1.0.193" 252 | source = "registry+https://github.com/rust-lang/crates.io-index" 253 | checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" 254 | dependencies = [ 255 | "proc-macro2", 256 | "quote", 257 | "syn", 258 | ] 259 | 260 | [[package]] 261 | name = "serde_json" 262 | version = "1.0.108" 263 | source = "registry+https://github.com/rust-lang/crates.io-index" 264 | checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" 265 | dependencies = [ 266 | "itoa", 267 | "ryu", 268 | "serde", 269 | ] 270 | 271 | [[package]] 272 | name = "serde_repr" 273 | version = "0.1.17" 274 | source = "registry+https://github.com/rust-lang/crates.io-index" 275 | checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" 276 | dependencies = [ 277 | "proc-macro2", 278 | "quote", 279 | "syn", 280 | ] 281 | 282 | [[package]] 283 | name = "syn" 284 | version = "2.0.39" 285 | source = "registry+https://github.com/rust-lang/crates.io-index" 286 | checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" 287 | dependencies = [ 288 | "proc-macro2", 289 | "quote", 290 | "unicode-ident", 291 | ] 292 | 293 | [[package]] 294 | name = "thiserror" 295 | version = "1.0.50" 296 | source = "registry+https://github.com/rust-lang/crates.io-index" 297 | checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" 298 | dependencies = [ 299 | "thiserror-impl", 300 | ] 301 | 302 | [[package]] 303 | name = "thiserror-impl" 304 | version = "1.0.50" 305 | source = "registry+https://github.com/rust-lang/crates.io-index" 306 | checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" 307 | dependencies = [ 308 | "proc-macro2", 309 | "quote", 310 | "syn", 311 | ] 312 | 313 | [[package]] 314 | name = "tinyvec" 315 | version = "1.6.0" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" 318 | dependencies = [ 319 | "tinyvec_macros", 320 | ] 321 | 322 | [[package]] 323 | name = "tinyvec_macros" 324 | version = "0.1.1" 325 | source = "registry+https://github.com/rust-lang/crates.io-index" 326 | checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" 327 | 328 | [[package]] 329 | name = "tracing" 330 | version = "0.1.40" 331 | source = "registry+https://github.com/rust-lang/crates.io-index" 332 | checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" 333 | dependencies = [ 334 | "log", 335 | "pin-project-lite", 336 | "tracing-attributes", 337 | "tracing-core", 338 | ] 339 | 340 | [[package]] 341 | name = "tracing-attributes" 342 | version = "0.1.27" 343 | source = "registry+https://github.com/rust-lang/crates.io-index" 344 | checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" 345 | dependencies = [ 346 | "proc-macro2", 347 | "quote", 348 | "syn", 349 | ] 350 | 351 | [[package]] 352 | name = "tracing-core" 353 | version = "0.1.32" 354 | source = "registry+https://github.com/rust-lang/crates.io-index" 355 | checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" 356 | dependencies = [ 357 | "once_cell", 358 | ] 359 | 360 | [[package]] 361 | name = "unicode-bidi" 362 | version = "0.3.14" 363 | source = "registry+https://github.com/rust-lang/crates.io-index" 364 | checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" 365 | 366 | [[package]] 367 | name = "unicode-ident" 368 | version = "1.0.12" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 371 | 372 | [[package]] 373 | name = "unicode-normalization" 374 | version = "0.1.22" 375 | source = "registry+https://github.com/rust-lang/crates.io-index" 376 | checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" 377 | dependencies = [ 378 | "tinyvec", 379 | ] 380 | 381 | [[package]] 382 | name = "url" 383 | version = "2.5.0" 384 | source = "registry+https://github.com/rust-lang/crates.io-index" 385 | checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" 386 | dependencies = [ 387 | "form_urlencoded", 388 | "idna", 389 | "percent-encoding", 390 | "serde", 391 | ] 392 | 393 | [[package]] 394 | name = "zip" 395 | version = "0.6.6" 396 | source = "registry+https://github.com/rust-lang/crates.io-index" 397 | checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" 398 | dependencies = [ 399 | "byteorder", 400 | "crc32fast", 401 | "crossbeam-utils", 402 | "flate2", 403 | ] 404 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | edition = "2021" 3 | name = "lapce-copilot" 4 | version = "1.0.0" 5 | resolver = "2" 6 | 7 | [target.'cfg(target_os = "wasi")'.dependencies] 8 | # plugin deps 9 | 10 | # default deps for all lapce plugins 11 | anyhow = "1.0" 12 | serde_json = "1.0" 13 | serde = { version = "1.0", features = ["derive"] } 14 | lapce-plugin = { git = "https://github.com/lapce/lapce-plugin-rust.git" } 15 | # lapce-plugin = { git = "https://github.com/panekj/lapce-plugin-rust.git", branch = "volt" } 16 | zip = { version = "0.6", default-features = false, features = ["deflate"] } 17 | 18 | [patch.crates-io] 19 | # Temporarily patch lsp-types with a version that supports inline-completion 20 | lsp-types = { git = "https://github.com/lapce/lsp-types", rev = "3031a76c4452f46ed265eb0154d6bb1d10ddb9f6" } 21 | 22 | [profile.release] 23 | opt-level = 3 24 | lto = true 25 | codegen-units = 1 26 | strip = true 27 | -------------------------------------------------------------------------------- /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 | # Lapce Copilot 2 | This is an unofficial Copilot plugin for Lapce. 3 | IMPORTANT NOTE: This plugin currently requires nightly Lapce, as the inline completions feature is not yet on stable. 4 | 5 | 6 | ## Installation 7 | Requires: NodeJS 16+ 8 | It will try to find the `node` binary in your path, but you can also change the setting to point to the binary. 9 | 10 | - Open Lapce 11 | - Go to the plugins panel 12 | - Find 'Copilot (Unofficial)' 13 | - Click install 14 | 15 | This will immediately open a browser window to the Github login page with a notification containing a code. Enter that code into the website to authorize Copilot. You shouldn't need to do this again. 16 | 17 | ## Development 18 | Building: 19 | Requires: `rustup target add wasm32-wasi` 20 | 21 | `cargo build --release` 22 | 23 | The plugin file will be located in `target/wasm32-wasi/release/lapce-copilot.wasm` 24 | This can be copied to a folder along with a couple other files: 25 | ```bash 26 | minusgix.lapce-copilot/ 27 | - dist/ 28 | - volt.toml 29 | - lapce-copilot.wasm 30 | ``` 31 | 32 | ### Updating 33 | If Copilot ends up out of date, then it can be updated by copying the `dist/` folder from the [copilot.vim](https://github.com/github/copilot.vim/) repo. That repo contains an agent.js which this plugin starts as the actual core copilot. 34 | 35 | ### Impl Details 36 | This plugin currently: 37 | - Looks for node 38 | - And checks if the `node` version is good 39 | - Tells Lapce to spawn a new Language Server using roughly `[node, agent.js]` 40 | - I'm not sure if it is waiting for copilot to send the initialize response back to Lapce, possibly it should 41 | - The plugin sends to the newly spawned Copilot LSP information about the editor + plugin 42 | - names and versions, but also some configuration 43 | - The plugin asks Copilot if we are signed in 44 | - If we are not, then it does a few more requests to try signing in 45 | - The Copilot LSP currently uses a nonstandard `getCompletions`/`getCompletionsCycling` request. 46 | - I didn't try to implement this in Lapce because it is from a single plugin, and is also of dubious origin since Github doesn't document their own API. 47 | - Lapce implements the 3.18 (upcoming) LSP command `textDocument/inlineCompletion` which serves a similar purpose. 48 | - So the plugin tells Lapce that it supports Inline Completions, and maps those to the Copilot LSP requests and back. 49 | - We also have to listen for onChange/onOpen events, because Copilot wants the `version` of the file to be sent with the request but `textDocument/inlineCompletion` does not include that. 50 | 51 | Once 3.18 is standardized, if Copilot's agent.js implements inlineCompletion then that special-handling can be removed from this extension. 52 | 53 | ## License 54 | The license of the *plugin* is Apache/MIT, but the license of the files in the `dist/` is covered under the [GitHub Terms of Service](https://docs.github.com/en/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot). Possibly the definitions in `copilot.rs` of the RPC commands also falls under Github's license? -------------------------------------------------------------------------------- /dist/README.md: -------------------------------------------------------------------------------- 1 | # Dist/ 2 | This folder holds the distribution files for Copilot. 3 | These are grabbed from https://github.com/github/copilot.vim/tree/release/dist, specifically the: 4 | - `agent.js` 5 | - `agent.js.LICENSE.txt` 6 | - `agent.js.map` 7 | (MORE?) -------------------------------------------------------------------------------- /dist/agent.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * Application Insights JavaScript SDK - Web Snippet, 1.0.1 3 | * Copyright (c) Microsoft and contributors. All rights reserved. 4 | */ 5 | 6 | /*! 7 | * buildToken 8 | * Builds OAuth token prefix (helper function) 9 | * 10 | * @name buildToken 11 | * @function 12 | * @param {GitUrl} obj The parsed Git url object. 13 | * @return {String} token prefix 14 | */ 15 | 16 | /*! 17 | * mime-db 18 | * Copyright(c) 2014 Jonathan Ong 19 | * MIT Licensed 20 | */ 21 | 22 | /*! 23 | * mime-types 24 | * Copyright(c) 2014 Jonathan Ong 25 | * Copyright(c) 2015 Douglas Christopher Wilson 26 | * MIT Licensed 27 | */ 28 | 29 | /** @preserve 30 | * Counter block mode compatible with Dr Brian Gladman fileenc.c 31 | * derived from CryptoJS.mode.CTR 32 | * Jan Hruby jhruby.web@gmail.com 33 | */ 34 | 35 | /** @preserve 36 | (c) 2012 by Cédric Mesnil. All rights reserved. 37 | 38 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 39 | 40 | - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 41 | - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 42 | 43 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | */ 45 | -------------------------------------------------------------------------------- /dist/compiled/darwin/arm64/kerberos.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/compiled/darwin/arm64/kerberos.node -------------------------------------------------------------------------------- /dist/compiled/darwin/x64/kerberos.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/compiled/darwin/x64/kerberos.node -------------------------------------------------------------------------------- /dist/compiled/linux/arm64/kerberos.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/compiled/linux/arm64/kerberos.node -------------------------------------------------------------------------------- /dist/compiled/linux/x64/kerberos.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/compiled/linux/x64/kerberos.node -------------------------------------------------------------------------------- /dist/compiled/win32/x64/kerberos.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/compiled/win32/x64/kerberos.node -------------------------------------------------------------------------------- /dist/crypt32.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/crypt32.node -------------------------------------------------------------------------------- /dist/tree-sitter-go.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/tree-sitter-go.wasm -------------------------------------------------------------------------------- /dist/tree-sitter-javascript.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/tree-sitter-javascript.wasm -------------------------------------------------------------------------------- /dist/tree-sitter-python.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/tree-sitter-python.wasm -------------------------------------------------------------------------------- /dist/tree-sitter-ruby.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/tree-sitter-ruby.wasm -------------------------------------------------------------------------------- /dist/tree-sitter-tsx.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/tree-sitter-tsx.wasm -------------------------------------------------------------------------------- /dist/tree-sitter-typescript.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/tree-sitter-typescript.wasm -------------------------------------------------------------------------------- /dist/tree-sitter.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinusGix/lapce-copilot/6b244612043157beb0f509b7ba16de0b5e7d95f4/dist/tree-sitter.wasm -------------------------------------------------------------------------------- /src/copilot.rs: -------------------------------------------------------------------------------- 1 | use lapce_plugin::psp_types::{ 2 | lsp_types::{Position, Range, Url}, 3 | Notification, Request, 4 | }; 5 | use serde::{Deserialize, Serialize}; 6 | use serde_json::Value; 7 | 8 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] 9 | pub enum Status { 10 | #[serde(rename = "OK")] 11 | Ok, 12 | MaybeOk, 13 | NotSignedIn, 14 | NotAuthorized, 15 | FailedToGetToken, 16 | TokenInvalid, 17 | } 18 | impl Status { 19 | pub fn is_ok(self) -> bool { 20 | self == Status::Ok || self == Status::MaybeOk 21 | } 22 | } 23 | 24 | #[derive(Debug)] 25 | pub enum SetEditorInfo {} 26 | 27 | #[derive(Debug, Serialize, Deserialize)] 28 | #[serde(rename_all = "camelCase")] 29 | pub struct SetEditorInfoParams { 30 | pub editor_info: EditorInfo, 31 | pub editor_plugin_info: EditorPluginInfo, 32 | #[serde(skip_serializing_if = "Option::is_none")] 33 | pub editor_configuration: Option, 34 | #[serde(skip_serializing_if = "Option::is_none")] 35 | pub network_proxy: Option, 36 | #[serde(skip_serializing_if = "Option::is_none")] 37 | pub auth_provider: Option, 38 | #[serde(skip_serializing_if = "Option::is_none")] 39 | pub options: Option, 40 | } 41 | 42 | impl Request for SetEditorInfo { 43 | type Params = SetEditorInfoParams; 44 | 45 | type Result = String; 46 | 47 | // TODO: what is the command to use here?? 48 | const METHOD: &'static str = "setEditorInfo"; 49 | } 50 | 51 | #[derive(Debug, Serialize, Deserialize)] 52 | #[serde(rename_all = "camelCase")] 53 | pub struct EditorInfo { 54 | pub name: String, 55 | pub version: String, 56 | } 57 | 58 | #[derive(Debug, Serialize, Deserialize)] 59 | #[serde(rename_all = "camelCase")] 60 | pub struct EditorPluginInfo { 61 | pub name: String, 62 | pub version: String, 63 | } 64 | 65 | #[derive(Debug, Default, Serialize, Deserialize)] 66 | #[serde(rename_all = "camelCase")] 67 | pub struct EditorConfiguration { 68 | #[serde(skip_serializing_if = "Option::is_none")] 69 | pub show_editor_completions: Option, 70 | #[serde(skip_serializing_if = "Option::is_none")] 71 | pub enable_auto_completions: Option, 72 | #[serde(skip_serializing_if = "Option::is_none")] 73 | pub delay_completions: Option, 74 | #[serde(skip_serializing_if = "Option::is_none")] 75 | pub filter_completions: Option, 76 | #[serde(skip_serializing_if = "Option::is_none")] 77 | pub disabled_languages: Option>, 78 | } 79 | 80 | #[derive(Debug, Default, Serialize, Deserialize)] 81 | pub struct LanguageId { 82 | pub language_ids: Vec, 83 | } 84 | 85 | #[derive(Debug, Serialize, Deserialize)] 86 | #[serde(rename_all = "camelCase")] 87 | pub struct NetworkProxy { 88 | pub host: String, 89 | pub port: u16, 90 | #[serde(skip_serializing_if = "Option::is_none")] 91 | pub username: Option, 92 | #[serde(skip_serializing_if = "Option::is_none")] 93 | pub password: Option, 94 | #[serde(skip_serializing_if = "Option::is_none")] 95 | pub reject_unauthorized: Option, 96 | } 97 | 98 | #[derive(Debug, Serialize, Deserialize)] 99 | #[serde(rename_all = "camelCase")] 100 | pub struct AuthProvider { 101 | #[serde(skip_serializing_if = "Option::is_none")] 102 | pub url: Option, 103 | } 104 | 105 | #[derive(Debug)] 106 | pub enum CheckAuthStatus {} 107 | 108 | #[derive(Debug, Serialize, Deserialize)] 109 | #[serde(rename_all = "camelCase")] 110 | pub struct CheckAuthStatusParams { 111 | #[serde(skip_serializing_if = "Option::is_none")] 112 | pub options: Option, 113 | } 114 | 115 | impl Request for CheckAuthStatus { 116 | type Params = CheckAuthStatusParams; 117 | 118 | type Result = CheckAuthStatusResult; 119 | 120 | const METHOD: &'static str = "checkStatus"; 121 | } 122 | 123 | #[derive(Debug, Default, Serialize, Deserialize)] 124 | #[serde(rename_all = "camelCase")] 125 | pub struct CheckAuthStatusOptions { 126 | #[serde(skip_serializing_if = "Option::is_none")] 127 | pub local_checks_only: Option, 128 | } 129 | 130 | #[derive(Debug, Serialize, Deserialize)] 131 | #[serde(rename_all = "camelCase")] 132 | pub struct CheckAuthStatusResult { 133 | pub status: Status, 134 | /// Github user 135 | pub user: Option, 136 | } 137 | 138 | #[derive(Debug, Serialize, Deserialize)] 139 | pub enum SignInStatus { 140 | AlreadySignedIn, 141 | PromptUserDeviceFlow, 142 | } 143 | 144 | /// Start signing in 145 | /// The user will have to open the verification uri and then enter the user code 146 | #[derive(Debug)] 147 | pub enum SignInInitiate {} 148 | 149 | #[derive(Debug, Serialize, Deserialize)] 150 | #[serde(rename_all = "camelCase")] 151 | pub struct SignInInitiateParams {} 152 | 153 | impl Request for SignInInitiate { 154 | type Params = SignInInitiateParams; 155 | 156 | type Result = SignInInitiateResult; 157 | 158 | const METHOD: &'static str = "signInInitiate"; 159 | } 160 | 161 | #[derive(Debug, Serialize, Deserialize)] 162 | #[serde(rename_all = "camelCase")] 163 | pub struct SignInInitiateResult { 164 | // TODO: could we make this an enum...? 165 | pub status: SignInStatus, 166 | /// Only for [`Status::PromptUserDeviceFlow`] 167 | /// Short string of numbers 168 | pub user_code: Option, 169 | /// Only for [`Status::PromptUserDeviceFlow`] 170 | pub verification_uri: Option, 171 | /// Only for [`Status::PromptUserDeviceFlow`] 172 | pub expires_in: Option, 173 | /// Only for [`Status::PromptUserDeviceFlow`] 174 | pub interval: Option, 175 | 176 | /// Only for [`Status::AlreadySignedIn`] 177 | pub user: Option, 178 | } 179 | 180 | /// Sign in confirm waits until the user has finished interacting to respond 181 | #[derive(Debug)] 182 | pub enum SignInConfirm {} 183 | 184 | #[derive(Debug, Serialize, Deserialize)] 185 | #[serde(rename_all = "camelCase")] 186 | pub struct SignInConfirmParams {} 187 | 188 | impl Request for SignInConfirm { 189 | type Params = SignInConfirmParams; 190 | 191 | type Result = SignInConfirmResult; 192 | 193 | const METHOD: &'static str = "signInConfirm"; 194 | } 195 | 196 | #[derive(Debug, Serialize, Deserialize)] 197 | #[serde(rename_all = "camelCase")] 198 | pub struct SignInConfirmResult { 199 | /// "OK" | ? 200 | pub status: String, 201 | pub user: Option, 202 | } 203 | 204 | #[derive(Debug)] 205 | pub enum SignOut {} 206 | 207 | #[derive(Debug, Serialize, Deserialize)] 208 | pub struct SignOutParams {} 209 | 210 | impl Request for SignOut { 211 | type Params = SignOutParams; 212 | 213 | type Result = SignOutResult; 214 | 215 | const METHOD: &'static str = "signOut"; 216 | } 217 | 218 | #[derive(Debug, Serialize, Deserialize)] 219 | #[serde(rename_all = "camelCase")] 220 | pub struct SignOutResult { 221 | /// "NotSignedin" | ? 222 | pub status: String, 223 | } 224 | 225 | #[derive(Debug)] 226 | pub enum GetCompletions {} 227 | 228 | impl Request for GetCompletions { 229 | type Params = GetCompletionsParams; 230 | 231 | type Result = GetCompletionsResult; 232 | 233 | const METHOD: &'static str = "getCompletions"; 234 | } 235 | 236 | #[derive(Debug)] 237 | pub enum GetCompletionsCycling {} 238 | 239 | impl Request for GetCompletionsCycling { 240 | type Params = GetCompletionsParams; 241 | 242 | type Result = GetCompletionsResult; 243 | 244 | const METHOD: &'static str = "getCompletionsCycling"; 245 | } 246 | 247 | #[derive(Debug, Serialize, Deserialize)] 248 | pub struct GetCompletionsParams { 249 | pub doc: GetCompletionsDoc, 250 | #[serde(skip_serializing_if = "Option::is_none")] 251 | pub options: Option, 252 | } 253 | 254 | #[derive(Debug, Serialize, Deserialize)] 255 | #[serde(rename_all = "camelCase")] 256 | pub struct GetCompletionsDoc { 257 | pub position: Position, 258 | pub uri: Url, 259 | pub version: i32, 260 | /// Whether to insert spaces maybe? 261 | #[serde(skip_serializing_if = "Option::is_none")] 262 | pub insert_spaces: Option, 263 | /// The size of tabs in the document 264 | #[serde(skip_serializing_if = "Option::is_none")] 265 | pub tab_size: Option, 266 | /// ?? 267 | #[serde(skip_serializing_if = "Option::is_none")] 268 | pub source: Option, 269 | #[serde(skip_serializing_if = "Option::is_none")] 270 | pub language_id: Option, 271 | #[serde(skip_serializing_if = "Option::is_none")] 272 | pub relative_path: Option, 273 | #[serde(skip_serializing_if = "Option::is_none")] 274 | pub if_inserted: Option, 275 | } 276 | 277 | #[derive(Debug, Serialize, Deserialize)] 278 | pub struct IfInserted { 279 | pub text: String, 280 | #[serde(skip_serializing_if = "Option::is_none")] 281 | pub end: Option, 282 | } 283 | 284 | #[derive(Debug, Serialize, Deserialize)] 285 | pub struct GetCompletionsResult { 286 | pub completions: Vec, 287 | } 288 | 289 | #[derive(Debug, Serialize, Deserialize)] 290 | #[serde(rename_all = "camelCase")] 291 | pub struct Completion { 292 | pub uuid: String, 293 | /// Full line of text 294 | pub text: String, 295 | pub range: Range, 296 | /// Text after the current cursor position 297 | pub display_text: String, 298 | pub position: Position, 299 | pub doc_version: u64, 300 | } 301 | 302 | /// I think this is supposed to be sent when the completion is shown? 303 | #[derive(Debug)] 304 | pub enum NotifyShown {} 305 | 306 | impl Notification for NotifyShown { 307 | type Params = NotifyShownParams; 308 | 309 | const METHOD: &'static str = "notifyShown"; 310 | } 311 | 312 | #[derive(Debug, Serialize, Deserialize)] 313 | pub struct NotifyShownParams { 314 | pub uuid: String, 315 | #[serde(skip_serializing_if = "Option::is_none")] 316 | pub options: Option, 317 | } 318 | 319 | /// This is supposed to be sent when a completion is accepted 320 | #[derive(Debug)] 321 | pub enum NotifyAccepted {} 322 | 323 | impl Notification for NotifyAccepted { 324 | type Params = NotifyAcceptedParams; 325 | 326 | const METHOD: &'static str = "notifyAccepted"; 327 | } 328 | 329 | #[derive(Debug, Serialize, Deserialize)] 330 | pub struct NotifyAcceptedParams { 331 | pub uuid: String, 332 | #[serde(skip_serializing_if = "Option::is_none")] 333 | pub options: Option, 334 | } 335 | 336 | /// This is supposed to be sent when a completion is rejected 337 | #[derive(Debug)] 338 | pub enum NotifyRejected {} 339 | 340 | impl Notification for NotifyRejected { 341 | type Params = NotifyRejectedParams; 342 | 343 | const METHOD: &'static str = "notifyRejected"; 344 | } 345 | 346 | #[derive(Debug, Serialize, Deserialize)] 347 | pub struct NotifyRejectedParams { 348 | pub uuid: String, 349 | #[serde(skip_serializing_if = "Option::is_none")] 350 | pub options: Option, 351 | } 352 | 353 | #[derive(Debug)] 354 | pub enum Cancel {} 355 | 356 | impl Request for Cancel { 357 | type Params = CancelParams; 358 | 359 | type Result = CancelResult; 360 | 361 | const METHOD: &'static str = "cancel"; 362 | } 363 | 364 | #[derive(Debug, Serialize, Deserialize)] 365 | pub struct CancelParams { 366 | /// Request id 367 | pub id: u64, 368 | } 369 | 370 | #[derive(Debug, Serialize, Deserialize)] 371 | pub struct CancelResult { 372 | // ?? 373 | } 374 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | // Deny usage of print and eprint as it won't have same result 2 | // in WASI as if doing in standard program, you must really know 3 | // what you are doing to disable that lint (and you don't know) 4 | #![deny(clippy::print_stdout)] 5 | #![deny(clippy::print_stderr)] 6 | 7 | use std::{collections::HashMap, fs::File}; 8 | 9 | use anyhow::Result; 10 | use copilot::{ 11 | CheckAuthStatus, CheckAuthStatusParams, CheckAuthStatusResult, EditorConfiguration, EditorInfo, 12 | EditorPluginInfo, GetCompletions, GetCompletionsCycling, GetCompletionsResult, SetEditorInfo, 13 | SetEditorInfoParams, SignInConfirm, SignInConfirmParams, SignInConfirmResult, SignInInitiate, 14 | SignInInitiateParams, SignInInitiateResult, SignInStatus, Status, 15 | }; 16 | 17 | use lapce_plugin::{ 18 | lsp::LspRef, 19 | psp_types::{ 20 | lsp_types::{ 21 | notification::{DidChangeTextDocument, DidOpenTextDocument}, 22 | request::{Initialize, InlineCompletionRequest}, 23 | DidChangeTextDocumentParams, DidOpenTextDocumentParams, DocumentFilter, 24 | DocumentSelector, InitializeParams, InitializeResult, InlineCompletionItem, 25 | InlineCompletionParams, InlineCompletionResponse, InlineCompletionTriggerKind, 26 | InsertTextFormat, MessageType, OneOf, ServerCapabilities, ServerInfo, TextDocumentItem, 27 | TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncOptions, 28 | TextDocumentSyncSaveOptions, Url, VersionedTextDocumentIdentifier, 29 | }, 30 | Notification, Request, 31 | }, 32 | register_plugin, Http, LapcePlugin, VoltEnvironment, PLUGIN_RPC, 33 | }; 34 | 35 | use serde_json::Value; 36 | 37 | pub mod copilot; 38 | 39 | pub const PLUGIN_VERSION: &str = env!("CARGO_PKG_VERSION"); 40 | 41 | #[derive(Default)] 42 | struct State { 43 | pub lsp: Option, 44 | /// Track the latest versions 45 | pub versions: HashMap, 46 | } 47 | impl State { 48 | fn handle_inline_completion(&mut self, id: u64, params: InlineCompletionParams) -> Result<()> { 49 | // PLUGIN_RPC.stderr("Handling Inline Completion"); 50 | let Some(lsp) = self.lsp else { 51 | // PLUGIN_RPC.stderr("No lsp ref"); 52 | return Ok(()); 53 | }; 54 | 55 | let InlineCompletionParams { 56 | text_document_position, 57 | context, 58 | .. 59 | } = params; 60 | 61 | let method = match context.trigger_kind { 62 | InlineCompletionTriggerKind::Automatic => GetCompletions::METHOD, 63 | InlineCompletionTriggerKind::Invoked => GetCompletionsCycling::METHOD, 64 | _ => { 65 | PLUGIN_RPC.stderr(&format!( 66 | "Unsupported trigger kind: {:?}", 67 | context.trigger_kind 68 | )); 69 | return Ok(()); 70 | } 71 | }; 72 | 73 | let version = self 74 | .versions 75 | .get(&text_document_position.text_document.uri) 76 | .copied() 77 | .unwrap_or_else(|| { 78 | PLUGIN_RPC.stderr(&format!( 79 | "No version for uri: {:?}", 80 | text_document_position.text_document.uri 81 | )); 82 | 0 83 | }); 84 | 85 | let params = copilot::GetCompletionsParams { 86 | doc: copilot::GetCompletionsDoc { 87 | position: text_document_position.position, 88 | uri: text_document_position.text_document.uri.clone(), 89 | version, 90 | insert_spaces: None, 91 | tab_size: None, 92 | source: None, 93 | language_id: None, 94 | relative_path: None, 95 | if_inserted: None, 96 | }, 97 | options: None, 98 | }; 99 | 100 | let params = serde_json::to_value(params).unwrap(); 101 | 102 | // PLUGIN_RPC.stderr(&format!( 103 | // "URI: {:?}; VERSION: {:?}; sending to lsp", 104 | // &text_document_position.text_document.uri, version 105 | // )); 106 | let GetCompletionsResult { completions } = lsp.send_request_blocking(method, params)?; 107 | 108 | // PLUGIN_RPC.stderr(&format!("Got completions: {completions:?}")); 109 | 110 | let completions: Vec<_> = completions 111 | .into_iter() 112 | .map(|c| { 113 | InlineCompletionItem { 114 | // TODO: is this correct? 115 | insert_text: c.display_text, 116 | insert_text_format: Some(InsertTextFormat::PLAIN_TEXT), 117 | filter_text: None, 118 | range: None, // TODO 119 | command: None, 120 | } 121 | }) 122 | .collect(); 123 | let params = InlineCompletionResponse::Array(completions); 124 | let params = serde_json::to_value(params).unwrap(); 125 | 126 | // PLUGIN_RPC.stderr("Sending success"); 127 | PLUGIN_RPC.host_success(id, params)?; 128 | 129 | Ok(()) 130 | } 131 | 132 | fn handle_did_change_text_document(&mut self, params: DidChangeTextDocumentParams) { 133 | let DidChangeTextDocumentParams { text_document, .. } = params; 134 | 135 | let VersionedTextDocumentIdentifier { uri, version } = text_document; 136 | 137 | self.versions.insert(uri, version); 138 | } 139 | 140 | fn handle_did_open_text_document(&mut self, params: DidOpenTextDocumentParams) { 141 | let DidOpenTextDocumentParams { text_document, .. } = params; 142 | 143 | let TextDocumentItem { uri, version, .. } = text_document; 144 | 145 | self.versions.insert(uri, version); 146 | } 147 | } 148 | 149 | register_plugin!(State); 150 | 151 | // TODO: Icon in corner for when copilot is doing stuff and whether it is active 152 | // TODO: Copilot generation panel 153 | // TODO: Swap between generations, though that's a Lapce thing 154 | // TODO: Copilot Chat support 155 | // TODO: the other copilot stuff 156 | fn initialize(state: &mut State, params: InitializeParams) -> Result<()> { 157 | PLUGIN_RPC.window_log_message(MessageType::ERROR, "Initializing copilot".to_string())?; 158 | let document_selector: DocumentSelector = vec![DocumentFilter { 159 | language: None, 160 | pattern: Some(String::from("**/*")), 161 | scheme: None, 162 | }]; 163 | 164 | // Download the proper dist files if the path hasn't been manually specified 165 | let agent_path = params 166 | .initialization_options 167 | .as_ref() 168 | .and_then(|options| options.get("agent")) 169 | .and_then(|agent| agent.get("path")) 170 | .and_then(|path| path.as_str()) 171 | .filter(|path| !path.is_empty()); 172 | if agent_path.is_none() { 173 | download_copilot_dist()?; 174 | } 175 | 176 | let agent_path = agent_path.unwrap_or("dist/agent.js"); 177 | 178 | // By default we just try using some global node 179 | let mut node_url = Url::parse("urn:node")?; 180 | let mut node_path = "node"; 181 | if let Some(options) = params.initialization_options.as_ref() { 182 | if let Some(node) = options.get("node") { 183 | if let Some(path) = node.get("path") { 184 | if let Some(path) = path.as_str() { 185 | node_url = Url::parse(&format!("urn:{}", path))?; 186 | node_path = path; 187 | } 188 | } 189 | } 190 | } 191 | 192 | if !check_node_version(node_path.to_string())? { 193 | PLUGIN_RPC.stderr("NODE VERSION WAS BAD OR SOMETHING?"); 194 | return Ok(()); 195 | } 196 | 197 | PLUGIN_RPC.window_log_message( 198 | MessageType::ERROR, 199 | "Everything was fine. Starting LSP".to_string(), 200 | )?; 201 | 202 | let volt_uri = std::env::var("VOLT_URI")?; 203 | let volt_uri = volt_uri.strip_prefix("file://").unwrap_or(&volt_uri); 204 | // PLUGIN_RPC.stderr(&format!("Agent path: {agent_path:?}")); 205 | let agent_path = std::path::Path::new(&volt_uri).join(agent_path); 206 | // PLUGIN_RPC.stderr(&format!("Agent path: {agent_path:?}")); 207 | let args = vec![agent_path.to_string_lossy().to_string()]; 208 | 209 | let lsp = PLUGIN_RPC.start_lsp( 210 | node_url, 211 | args, 212 | document_selector, 213 | params.initialization_options, 214 | )?; 215 | 216 | state.lsp = Some(lsp); 217 | 218 | let resp: String = lsp.send_request_blocking( 219 | SetEditorInfo::METHOD, 220 | SetEditorInfoParams { 221 | editor_info: EditorInfo { 222 | name: "Lapce".to_string(), 223 | version: "0.3.1".to_string(), 224 | }, 225 | editor_plugin_info: EditorPluginInfo { 226 | name: "lapce-copilot".to_string(), 227 | version: PLUGIN_VERSION.to_string(), 228 | }, 229 | editor_configuration: Some(EditorConfiguration { 230 | show_editor_completions: Some(true), 231 | enable_auto_completions: Some(true), 232 | disabled_languages: Some(vec![]), 233 | ..Default::default() 234 | }), 235 | auth_provider: None, 236 | network_proxy: None, 237 | options: None, 238 | }, 239 | )?; 240 | 241 | // PLUGIN_RPC.stderr(&format!("Got response to set editor params: {resp:?}")); 242 | 243 | if resp != "OK" { 244 | PLUGIN_RPC.stderr(&format!( 245 | "RESPONSE TO Copilot's setEditorInfo WAS NOT OK: {resp:?}" 246 | )); 247 | } 248 | 249 | let status: CheckAuthStatusResult = lsp.send_request_blocking( 250 | CheckAuthStatus::METHOD, 251 | CheckAuthStatusParams { options: None }, 252 | )?; 253 | 254 | // PLUGIN_RPC.stderr(&format!("Got auth status: {status:?}")); 255 | 256 | if status.status == Status::Ok { 257 | PLUGIN_RPC 258 | .window_log_message(MessageType::INFO, "Copilot already signed in".to_string())?; 259 | return Ok(()); 260 | 261 | // // Sign out for testing 262 | // let resp: SignOutResult = lsp.send_request_blocking(SignOut::METHOD, SignOutParams {})?; 263 | // PLUGIN_RPC.stderr(&format!("SIGN OUT RESULT: {resp:?}")); 264 | 265 | // let status: CheckAuthStatusResult = lsp.send_request_blocking( 266 | // CheckAuthStatus::METHOD, 267 | // CheckAuthStatusParams { options: None }, 268 | // )?; 269 | 270 | // PLUGIN_RPC.stderr(&format!("AUTH STATUS NEW: {status:?}")); 271 | } 272 | 273 | // Log in 274 | let resp: SignInInitiateResult = 275 | lsp.send_request_blocking(SignInInitiate::METHOD, SignInInitiateParams {})?; 276 | 277 | match resp.status { 278 | SignInStatus::AlreadySignedIn => { 279 | PLUGIN_RPC.window_log_message( 280 | MessageType::WARNING, 281 | "Already signed-in despite checking that..".to_string(), 282 | )?; 283 | return Ok(()); 284 | } 285 | SignInStatus::PromptUserDeviceFlow => { 286 | let Some(verification_uri) = &resp.verification_uri else { 287 | PLUGIN_RPC 288 | .window_log_message(MessageType::ERROR, "No verification uri".to_string())?; 289 | anyhow::bail!("No verification uri: {resp:?}"); 290 | }; 291 | let Some(user_code) = &resp.user_code else { 292 | PLUGIN_RPC.window_log_message( 293 | MessageType::ERROR, 294 | "No user code for sign-in".to_string(), 295 | )?; 296 | anyhow::bail!("No user code: {resp:?}"); 297 | }; 298 | let message = format!("Input this code in the opened browser: {}", user_code); 299 | PLUGIN_RPC.window_show_message(MessageType::INFO, message)?; 300 | 301 | open(verification_uri)?; 302 | } 303 | } 304 | 305 | let _resp: SignInConfirmResult = 306 | lsp.send_request_blocking(SignInConfirm::METHOD, SignInConfirmParams {})?; 307 | 308 | Ok(()) 309 | } 310 | 311 | const GITHUB_URL: &str = "https://github.com/MinusGix/lapce-copilot/archive/refs/heads/master.zip"; 312 | fn download_copilot_dist() -> anyhow::Result<()> { 313 | // We download the dist files from the github repo for this plugin to avoid hosting them in the 314 | // Lapce plugin store 315 | 316 | let mut resp = Http::get(GITHUB_URL)?; 317 | let body = resp.body_read_all()?; 318 | let body = std::io::Cursor::new(body); 319 | 320 | let mut zip = zip::ZipArchive::new(body)?; 321 | 322 | // Create the actual dist folder 323 | std::fs::create_dir_all("dist")?; 324 | 325 | for i in 0..zip.len() { 326 | let mut file = zip.by_index(i)?; 327 | 328 | let Some(path) = file.enclosed_name() else { 329 | continue; 330 | }; 331 | 332 | if !path.starts_with("lapce-copilot-master/dist/") { 333 | continue; 334 | } 335 | 336 | let path = path.strip_prefix("lapce-copilot-master/")?; 337 | 338 | if file.is_dir() { 339 | std::fs::create_dir_all(path)?; 340 | } else { 341 | if let Some(path) = path.parent() { 342 | if !path.exists() { 343 | std::fs::create_dir_all(path)?; 344 | } 345 | } 346 | 347 | let mut out = File::create(path)?; 348 | std::io::copy(&mut file, &mut out)?; 349 | } 350 | } 351 | 352 | Ok(()) 353 | } 354 | 355 | fn open(url: &str) -> anyhow::Result<()> { 356 | let os = VoltEnvironment::operating_system()?; 357 | match os.as_str() { 358 | "linux" | "freebsd" | "netbsd" | "openbsd" | "solaris" | "android" => { 359 | let _ = PLUGIN_RPC.execute_process("xdg-open".to_string(), vec![url.to_string()])?; 360 | } 361 | "macos" => { 362 | let _ = PLUGIN_RPC.execute_process("open".to_string(), vec![url.to_string()])?; 363 | } 364 | "windows" => { 365 | let _ = PLUGIN_RPC.execute_process( 366 | "cmd".to_string(), 367 | vec!["/C".to_string(), "start".to_string(), url.to_string()], 368 | )?; 369 | } 370 | _ => { 371 | let err = format!("Unsupported operating system {os:?} when trying to open {url}, please open it manually."); 372 | PLUGIN_RPC.window_show_message(MessageType::ERROR, err.clone())?; 373 | return Ok(()); 374 | } 375 | } 376 | 377 | Ok(()) 378 | } 379 | 380 | // The Copilot agent.js uses a custom `getCompletions`/`getCompletionsCycle` request for inline 381 | // completions, but we don't want to force Lapce to support the non-standard request. 382 | // 383 | // Thankfully, the 3.18 version of the LSP spec comes with inline completion support - though it is 384 | // not yet finalized. 385 | // What this plugin does then, is start copilot and tell Lapce that the plugin supports inline 386 | // completions. The plugin then translates back and forth between the inline completion request and 387 | // the custom request that copilot expects. 388 | // 389 | // Once Copilot properly supports inlineCompletion requests, this extra code can be removed. 390 | 391 | /// Reply to the initialize request properly 392 | fn reply_initialize(id: u64, _params: &InitializeParams) -> Result<()> { 393 | let message = InitializeResult { 394 | capabilities: ServerCapabilities { 395 | inline_completion_provider: Some(OneOf::Left(true)), 396 | // We don't care about the file contents, but we need to be alerted so that we can 397 | // track the version number for copilot. 398 | text_document_sync: Some(TextDocumentSyncCapability::Options( 399 | TextDocumentSyncOptions { 400 | change: Some(TextDocumentSyncKind::INCREMENTAL), 401 | open_close: Some(true), 402 | save: Some(TextDocumentSyncSaveOptions::Supported(true)), 403 | ..Default::default() 404 | }, 405 | )), 406 | ..Default::default() 407 | }, 408 | server_info: Some(ServerInfo { 409 | name: "lapce-copilot".to_string(), 410 | version: Some(PLUGIN_VERSION.to_string()), 411 | }), 412 | ..Default::default() 413 | }; 414 | 415 | PLUGIN_RPC.host_success(id, message)?; 416 | 417 | Ok(()) 418 | } 419 | 420 | impl LapcePlugin for State { 421 | fn handle_request(&mut self, id: u64, method: String, params: Value) { 422 | match method.as_str() { 423 | Initialize::METHOD => { 424 | let params: InitializeParams = serde_json::from_value(params).unwrap(); 425 | 426 | if let Err(e) = reply_initialize(id, ¶ms) { 427 | let _ = PLUGIN_RPC.window_show_message( 428 | MessageType::ERROR, 429 | format!("plugin reply_initialize returned with error: {e}"), 430 | ); 431 | } 432 | 433 | if let Err(e) = initialize(self, params) { 434 | let _ = PLUGIN_RPC.window_show_message( 435 | MessageType::ERROR, 436 | format!("plugin returned with error: {e}"), 437 | ); 438 | } 439 | } 440 | InlineCompletionRequest::METHOD => { 441 | let params: Result = serde_json::from_value(params); 442 | let params = match params { 443 | Ok(params) => params, 444 | Err(err) => { 445 | PLUGIN_RPC 446 | .stderr(&format!("Failed to parse inline completion params: {err}")); 447 | return; 448 | } 449 | }; 450 | 451 | if let Err(e) = self.handle_inline_completion(id, params) { 452 | PLUGIN_RPC.stderr(&format!("copilot inline completion error: {e}")); 453 | } 454 | } 455 | _ => {} 456 | } 457 | } 458 | 459 | fn handle_notification(&mut self, method: String, params: Value) { 460 | match method.as_str() { 461 | DidChangeTextDocument::METHOD => { 462 | let params: DidChangeTextDocumentParams = serde_json::from_value(params).unwrap(); 463 | 464 | self.handle_did_change_text_document(params); 465 | } 466 | DidOpenTextDocument::METHOD => { 467 | let params: DidOpenTextDocumentParams = serde_json::from_value(params).unwrap(); 468 | 469 | self.handle_did_open_text_document(params); 470 | } 471 | _ => {} 472 | } 473 | } 474 | } 475 | 476 | fn check_node_version(node: String) -> Result { 477 | let node_version = PLUGIN_RPC.execute_process(node, vec!["--version".to_string()]); 478 | match node_version { 479 | Ok(res) => { 480 | if !res.success { 481 | PLUGIN_RPC.window_show_message( 482 | MessageType::ERROR, 483 | "Node.js did not successfully exit.".to_string(), 484 | )?; 485 | PLUGIN_RPC.stderr("Node.js did not successfully exit."); 486 | return Ok(false); 487 | } 488 | 489 | let Some(stdout) = res.stdout else { 490 | let err = "Failed to get stdout when getting Nodejs version".to_string(); 491 | PLUGIN_RPC.window_show_message(MessageType::ERROR, err.clone())?; 492 | PLUGIN_RPC.stderr(&err); 493 | PLUGIN_RPC.window_log_message(MessageType::ERROR, err)?; 494 | return Ok(false); 495 | }; 496 | 497 | // Node's version is typically of the form v16.16.0 498 | let stdout = std::str::from_utf8(&stdout)?; 499 | let stdout = stdout.trim(); 500 | 501 | // Currently we just require >16.0.0 502 | // We just do a kinda hacky strip 503 | let version = stdout.strip_prefix('v').unwrap_or(stdout); 504 | let (version, _) = version.split_once('.').unwrap_or(("", "")); 505 | let Ok(version) = version.parse::() else { 506 | let err = format!("Failed to parse Nodejs version: {:?}", stdout); 507 | PLUGIN_RPC.window_show_message(MessageType::ERROR, err.clone())?; 508 | PLUGIN_RPC.stderr(&err); 509 | PLUGIN_RPC.window_log_message(MessageType::ERROR, err)?; 510 | return Ok(false); 511 | }; 512 | 513 | if version < 16 { 514 | let err = format!( 515 | "Node.js version is too old, we require a minimum of v16: {:?}", 516 | stdout 517 | ); 518 | PLUGIN_RPC.window_show_message(MessageType::ERROR, err.clone())?; 519 | PLUGIN_RPC.stderr(&err); 520 | PLUGIN_RPC.window_log_message(MessageType::ERROR, err)?; 521 | return Ok(false); 522 | } 523 | 524 | Ok(true) 525 | } 526 | Err(err) => { 527 | let err = format!("Node.js failed to start: {}", err); 528 | PLUGIN_RPC.window_show_message(MessageType::ERROR, err.clone())?; 529 | PLUGIN_RPC.stderr(&err); 530 | PLUGIN_RPC.window_log_message(MessageType::ERROR, err)?; 531 | Ok(false) 532 | } 533 | } 534 | } 535 | -------------------------------------------------------------------------------- /volt.toml: -------------------------------------------------------------------------------- 1 | name = "lapce-copilot" 2 | version = "1.0.1" 3 | author = "MinusGix" 4 | display-name = "Copilot (Unofficial)" 5 | description = "Unofficial Github Copilot plugin" 6 | wasm = "lapce-copilot.wasm" 7 | 8 | [activation] 9 | language = ["rust"] 10 | workspace-contains = ["**/*"] 11 | 12 | [config."node.path"] 13 | default = "" 14 | description = "Path to nodejs executable, used to launch Copilot" 15 | 16 | [config."agent.path"] 17 | default = "" 18 | description = "Path to agent.js, used to launch Copilot" 19 | 20 | # TODO: allow providing a custom copilot agent.js 21 | 22 | #[config."lsp.serverPath"] 23 | #default = "" 24 | #description = "Path to custom LSP executable" 25 | 26 | # [config."lsp.serverArgs"] 27 | # default = [] 28 | # description = "" 29 | 30 | # [config."lspSettingArray"] 31 | # default = [] 32 | # description = "" 33 | 34 | # [config."lspSettingString"] 35 | # default = "" 36 | # description = "" 37 | 38 | # [config."lspSettingBool"] 39 | # default = false 40 | # description = "" 41 | --------------------------------------------------------------------------------