Skip to content

Commit 1554367

Browse files
committed
Update exercise information
1 parent 2e9083f commit 1554367

File tree

3 files changed

+599
-0
lines changed

3 files changed

+599
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# GitHub Copilot Interaction Cheatsheet
2+
3+
This cheatsheet summarizes key ways to interact with GitHub Copilot in VS Code, based on the Simple Weather CLI exercises. Use this as a quick reference, especially when focusing on code generation.
4+
5+
---
6+
7+
## 1. Main Interaction Interfaces
8+
9+
* **Chat View:**
10+
* Primary panel for detailed questions, code generation, explanations.
11+
* Use **Participants (`@`)** and **Variables (`#`)** for context.
12+
* Use **Slash Commands (`/`)** for specific actions.
13+
* Modes like **"Ask"** (default), **"Edits"**, and **"Agent"** (via `/new`) available.
14+
* **Inline Chat:**
15+
* Quick chat directly in the editor (`Cmd+I` / `Ctrl+I`) on selected code.
16+
* Great for fast explanations (`/explain`), documentation (`/doc`), or quick edits/fixes (`/fix`).
17+
* Review multiple suggestions: `Alt+]` / `Option+]` (Next), `Alt+[` / `Option+[` (Previous).
18+
19+
---
20+
21+
## 2. Providing Context (Crucial for Good Results!)
22+
23+
* **Participants (`@`):** Broad context. **Limit: 1 per prompt.**
24+
* `@workspace`: The entire project/workspace content. Good for general questions, brainstorming, and analysis in "Ask" mode.
25+
* `@vscode`: VS Code editor features, settings, tasks.
26+
* **Variables (`#`):** Granular context. **Can be combined** with a participant. Use `#` + start typing (interactive select) or drag/drop files/folders.
27+
* `#file:path/to/YourFile.java`: Specific file content.
28+
* `#folder:path/to/your/folder`: Specific folder content.
29+
* `#selection`: Currently selected code in the editor.
30+
* `#sym:YourClassName` or `#sym:yourMethodName`: A specific class, method, or variable symbol.
31+
* `#usage:YourSymbolName`: Find where a symbol is used (implementations, calls).
32+
* `#codebase`: Workspace context (variable form, often implicitly used or needed for **Edits** / **Agent (`/new`)** modes).
33+
* `#changes`: Current staged/unstaged Git changes.
34+
* `#terminalLastCommand`: The last command run in the integrated terminal.
35+
* `#terminalSelection`: Text selected in the integrated terminal.
36+
* `#fetch:URL`: Content from a web URL.
37+
38+
* **`@workspace` vs `#codebase`:**
39+
* Both provide project-wide context.
40+
* `@workspace` is a *Participant* (use in Ask mode, subject to 1-participant limit).
41+
* `#codebase` is a *Variable* (often needed for **Edits** mode or **`/new`** command, doesn't conflict with participant limit).
42+
43+
---
44+
45+
## 3. Directing Copilot's Actions
46+
47+
* **Code Completion:** Automatic suggestions as you type. Press `Tab` to accept.
48+
* **Slash Commands (`/`):** Use in Chat View or Inline Chat.
49+
* `/explain`: Ask for explanations of code (`#selection`, `#file`), concepts, errors (`#terminalSelection`), commands (`#terminalLastCommand`).
50+
* `/tests`: Generate unit tests (provide context like `#file:TestFile.java #file:SourceFile.java`).
51+
* `/fix`: Suggest fixes for selected code (`#selection`) or based on error messages.
52+
* `/new`: Generate new files/scaffolding (Agent mode, often needs `#codebase` or specific instructions).
53+
* `/doc`: Generate documentation (usually for `#selection`).
54+
* **"Edits" Mode (Chat View):**
55+
* Select code in the editor.
56+
* Choose "Edits" mode in the Chat View input dropdown.
57+
* Type natural language instructions for refactoring or modification (e.g., "Extract this logic into a new private method", "Add error handling for...")
58+
* Review the proposed diff and apply.
59+
* **Agent Mode (`/new`):**
60+
* Used to create new files/components.
61+
* Provide detailed instructions on the structure and content.
62+
* Often requires broader context (`#codebase`).
63+
64+
---
65+
66+
## 4. Guiding Copilot's Behavior
67+
68+
* **Custom Instructions:**
69+
* Create `.github/copilot-instructions.md` in your project root.
70+
* Define rules, patterns, or style guides (e.g., logging practices, preferred libraries).
71+
* Copilot automatically uses these instructions to tailor suggestions for the workspace.
72+
73+
---
74+
75+
## 5. Key Activities for Code Generation Focus
76+
77+
* **Scaffolding:** Use `/new #codebase` to create new classes/files based on requirements.
78+
* **Implementing Methods/Logic:**
79+
* Use **Code Completion** for line-by-line help.
80+
* Use **Ask Mode** (`@workspace` or `#file` context) to ask "How do I implement...?" or "Show me code to...".
81+
* Use **Edits Mode** on method stubs or existing code to add/modify logic based on instructions.
82+
* **Generating Tests:** Use `/tests` with file context (`#file:Test.java #file:Source.java`).
83+
* **Refactoring:** Use **Edits Mode** on selected code with instructions like "Refactor...", "Improve...", "Simplify...".
84+
* **Adding Features:** Combine brainstorming (`@workspace`), planning (`@workspace /explain steps for feature X`), and implementation using Edits/Ask/Completion.
85+
* **Documentation:** Use `/doc #selection` or Inline Chat (`/doc`).
86+
87+
---

0 commit comments

Comments
 (0)