Duration: 45 minutes (15 min demo + 30 min hands-on)
Format: Demo + Hands-on
By the end of this module, you will be able to:
- Receive and accept inline code suggestions using Tab, partial accept, and next edit suggestions
- Write effective comment-driven prompts that produce accurate code completions
- Navigate alternative suggestions and understand when to accept, modify, or reject them
- Apply Copilot code suggestions to real enterprise tasks: CRUD operations, data transformations, and boilerplate reduction
GitHub Copilot provides autocomplete-style code suggestions as you type. Suggestions appear as grayed-out "ghost text" in your editor.
Copilot generates suggestions from:
- Code context: The code already in your file and open tabs
- Comments: Natural language descriptions of what you want to build
- Function signatures: Method names and parameter types hint at intended behavior
| Action | macOS | Windows/Linux |
|---|---|---|
| Accept full suggestion | Tab |
Tab |
| Accept next word | ⌘ → |
Ctrl → |
| Accept next line | Custom keybind | Custom keybind |
| Next suggestion | ⌥ ] |
Alt ] |
| Previous suggestion | ⌥ [ |
Alt [ |
| Show all suggestions in panel | Ctrl Enter |
Ctrl Enter |
| Dismiss suggestion | Esc |
Esc |
Copilot can predict where your next edit will be and suggest a completion for it. Look for the arrow indicator in the gutter - press Tab to navigate to it, then Tab again to accept the suggestion.
Writing descriptive comments before code is one of the most effective ways to get high-quality suggestions.
// Calculate the number of business days between two dates
// excluding weekends (Saturday and Sunday) and an optional
// array of holiday dates
function calculateBusinessDays(startDate, endDate, holidays = []) {
// Copilot will suggest the implementation here
}/**
* Calculates the number of business days between two dates,
* excluding weekends (Saturday and Sunday) and an optional
* list of holiday dates.
*
* @param startDate the start date (inclusive)
* @param endDate the end date (inclusive)
* @param holidays list of holiday dates to exclude
* @return the number of business days
*/
public static long calculateBusinessDays(LocalDate startDate, LocalDate endDate, List<LocalDate> holidays) {
// Copilot will suggest the implementation here
}| Tip | Example |
|---|---|
| Be specific about inputs/outputs | // Parse a CSV string into a list of Employee objects with name, department, and salary fields |
| Mention edge cases | // Handle null inputs by returning an empty list |
| Reference enterprise patterns | // Use the repository pattern to fetch orders from the database |
| Specify error handling | // Throw IllegalArgumentException if the date range is invalid |
// Convert a UserEntity JPA entity to a UserDTO
// Map all fields including nested Address entity to AddressDTO
// Null-safe: return null if entity is null
public static UserDTO toDTO(UserEntity entity) {
// Copilot suggests the full mapping
}// Create a standardized API response envelope
// with status, data, message, and timestamp fields
// following the enterprise API response format
function createApiResponse(status, data, message) {
// Copilot suggests the response structure
}Open exercises/orderService.js and use Copilot to complete the functions.
Goals:
- Let Copilot generate implementations from the comments
- Practice accepting, rejecting, and navigating between suggestions
- Use partial accept (
⌘ →) to take a suggestion word by word
Open exercises/OrderService.java and use Copilot to complete the methods.
Goals:
- Use Copilot to implement enterprise patterns like validation, filtering, and aggregation
- Observe how Copilot uses Java type information to provide better suggestions
- Practice showing alternative suggestions with
⌥ ]/⌥ [
Open a new file and write the following comment, then let Copilot generate the code:
JavaScript:
// Express.js REST controller for a Product resource
// with CRUD endpoints: GET all, GET by id, POST, PUT, DELETE
// Include input validation and error handling middleware
// Use async/await patternJava:
/**
* Spring Boot REST controller for a Product resource.
* CRUD endpoints: GET all, GET by id, POST, PUT, DELETE.
* Include request validation with @Valid annotation.
* Use ResponseEntity for proper HTTP status codes.
*/- Copilot is a pair programmer, not autopilot: Always review suggestions before accepting
- Better context = better suggestions: Descriptive comments, type hints, and existing code all improve completion quality
- Partial acceptance is powerful: Use
⌘ →to accept word-by-word when a suggestion is mostly right - Next Edit Suggestions save navigation time: Let Copilot predict where you need to edit next
- Enterprise patterns are well-supported: DTOs, repository patterns, API envelopes, and validation logic all generate reliably