Boosting Productivity with GitHub Copilot in VS Code

GitHub Copilot is an AI-powered coding assistant developed by GitHub and OpenAI. It helps you write code faster by suggesting lines or blocks of code based on your context. Think of Copilot in VS Code as a smart pair programmer that works right inside your editor.

What is GitHub Copilot

Copilot in VS Code helps you write code faster by suggesting lines or blocks of code based on your context. It’s like a smart pair programmer that anticipates your next move.

Setting Up Copilot in VS Code

Step 1: Install the Extension

  • Open VS Code.
  • Go to the Extensions tab (Ctrl+Shift+X).
  • Search for GitHub Copilot and click Install.
image of Installing GitHub Copilot in VS Code
Fig 1: Installing GitHub Copilot in VS Code

Step 2: Sign In

  • Authenticate with your GitHub account.
  • Enable inline suggestions.

Step 3: Configure Settings

  • Go to VS Code settings (Ctrl+,).
  • Search for Copilot in VS Code to tweak how suggestions appear.

How I Use Copilot Efficiently

Code Autocompletion (Boilerplate)

Copilot in VS Code predicts and completes code as you type. For example, when I start writing a React component or a Node.js API route, it often fills in the rest.

// Calculate sum

function sum(a, b) {

  return a + b;

}

Copilot can suggest the entire function after you type the comment or function name.

Function/Logic Suggestions

If I write a function signature or a comment describing what I want, Copilot in VS Code suggests the logic. This is super helpful for repetitive tasks.

// Validate user input

function validateInput(input) {

  if (!input) return false;

  // more validation logic...

}

Comment-to-Code (Docstrings)

Writing a comment like // Get all users from database and pressing Tab often gives me the full code block. It’s like magic for boilerplate code.

// Get all users from database

const users = await db.getUsers();

Test Case Generation

Copilot in VS Code can generate unit tests if you write a comment like // Write tests for the addUser function. This saves a lot of time, especially for basic test cases.

// Jest test for add function

test('adds 1 + 2 to equal 3', () => {

  expect(add(1, 2)).toBe(3);

});

Refactoring Help

If I want to refactor a function, I just write a comment like // Refactor to use async/await, and Copilot suggests the updated code.

// Refactor to use async/await

async function fetchData() {

  try {

    const res = await fetch(url);

    const data = await res.json();

    return data;

  } catch (err) {

    console.error(err);

  }

}

Boost Your Coding Speed with Copilot in VS Code Today.

Copilot Chat & Inline Chat

With Copilot in VS Code, you can ask questions right inside your editor. For example:

  • “What does this function do?”
  • “Can you optimize this code?”
  • “Write a test for this function.”

Just select the code, right-click, and choose Ask Copilot.

Copilot Agent & Ask Mode

The Agent acts like a smart assistant that can perform tasks like refactoring, explaining code, or even running commands. Ask Mode is where you type natural language queries and Copilot in VS Code responds with code or actions.

Example:
Ask: “Convert this JavaScript function to TypeScript.”
Copilot provides the converted code.

Prompt Files & Custom Instructions

You can guide Copilot in VS Code using prompt files (.copilot folder). For example, you can set rules for code style or add project-specific instructions. This helps keep code consistent across the team.

Example:
Add a prompt file to enforce using arrow functions or a specific comment style.

Best Practices I Follow

  • Accept vs Edit Suggestions: Don’t just accept everything. Edit suggestions to fit your style and project needs.
  • Write Meaningful Prompts: The more specific your comments, the better Copilot in VS Code performs.
  • Treat Copilot as a Pair Programmer: It’s a helper, not a replacement. Always review the code.
  • Review for Correctness & Security: Sometimes Copilot suggests outdated or insecure code. Always double-check.

Efficiency Gains

  • Faster prototyping and debugging
  • More tests written in less time
  • Less time spent on boilerplate

Limitations & Cautions

  • Sometimes Copilot in VS Code suggests incorrect or outdated code.
  • Manual review is always needed.
  • Be careful with sensitive data and licensing.
coma

Conclusion

GitHub Copilot in VS Code has made my workflow smoother and faster. Try Copilot Chat, define team prompts, and measure your outcomes.

Nadeem K

Associate Software Engineer

Nadeem is a front-end developer with 1.5+ years of experience. He has experience in web technologies like React.js, Redux, and UI frameworks. His expertise in building interactive and responsive web applications, creating reusable components, and writing efficient, optimized, and DRY code. He enjoys learning about new technologies.

Keep Reading

Let’s Transform
Healthcare,
Together.

Partner with us to design, build, and scale digital solutions that drive better outcomes.

Contact form