DEV Community

Cover image for How to Write Code 4X Faster with GitHub Copilot in VS Code
Ramkumar M N
Ramkumar M N

Posted on

How to Write Code 4X Faster with GitHub Copilot in VS Code

"AI won’t replace engineers. Engineers who use AI will replace those who don’t."

Introduction

GitHub Copilot is an AI-powered code completion tool that helps developers write code faster and more efficiently. Integrated with Visual Studio Code (VS Code), Copilot suggests entire lines or blocks of code based on context, significantly reducing development time. In this blog, we'll cover how to set up GitHub Copilot in VS Code, how to use it effectively, and how it can drastically enhance a developer's productivity.

Setting Up GitHub Copilot in VS Code

Step 1: Install GitHub Copilot Extension

  1. Open VS Code and navigate to the Extensions Marketplace (Ctrl+Shift+X).
  2. Search for GitHub Copilot.
  3. Click Install.

Image description

Step 2: Enable GitHub Copilot

  1. Open VS Code Settings (Ctrl+,).
  2. Search for GitHub Copilot and ensure it is enabled.
  3. Sign in to your GitHub account and authorize GitHub Copilot if prompted.

Image description

Step 3: Configure GitHub Copilot

  • In VS Code, go to Settings > GitHub Copilot and adjust preferences such as inline suggestions and accepted file types.

Image description

How to Use GitHub Copilot

Once installed and configured, using GitHub Copilot is simple. Start typing in any programming file, and Copilot will provide auto-suggestions.

Example: Creating a Blockchain API

I created a simple server.js file using Node.js and Express, defining a blockchain implementation:

Image description

Generating Test Cases with Copilot

To verify the functionality of our blockchain API, we need test cases. Instead of writing them manually, I let Copilot generate a server.test.js file automatically, making the process effortless.

Image description

Image description

const request = require("supertest");
const app = require("./server");

describe("Blockchain API", () => {
  it("should return the blockchain", async () => {
    const response = await request(app).get("/blocks");
    expect(response.status).toBe(200);
    expect(response.body).toBeInstanceOf(Array);
    expect(response.body.length).toBeGreaterThan(0);
    expect(response.body[0]).toHaveProperty("index", 0);
    expect(response.body[0]).toHaveProperty("data", "Genesis Block");
  });

  it("should mine a new block", async () => {
    const data = "Test Block";
    const response = await request(app).post("/mine").send({ data });
    expect(response.status).toBe(200);
    expect(response.body).toHaveProperty("index");
    expect(response.body).toHaveProperty("previousHash");
    expect(response.body).toHaveProperty("timestamp");
    expect(response.body).toHaveProperty("data", data);
    expect(response.body).toHaveProperty("hash");
    expect(response.body).toHaveProperty("nonce");
  });

  it("should add the new block to the blockchain", async () => {
    const data = "Another Test Block";
    await request(app).post("/mine").send({ data });
    const response = await request(app).get("/blocks");
    expect(response.status).toBe(200);
    expect(response.body).toBeInstanceOf(Array);
    expect(response.body.length).toBeGreaterThan(1);
    expect(response.body[response.body.length - 1]).toHaveProperty("data", data);
  });
});
Enter fullscreen mode Exit fullscreen mode

Maximizing Copilot's Accuracy

To improve Copilot’s suggestions, you can provide it with more context by attaching multiple file references. This helps generate better results when working on complex applications.

Image description

Example:

If you reference both server.js and server.test.js, Copilot can:

  • Understand existing function structures.
  • Suggest more relevant test cases.
  • Generate related APIs with improved accuracy.

Image description

Image description

Time Savings with GitHub Copilot

Using GitHub Copilot, I:

  • Created an API in minutes instead of hours.
  • Generated test cases instantly without manual effort.
  • Added new APIs seamlessly, reducing development time significantly.

Estimated Time Savings:

Task Without Copilot With Copilot
Writing API code ~2 hours ~30 minutes
Writing test cases ~1 hour ~10 minutes
Expanding functionality ~1 hour ~15 minutes
Total Time Saved ~4 hours ~55 minutes

Here’s the additional content you requested. You can copy and paste it into the appropriate sections of your original blog post.

