GitHub Copilot in flight
Tags: githubcopilot, development, productivity, javascript
Published: 2021-12-09 15:30:32

---
title: GitHub Copilot in flight
published: true
description: GitHub Copilot in flight
tags: GitHubCopilot,Development,Productivity,JavaScript
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b63rfy2e2wbo06wfwfxf.jpg
canonical_url: https://medium.com/@arsen.ali/github-copilot-in-flight-2d5bba8d16c
---

## GitHub Copilot in flight

---

### GitHub Copilot?
If you haven't heard about [GitHub Copilot](https://copilot.github.com) yet, it is an AI-powered code assistant which can suggest whole lines and entire functions of code inside your favorite IDE.

---

### Copilot in flight

Just when I started to create a [simple compiler](https://github.com/arszen123/calculator) in TypeScript, I got access to GitHub Copilot. I got excited and instantly integrated it into VSCode and started using it. My first thought was it will only slow me down because I have to interpret and correct every single line of code it suggests. Soon I realized it made the development faster than I could have imagined.

The first thing I tried is to make Copilot suggest me a complete implementation of a [CircularBuffer](https://en.wikipedia.org/wiki/Circular_buffer) utility class. But it only suggested a simple Buffer class, which implementation was incorrect and I had to fix it manually.

Probably this was a bigger challenge for it, so I decided to only use it for smaller tasks like function implementations and unit test writing. In the beginning, it still suggested some irrelevant and incorrect code, but as the project grew the suggestion got better.

My experience is that it adapts to the developer/project, so you can't trust it 100% (as it is [noted on their website](https://copilot.github.com/#faq-does-github-copilot-write-perfect-code)). For example, at first, I started writing unit tests like this:

{% gist https://gist.github.com/arszen123/683007823a3ab7cb0dcfe5f5c2559e43 %}

And soon it started suggesting similar code. Imagine a test case where I want to test a more complex expression, like this: `10 * (4 + 16) / 10`. It would be messy, and unreadable. So I refactored the test cases to assert the generated syntax tree.

{% gist https://gist.github.com/arszen123/f15070ebbe43b010359bf0762264e43d %}

You can see that it's much easier to read this test case than the previous one. Copilot quickly adapted to this and started suggesting relevant code, to make the development faster.

Another example is when I wanted to parse a simple expression with a single function call for the first time.

![Simple function call test case suggested by Copilot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31sydo281ppywhc357zu.jpg)

At first sight, this code suggestion looks good, but it does not fit entirely well into my project. First, there is no `CallNode`, only a `FunctionCallNode` (It was defined before I started writing this test case). Also, the node first parameter should be a token and not another node. You can see a possible implementation below.

{% gist https://gist.github.com/arszen123/687314fe59c2a419a1383e33602e681e %}

After this test case was implemented, Copilot started suggesting correct implementations for similar test cases. Below is a nested function call test case suggested by Copilot.

![Nested function call](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/107x6v8wve75fi9nkehw.jpg)

---

I also tried to observe Copilot during the core components implementation. So, I gave it a task to suggest a function call parser, and to my surprise, it suggested a nice code snippet.

![Function call parser by Copilot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7934ql70h35xvubhvsqu.jpg)

But there is some problem with the above code,

1. It should create a new `FunctionCallNode` and not a `VarNode` ,
2. If the current token is not a function identifier, it should forward the control and try to parse an expression,
3. The parsed function must have one and only one parameter, and it is a big limitation.

{% gist https://gist.github.com/arszen123/358f01a51678ac601d51588f106466ac %}

As you can see in the above implementation the previously mentioned errors are fixed and the parsed function calls can have zero or more parameters.

---

### Conclusion

For me, Copilot was very helpful for some tedious work, especially when I had to write almost the same code over and over (ex. token definitions, specific node types), and it was also very useful for writing unit tests. For the core components implementation, I mostly used it as an autocomplete to type faster, and not as an assistant who suggests whole implementations.

In my opinion, Copilot adapts to the project/developer, therefore it does not make anyone a better developer, but it can make a good developer faster. We still have to understand the suggested code and correct any mistake it makes, but it looks very promising.

---

Thank you for reading my first ever article, I hope you enjoyed it.