Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VS Code + GitHub Copilot Tutorial

This tutorial helps you set up and use GitHub Copilot in VS Code to write, refactor, test, and document code faster.

1) Prerequisites

  • A GitHub account with Copilot access
  • Visual Studio Code (latest recommended)
  • Internet connection

2) Install Copilot in VS Code

  1. Open VS Code.
  2. Go to Extensions (Cmd+Shift+X on macOS / Ctrl+Shift+X on Windows/Linux).
  3. Search for and install:
    • GitHub Copilot
    • GitHub Copilot Chat
  4. Sign in to GitHub when prompted.

3) Verify Copilot Is Working

  • Open any project file (for example, .js, .py, or .ts).
  • Start typing a function.
  • If Copilot suggests ghost text inline, it is active.
  • Press:
    • Tab to accept suggestion
    • Esc to dismiss

4) Core Workflows

A. Inline Code Completion

Use for fast coding while typing:

  1. Write a clear function name and comment.
  2. Pause briefly for suggestions.
  3. Accept full (Tab) or keep typing to refine.

Example comment:

# Parse a CSV file and return rows grouped by country

B. Copilot Chat (In-Editor Assistant)

Use for explanations, refactors, and generation:

  1. Open Chat panel (Copilot icon in the sidebar).
  2. Ask focused prompts such as:
    • “Explain this function in plain language.”
    • “Refactor this to reduce duplication.”
    • “Write unit tests for this file using pytest.”
  3. Review generated code before applying.

C. Edit/Rewrite With Context

  1. Select code block.
  2. Open Copilot Chat.
  3. Prompt with intent + constraints:
    • “Rewrite this to be async, keep the same behavior, and preserve function names.”

5) Prompting Tips (High Impact)

  • Be specific about:
    • language/framework
    • desired output format
    • constraints (performance, style, compatibility)
  • Provide context files or snippets when possible.
  • Ask for step-by-step changes for safer refactors.

Good prompt template:

You are helping with a <language> project.
Task: <what to build/change>
Constraints: <rules, versions, style>
Output: <code/tests/explanation>

6) Practical Tutorial Exercise

Try this mini-project:

  1. Create calculator.py.
  2. Prompt Copilot:
    • “Create a Calculator class with add, subtract, multiply, divide methods and type hints.”
  3. Prompt Copilot Chat:
    • “Generate pytest tests for edge cases, including divide by zero.”
  4. Prompt Copilot Chat:
    • “Refactor for readability without changing behavior.”

You will practice generation, testing, and refactoring in one flow.

7) Best Practices

  • Treat Copilot output as a draft, not final truth.
  • Run tests and linters after accepting suggestions.
  • Check security-sensitive code carefully (auth, SQL, shell commands).
  • Prefer smaller prompts for precise edits.

8) Quarto Website Project (workflowr-like for Python)

This workspace now includes a Quarto website scaffold that mimics workflowr-style practice:

  • source analysis files in analysis/
  • reproducible execution with quarto render
  • publishable static output in docs/

Project Files

  • _quarto.yml: Quarto project and website configuration
  • index.qmd: Website home page
  • analysis/index.qmd: Analysis listing page
  • analysis/01-data-check.qmd: Starter Python analysis report

Local Setup

  1. Install Quarto: https://quarto.org/docs/get-started/
  2. Create and activate a Python environment.
  3. Install dependencies:
pip install -r requirements.txt
  1. Render site:
quarto render

Rendered pages are written to docs/.

Publish

  1. Run:
quarto render
  1. Commit and push the rendered docs/ directory.
  2. In GitHub repository settings, open Pages and set:
    • Source: Deploy from a branch
    • Branch: main
    • Folder: /docs

9) Troubleshooting

  • No suggestions:
    • Check GitHub sign-in status in VS Code.
    • Ensure Copilot extensions are enabled.
    • Reload VS Code window.
  • Poor suggestions:
    • Add more context and constraints.
    • Break tasks into smaller prompts.
  • Slow responses:
    • Check internet connection and retry.

10) Next Steps

  • Add project-specific prompt recipes to your team docs.
  • Use Copilot to scaffold tests first, then implementation.
  • Pair Copilot with CI checks for safe, fast iteration.

If you want, I can also generate a short version of this README for workshop handouts, or a team version with coding standards and review checklist.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages