Duration: 60 minutes (20 min demo + 40 min hands-on)
Format: Demo + Hands-on
By the end of this module, you will be able to:
- Use Chat participants (
@workspace,@terminal,@github), slash commands, and chat variables to craft precise prompts - Distinguish between Ask, Edit, Agent, and Plan modes and select the right one for a given task
- Generate, explain, and fix code using Copilot Chat with enterprise-grade examples
- Write unit tests for existing code using Copilot Chat in both Java and JavaScript
| Method | Shortcut (macOS) | Shortcut (Win/Linux) |
|---|---|---|
| Chat panel | Click Copilot icon in title bar | Click Copilot icon in title bar |
| Quick chat | ⇧ ⌥ ⌘ L |
Ctrl Shift Alt L |
| Inline chat | ⌘ I |
Ctrl I |
| Smart actions | Right-click → Copilot | Right-click → Copilot |
| Mode | Best For | How It Works |
|---|---|---|
| Ask | Questions about code, concepts, and guidance | Read-only; provides answers and code snippets but doesn't modify files |
| Edit | Controlled edits to a specific set of files | You select the working set of files; Copilot proposes diffs you accept or discard |
| Agent | Complex multi-step tasks with autonomous execution | Copilot determines files to change, runs terminal commands, and iterates to completion |
| Plan | Creating detailed implementation plans before coding | Research-first approach; produces a plan you review before handing off to Agent mode |
Enterprise tip: Use Plan mode for complex features to align on an approach before committing to implementation. This supports team review processes.
Chat participants are domain experts that scope your prompt to a specific area:
| Participant | Purpose | Example |
|---|---|---|
@workspace |
Questions about your entire codebase | @workspace Where is authentication implemented? |
@terminal |
Terminal and shell command help | @terminal How do I find all Java files modified in the last week? |
@github |
GitHub-specific skills (search, web, issues, PRs) | @github What are the open issues labeled 'bug' in this repo? |
Copilot can automatically infer the right participant from your natural language prompt, so explicit
@mention is optional but useful for precision.
| Command | Purpose |
|---|---|
/explain |
Explain selected code |
/fix |
Propose a fix for problems in selected code |
/tests |
Generate unit tests for selected code |
/doc |
Generate documentation for selected code |
/clear |
Clear the chat session |
| Variable | Purpose |
|---|---|
#file |
Reference a specific file |
#selection |
Reference the current editor selection |
#codebase |
Search across the entire codebase for context |
#web |
Include web search results |
#terminalLastCommand |
Reference the last terminal command output |
@workspace /explain #file:src/auth/tokenService.js
How does the token refresh logic work? What happens when the refresh token is expired?
Select the OrderService class and ask:
/tests Generate comprehensive JUnit 5 tests for this class.
Include tests for:
- Normal flow with valid orders
- Edge cases: empty list, null inputs
- Boundary conditions: orders at exactly the minimum amount
- Use @MockBean for the repository dependency
@workspace /explain #file:src/legacy/PaymentProcessor.java
Explain this payment processing logic. Identify any potential
security vulnerabilities or race conditions. Suggest modernization
improvements using current Java best practices.
After a failed build, use:
@terminal #terminalLastCommand
Fix the compilation errors shown in the terminal output.
Explain each fix.
Review this method for:
1. OWASP Top 10 security issues
2. Missing input validation
3. Error handling gaps
4. Performance concerns with large datasets
Open samples/javascript/src/userService.js and the test file samples/javascript/test/userService.test.js.
Step 1: Select the UserService class in the editor.
Step 2: Open Copilot Chat and enter:
/tests Generate comprehensive Jest tests for the selected UserService class.
Include:
- Tests for getAllUsers, getUserById, createUser, updateUser, deleteUser
- Mock the database dependency using jest.fn()
- Test error cases: user not found, duplicate email, invalid input
- Test edge cases: empty strings, very long names, special characters
- Follow AAA pattern (Arrange, Act, Assert)
Step 3: Review the generated tests. Check that:
- All public methods are covered
- Mock setup is correct
- Assertions are meaningful (not just testing that functions exist)
Step 4: Run the tests in the terminal to verify they pass.
Open samples/java/OrderService.java and the test file.
Step 1: Select the OrderService class.
Step 2: Open Copilot Chat and enter:
/tests Generate comprehensive JUnit 5 tests for this OrderService class.
Include:
- Use @ExtendWith(MockitoExtension.class) and @Mock for dependencies
- Tests for calculateOrderTotal, filterOrdersByStatus, getOrdersByDateRange
- Parameterized tests for multiple status values using @ParameterizedTest
- Test null safety and empty collection handling
- Use AssertJ assertions for readable assertions
- Follow the Given-When-Then pattern in test names
Step 3: Review the generated tests for:
- Proper use of Mockito mocks
- Meaningful test data (not just
"test"strings) - Edge case coverage
Step 4: If the test references missing dependencies, use inline chat (⌘ I) to ask Copilot to fix the imports.
Select any complex method from the sample code and ask:
/explain Explain this method step by step, then refactor it to:
1. Reduce cyclomatic complexity
2. Extract magic numbers into named constants
3. Improve null safety
4. Add proper logging with SLF4J
- Ask mode for learning, Edit mode for precision, Agent mode for autonomy: Choose the mode that matches your task
- Chat participants provide domain expertise:
@workspaceknows your code,@githubknows your repo,@terminalknows your shell - Slash commands are shortcuts:
/tests,/fix,/explain,/docsave time on common tasks - Be specific in test generation prompts: Mention the test framework, patterns, edge cases, and mock strategies you want
- Copilot Chat is context-aware: It automatically reads your open files, selections, and terminal output