GitHub Copilot is starting to produce D code that can almost pass code review

Petar Petar
Mon Apr 4 07:25:02 UTC 2022


On Sunday, 3 April 2022 at 23:25:45 UTC, Walter Bright wrote:
> This is extraordinary!
>
> Can Copilot be used standalone, i.e. not as a plugin to VS?

There are two parts of this feature:

1. The editor extension (plugin)
2. The GH Copilot API

Currently, the are editor extensions for Visual Studio (the big 
Windows-only IDE), Visual Studio Code (the cross-platform, 
Electron and Monaco-powered open-source editor written TypeScript 
/ JavaScript), Jet Brains (they mention only IntelliJ and 
PyCharm) and NeoVim 0.6+ (which a popular fork of Vim).

Note that VS Code for Web (the one that is opened when you press 
dot `.` while browsing a GH repo, or when you simply replace 
`github.com` with `github.dev` in the URL, e.g. 
https://github.dev/dlang/dmd) doesn't yet support Copilot. I 
don't know if that's a technical limitation (e.g. because VS Code 
for Web can't run extensions containing binary components, while 
the normal VS Code can), or whether it was a business decision 
(for now).

For 1 to work, you need to have access to 2, which is currently 
in a free closed beta. Anyone can request access with their GH 
account on the official page: https://copilot.github.com. I don't 
know how exactly they decide who's eligible and how they 
prioritize access to the beta, but my guess is they ought to 
heavily favor older accounts with a big stream of contributions 
(such as yours), than blank recently created accounts. For 
example, I requested access to GH Codespaces Beta almost 
immediately after it was announced, but didn't get access to it 
for more than an year. On the other hand, I think GH Copilot was 
announced at the end of June last year and I got access sometime 
in August, so your mileage may vary.

For now at least, the API is not documented. My guess is that 
they will document it eventually, since the secret sauce is in 
the implementation, not the API schema.

All of these extensions are freely available (so signup 
required), but are closed source (for now?), provided under the 
[gh-beta-tos].

That said, the NeoVim extension is actually distributed via this 
public repo: https://github.com/github/copilot.vim. As you can 
see it consists of two parts:

* Integration with the editor implemented in vimscript (the 
autoload and plugin folders)
* Copilot Agent consisting of:
   * A minified JavaScript file (about 55k LoC after formatting 
with Prettier), which contains the core of the frontend 
implementation
   * Treesitter parsers (compiled to WebAssembly) for Go, 
JavaScript. Python, Ruby and TypeScript. I think Vladimir's work 
could be really valuable here: 
https://github.com/CyberShadow/tree-sitter-d
   * Tokenizer data (Byte Pair Encoding, see [bpe])

---

In summary, even in the current state of affairs, I think it's 
technically possible to create an extension for other editors 
including your Micro Emacs editor, by porting the vimscript part 
of the NeoVim extension and using Node.js to run the JavaScript & 
Web Assembly client-side core. None of this is documented, and 
subject to change, but as far as I can tell, they haven't tried 
to obfuscate the inner workings, as it seems like they didn't 
want to commit to a fully open-source version yet.


[gh-beta-tos]: 
https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#j-beta-previews
[bpe]: 
https://towardsdatascience.com/byte-pair-encoding-subword-based-tokenization-algorithm-77828a70bee0


More information about the Digitalmars-d mailing list