Demonstrates GitHub Copilot’s multiple suggestions feature, how to open and cycle alternatives, inspect completions, and choose implementations to improve code quality and developer productivity.
In this lesson we’ll explore GitHub Copilot’s “multiple suggestions” feature: how to open the multi-suggestion panel, how to inspect alternate completions, and when to use it to improve code quality and developer productivity.
This feature surfaces several AI-generated completions for the same cursor context so you can pick the one that best fits your performance, readability, or style preferences. Each suggestion can represent a different algorithmic approach, a more concise expression, or a more explicit implementation — letting you choose instead of accepting the first result.How to open the multiple suggestions panel:
Windows / Linux: Alt+]
macOS: Option+]
When the panel opens you’ll see a small toolbar with available alternatives. Cycle between suggestions using the same shortcut (Alt+]/Option+]) and accept the chosen completion with Tab or by clicking it. You can enable “Always show toolbar” to display the toolbar whenever a suggestion is offered.
Use the multiple-suggestions panel when you want a range of possible implementations (for performance, readability, or style differences). Cycle with the keyboard shortcut, inspect each suggestion, and accept the one that fits your needs.
Quick reference: keyboard shortcuts and actions
Action
Shortcut
Open / cycle multiple suggestions
Alt+] (Windows/Linux), Option+] (macOS)
Accept selected suggestion
Tab or click
Show toolbar every time
Enable “Always show toolbar” in settings
Examples
Below are concise, corrected examples (extracted from a larger project). Each example illustrates different completions Copilot might propose when implementing common utilities. Use these as guidance; adjust constants and context (e.g., drawing surface, sizes) to your project.Example: Determine traffic light state
This implementation computes the current light color for a direction based on a repeating cycle timer. Durations here are sample values and can be configured centrally in your application.
def get_light_state(direction: str, cycle_timer: float) -> str: """ Determine the traffic light state ('green', 'yellow', 'red') for a given direction based on a repeating cycle timer. cycle_timer: elapsed time (seconds) since the start of the cycle. The durations below are examples and may be defined elsewhere in the project. """ # Example durations (seconds) NS_GREEN_DURATION = 10.0 NS_YELLOW_DURATION = 3.0 EW_GREEN_DURATION = 10.0 EW_YELLOW_DURATION = 3.0 cycle_length = NS_GREEN_DURATION + NS_YELLOW_DURATION + EW_GREEN_DURATION + EW_YELLOW_DURATION t = cycle_timer % cycle_length if direction in ("north", "south"): # North-South is green first, then yellow, then red while East-West is green+yellow if t < NS_GREEN_DURATION: return "green" elif t < NS_GREEN_DURATION + NS_YELLOW_DURATION: return "yellow" else: return "red" elif direction in ("east", "west"): # East-West is red while North-South is green+yellow, then green+yellow for EW if t < NS_GREEN_DURATION + NS_YELLOW_DURATION: return "red" elif t < NS_GREEN_DURATION + NS_YELLOW_DURATION + EW_GREEN_DURATION: return "green" else: return "yellow" else: raise ValueError("Invalid direction. Use 'north', 'south', 'east', or 'west'.")
Example: Draw a traffic light
This function places a circular traffic light at a fixed offset for each direction. It assumes drawing constants such as CENTER_X, CENTER_Y, STOP_LINE, LIGHT_OFFSET, LIGHT_RADIUS, and LIGHT_COLORS are provided by the surrounding module.
def draw_traffic_light(surface, direction: str, state: str) -> None: """ Draw a circular traffic light for the given direction at a fixed offset from the intersection center. This function assumes these constants are defined in the surrounding module: CENTER_X, CENTER_Y, STOP_LINE, LIGHT_OFFSET, LIGHT_RADIUS, LIGHT_COLORS. """ if direction == "north": pos = (CENTER_X, STOP_LINE["north"] - LIGHT_OFFSET) elif direction == "south": pos = (CENTER_X, STOP_LINE["south"] + LIGHT_OFFSET) elif direction == "east": pos = (STOP_LINE["east"] - LIGHT_OFFSET, CENTER_Y) elif direction == "west": pos = (STOP_LINE["west"] + LIGHT_OFFSET, CENTER_Y) else: raise ValueError("Invalid direction for traffic light.") color = LIGHT_COLORS[state] pygame.draw.circle(surface, color, pos, LIGHT_RADIUS)
Example: Simple area calculator
A utility that handles two shapes: rectangle (using CAR_SIZE) and circle (using LIGHT_RADIUS).
def calculate_area(shape: str) -> float: """ Calculate the area of a rectangle or circle. For the rectangle we assume CAR_SIZE is defined as: CAR_SIZE = {'vertical': (width, height)} and for the circle we rely on LIGHT_RADIUS defined elsewhere. """ if shape == "rectangle": # Example: CAR_SIZE['vertical'] contains (width, height) return CAR_SIZE["vertical"][0] * CAR_SIZE["vertical"][1] elif shape == "circle": return 3.141592653589793 * (LIGHT_RADIUS ** 2) else: raise ValueError("Invalid shape type. Use 'rectangle' or 'circle'.")
Example: Simple synchronous API request
A compact example showing a safe synchronous call with timeout handling and error propagation.
import requestsdef fetch_random_quote() -> str: """ Fetch a random quote from a public API. Raise requests.HTTPError on bad status. """ response = requests.get("https://api.quotable.io/random", timeout=5) response.raise_for_status() data = response.json() return data.get("content", "")
Example: One quicksort option
Copilot often suggests algorithmic variants. Here is a simple recursive, not-in-place quicksort completion it might propose.
def quicksort(arr: list) -> list: """ Simple recursive quicksort implementation. Not in-place. """ if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) + middle + quicksort(right)
Best practices when using multiple suggestions
Cycle through all alternatives and read them entirely before accepting.
Prefer suggestions that match your project’s coding standards and performance needs.
Test chosen code paths and add unit tests for edge cases the suggestion may not cover.
Treat generated code as a draft that requires review, refactoring, and security analysis.
Do not accept generated code blindly. Verify correctness, performance implications, and security concerns before merging suggestions into your codebase.
Summary
The multiple-suggestions panel is a powerful way to explore alternative implementations quickly. Use the keyboard shortcut to compare completions, choose the most appropriate one, and always validate the output. With careful review, multiple suggestions can accelerate development while maintaining code quality.Links and references