Insights on GitHub Copilot

  • The time savings mentioned in this article are based on actual development efforts. Compared to similar previous projects, GitHub Copilot significantly reduced the time required to write and test code.

  • GitHub Copilot provides more accurate results when you attach relevant files while prompting it in the chat. Providing context helps it understand function definitions, dependencies, and existing logic.

  • I use GitHub Copilot daily for development, primarily working with React.js, Node.js, and Python. My productivity has increased drastically, allowing me to focus on problem-solving rather than repetitive coding tasks.

  • I realized the full potential of Copilot when writing test cases for a legacy codebase. It helped me understand the logic of existing code quickly and generated meaningful test cases. As I continued working, its suggestions improved progressively.

  • If you're a web developer working with React.js, Node.js, and Python, GitHub Copilot will save tons of development time, making your workflow much smoother and more efficient.

Conclusion

GitHub Copilot is a game-changer for developers, reducing coding time and making development more efficient. By integrating Copilot with VS Code, you can accelerate development, improve code quality, and focus on more complex tasks.

🏆 The Future of AI-Assisted Coding

GitHub Copilot isn’t replacing developers—it’s empowering them! 🚀

"AI won’t replace engineers. Engineers who use AI will replace those who don’t."

✅ If you haven’t tried GitHub Copilot yet, install it today and experience the future of AI-assisted coding!

Follow for more updates!

Useful Resources:

Top comments (13)

Collapse
 
fm profile image
Fayaz

I regularly use GitHub copilot paid version, along with Copilot CLI and VSCode Insiders, so that I can play with the cutting edge improvements.

In my experience, AI code assistants like GitHub Copilot, Cursor, Windsurf etc. works pretty well when the context length is small and you know exactly what you are doing.

Which means, if you give it too much code to work with, or if you ask for something you yourself have no idea of, then it starts messing up after a point, without you ever realizing where it all went irreversibly wrong.

Also, there are some other observations I have that didn't change yet from the time of writing the following post: State of generative AI in Software Development: The reality check!

I think you'll find my observations interesting.

Collapse
 
ramkumar-m-n profile image
Ramkumar M N

Hi Fayaz,
Thanks for sharing your experience! I completely agree, AI code assistants work best with a well-defined context, but when dealing with larger code-bases or unfamiliar territory, things can go off track quickly.

From my experience, I always ask for improvements in small code blocks or functions. For REST APIs, I create a few myself first and then ask Copilot to generate the rest based on the existing code. Providing references to one or two files works well since it doesn’t require Copilot to infer too much.

However, where it struggles is in generating custom business logic or creating entirely new files/modules based on the existing code-base it often lags or produces inaccurate results.
I think we need to use Copilot the way a developer thinks writing one function at a time or iteratively building on existing code.

Appreciate your insights, and I’d love to check out your post on the state of generative AI in software development and let you know my insights.

Regards,
Ram

Collapse
 
fm profile image
Fayaz

Thanks!

BTW, wrote a related post just now: dev.to/fm/poll-on-ai-code-generati...

Please check it out if you get time! ♥️

Thread Thread
 
ramkumar-m-n profile image
Ramkumar M N

Sure.

Collapse
 
chrdek profile image
chrdek • Edited

If you need to add something specific to one of your current github repos then I think is better to use from the online account while on the github website.

The recommendations of the online copilot target the repos and account information directly and if required, account info is included directly- in the suggestions.

Not sure if the VS Code extension works exactly the same though.

Collapse
 
ramkumar-m-n profile image
Ramkumar M N

Hi Chrdek,
Good point, You’re right!
The VS Code extension doesn’t offer the same level of awareness as the GitHub website. Using Copilot directly on GitHub might be useful for vulnerability fixes, but creating new code could be more challenging.

repository-wide context, the GitHub website may have an edge. Build this level of intelligence within extensions with untracked file or code-changes could be difficult.

Thanks for highlighting this! It’s definitely an area that could be improved.

Regards,
Ram

Collapse
 
chrdek profile image
chrdek

Yep, thanks for the confirmation. Was wondering if it was worthwhile to include in my VS Code extensions as well and also meant to confirm this beforehand. So the entire context of github is not used with the full set of info of VS Code, but only for specified recommendations.
Will try it though just to be sure.
It is useful when you need to quickly make for example a pre-made .yaml or terraform file for your project for direct online deployment so you can directly set it up on your cloud account.

