/lapce-copilot

An unofficial Github Copilot extension for Lapce

Primary LanguageRustApache License 2.0Apache-2.0

Lapce Copilot

This is an unofficial Copilot plugin for Lapce.
IMPORTANT NOTE: This plugin currently requires nightly Lapce, as the inline completions feature is not yet on stable.

Installation

Requires: NodeJS 16+ It will try to find the node binary in your path, but you can also change the setting to point to the binary.

  • Open Lapce
  • Go to the plugins panel
  • Find 'Copilot (Unofficial)'
  • Click install

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.

Development

Building:
Requires: rustup target add wasm32-wasi

cargo build --release

The plugin file will be located in target/wasm32-wasi/release/lapce-copilot.wasm
This can be copied to a folder along with a couple other files:

minusgix.lapce-copilot/
  - dist/
  - volt.toml
  - lapce-copilot.wasm

Updating

If Copilot ends up out of date, then it can be updated by copying the dist/ folder from the copilot.vim repo. That repo contains an agent.js which this plugin starts as the actual core copilot.

Impl Details

This plugin currently:

  • Looks for node
    • And checks if the node version is good
  • Tells Lapce to spawn a new Language Server using roughly [node, agent.js]
    • I'm not sure if it is waiting for copilot to send the initialize response back to Lapce, possibly it should
  • The plugin sends to the newly spawned Copilot LSP information about the editor + plugin
    • names and versions, but also some configuration
  • The plugin asks Copilot if we are signed in
    • If we are not, then it does a few more requests to try signing in
  • The Copilot LSP currently uses a nonstandard getCompletions/getCompletionsCycling request.
    • 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.
    • Lapce implements the 3.18 (upcoming) LSP command textDocument/inlineCompletion which serves a similar purpose.
    • So the plugin tells Lapce that it supports Inline Completions, and maps those to the Copilot LSP requests and back.
    • 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.

Once 3.18 is standardized, if Copilot's agent.js implements inlineCompletion then that special-handling can be removed from this extension.

License

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. Possibly the definitions in copilot.rs of the RPC commands also falls under Github's license?