GitHub Copilot provides suggestions in various ways as you code or based on your comments.
Copilot suggests code directly as you type, often completing the current line or variable name. Suggestions appear as greyed-out text (ghost text).
// User types:
const userN
// Copilot Suggests (ghost text):
const userName = "guest";
Press Tab to accept.
Similar to inline, but often completes a full statement or expression on a single line based on context.
# User types:
import math
radius = 5
area =
# Copilot Suggests (ghost text):
area = math.pi * (radius ** 2)
Press Tab to accept.
Copilot can suggest entire blocks of code, like the body of a function, loop, or conditional statement.
// User types:
function greet(name) {
// Copilot Suggests (ghost text):
function greet(name) {
if (!name) {
logger.info("Hello there!");
} else {
logger.info(`Hello, ${name}!`);
}
}
Press Tab to accept the whole block.
Generates common, repetitive setup code for files, classes, or frameworks based on minimal input or comments.
// User types:
// Basic Express server setup
// Copilot Suggests (ghost text):
const express = require('express');
const app = express();
const port = 3000;
const logger = require('./utils/logger');
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(port, () => {
logger.info(`Example app listening at http://localhost:${port}`);
});
Suggests the entire body of a function or method based on its name, parameters, or a preceding comment describing its purpose.
# User types:
def calculate_days_between_dates(date1, date2):
# Copilot Suggests (ghost text):
def calculate_days_between_dates(date1, date2):
"""Calculates the number of days between two date objects."""
delta = date2 - date1
return delta.days
While not directly suggesting specific argument *values*, Copilot suggests code that correctly *uses* function arguments based on the function\'s purpose and surrounding context.
function processUserData(user) {
// User types:
const userGreeting =
// Copilot Suggests (ghost text based on likely 'user' object structure):
const userGreeting = `Welcome, ${user.firstName}!`;
logger.info(userGreeting);
// ... more code using user properties
}
Can generate comments or documentation strings (like JSDoc, Python docstrings) for your code, or generate code based on your descriptive comments.
/** User types Enter after function signature:
*
*/
function calculateArea(length, width) {
return length * width;
}
/* Copilot Suggests (ghost text for JSDoc):
* @param {number} length The length of the rectangle.
* @param {number} width The width of the rectangle.
* @returns {number} The area of the rectangle.
*/
Alternatively, writing a detailed comment can prompt Copilot to generate the corresponding code.