Good article, and also good luck with your code.

Thread Thread
 
ramkumar-m-n profile image
Ramkumar M N

Thank you Chrdek ! Glad you found my article useful :) . I will keep you posted my upcoming posts on blockchain development and how Copilot helps me write code.

Regards,
Ram

Collapse
 
jwp profile image
JWP

Agreed. One of the challenges I see is this. It allows one to go deep, really deep quickly. That has its own quirks. The deeper we go, the less we are subject matter experts.

Just today writing a VSCode extension, it took me via discovering things I did know like the Output Channel. It introduced me to how it's set up, configured and used as a logging tool. That part was great!

The part that wasn't so great is it didn't work. I reported the same failure at least 30 times and it was never able to get it right. This leaves me to try again tomorrow. However, the progress was stuck for 4 hours trying to get a logging channel going.

I would have never accidentally discovered the output channel. Rather becoming a SME in VSCode plug ins would have been the normal faire. Subject Matter Expertise takes about 1 year. So, I brushed up to things in 4 hours which was still great.

The other issues I have with it are hallucinations, and its current lack of reading in changes before making suggestions. If a person doesn't realize that is happening, they'll lose their mind saying, "I thought I changed that". But here's the catch, even when you set new rules to stop that kind of thing, it seems to forget those rules throughout the session. It's like banging our head against the wall.

Collapse
 
ramkumar-m-n profile image
Ramkumar M N

Hi JWP,
Thank you for sharing your insights!

You’ve perfectly captured both the power and the quirks of extensions. It’s amazing how it accelerates learning and exploration, but as you pointed out, the hallucinations and lack of context awareness can be frustrating.

Your experience with the VS Code Output Channel is a great example of both sides of the coin.
Hopefully, as the tool evolves, it will become more reliable in handling iterative changes.

Appreciate your thoughtful perspective!

Regards,
Ram

Collapse
 
ramkumar-m-n profile image
Ramkumar M N

🚀 Exciting Update! 🚀

Hi Devs,
I’ve just published a new blog on setting up your own AI agent using Fetch.ai uAgents. I created the source code with the help of GitHub Copilot, making it easier and faster to build intelligent agents.

If you’re interested in AI-powered automation, check it out here:

🔗 Set Up Your Own AI Agent in Minutes: Clone, Run, Deploy
Read More

Would love to hear your thoughts and feedback! Let me know what you think in the comments.

This keeps it engaging while highlighting Copilot’s role. Let me know if you need any changes!

Regards,
Ram

Collapse
 
nikhilroy2 profile image
Nikhil Chandra Roy

One question remains, will it collect secret data for large projects?
I see that many code editors already have this type of feature as a default, like Windsurf, Trae, and more.

Collapse
 
ramkumar-m-n profile image
Ramkumar M N • Edited

Hi Nikhil,
That's a great question! I hadn't thought of mentioning about it when I wrote the article, and I appreciate you bringing it up at the right time.

We need to disable telemetry either for the entire editor (VS Code telemetry) or specifically for GitHub Copilot. Attaching both options.

Disable VS code telemetry

  • Go to settings
  • Type 'telemetry'
  • Select Telemetry under Application
  • On the bottom you can see the below option. select off
Note: If this setting is 'off', no telemetry will be sent regardless of other telemetry settings. If this setting is set to anything except 'off' and telemetry is disabled with deprecated settings, no telemetry will be sent.
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Disable GitHub copilot telemetry

  • Go to Settings
  • Search copilot
  • On the bottom you can see Github copilot Advance -click on it, it will open a JSON file
  • Mark "telemetry.telemetryLevel" as off
  "telemetry.telemetryLevel": "off", // latest
   or
  "telemetry.enableTelemetry": false, // old, Deprecated
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Finally restart the editor. Hope this will work

  • As per the documentation and reference
  • No explicit collection of secrets from Copilot
  • Copilot does not intentionally collect sensitive data.

But if you accidentally include secrets (like API keys) in your code, it might process them. So it could take the sensitive data

Regards,
Ram