Chat, Smart Commands & Smart Actions
Completion (G02) answers "what comes next?". Chat answers everything else: "why is this broken?", "how does this work?", "what's a better way?". This module is about asking well.
The Chat Panel: A Conversation That Sees Your Code
Asking a coding question on a generic chatbot website is like phoning a help desk: before they can help, you must read your code aloud, describe your project, and explain what you already tried — and the moment you hang up, they forget you. It's slow, and the costliest part is the copy-paste shuttle where context gets lost. The IDE chat panel is a colleague standing at your desk, looking at your screen: "why does this function fail?" works, because they can see which function you mean, what file it's in, and what the rest of the project looks like. No reading aloud, no shuttle, no amnesia within the conversation.
The Gemini Code Assist chat panel (VS Code: Activity Bar ✦ icon; JetBrains: right tool window) is a conversational interface whose prompts are automatically enriched with IDE context: your active file, selected text, and — with codebase awareness (Standard/Enterprise, G05) — relevant files from the whole project. You can also attach specific files explicitly via the context controls (the + / paperclip control in the chat box, or by referencing open editors).
Conversations are sessions: each chat keeps its own history and context. Both IDEs let you create multiple chats (e.g., one debugging thread, one architecture thread) and switch between them — context in one doesn't bleed into another. In IntelliJ, chats survive restarts; in VS Code, history is available per workspace.
The copy-paste shuttle isn't just slow — it's lossy and risky. Pasting internal code into consumer chatbots is a data-leak vector that security teams ban outright (Samsung famously did after engineers pasted proprietary code into a public chatbot in 2023). In-IDE chat keeps code inside your licensed, governed channel and answers with your real project in view. Faster and safer is a rare combination; use it.
Three habits that make chat answers dramatically better
- Select before you ask. Highlighting the relevant lines pins the model's attention. "Why can this return None?" with a selection beats a paragraph of description.
- One thread per topic. Start a new chat when you change topics. A debugging thread polluted with naming-convention questions gives worse answers to both.
- Paste the evidence. Error message, stack trace, failing test output — verbatim. The model is excellent at reading tracebacks; don't paraphrase them.
Smart Commands: Slash Shortcuts for Routine Asks
Smart commands are built-in slash commands typed in the chat box. Each one wraps a well-engineered prompt around your current file or selection — so you get consistent, high-quality results for the most common requests without writing the prompt yourself.
| Command | What it does | Pro tip |
|---|---|---|
| /explain | Explains the selected code or current file in plain language | Add a focus: /explain the error handling path |
| /fix | Diagnoses and proposes fixes for errors in the selection/file | Select the failing code AND paste the error message |
| /generate | Generates code from a description, into chat or at the cursor | Use the spec-comment formula from G02 in your description |
| /doc | Writes documentation (docstrings, comments) for the selection | Tell it the style: /doc using Google-style docstrings |
| /simplify | Rewrites the selection to be cleaner and more readable | Great first pass before a human code review |
Slash commands operate on what the IDE considers current context — usually your selection, or the active file if nothing is selected. Running /fix with the wrong file focused produces confident fixes for code that was never broken. Glance at the context indicator in the chat box before you hit Enter.
Smart Actions: Right-Click and Lightbulb
Smart actions are the same capabilities surfaced where your mouse already is: select code → right-click → Gemini Code Assist submenu (Explain this, Generate unit tests, Fix, …). When the editor detects a problem, a lightbulb quick-fixThe 💡 icon IDEs show next to a line with a detected issue. Clicking it lists automated fixes — Gemini adds AI-powered ones to that list. may also offer a Gemini fix inline. Same engine as smart commands — different doorway.
When to reach for which:
- Smart action (right-click): you're mid-edit, hands on mouse, want a one-shot answer about this code.
- Smart command (slash): you're already in a chat thread and want the result to join that conversation's context.
- Free-form chat: the ask doesn't fit a template — trade-off questions, "what are my options?", architecture reasoning.
Source Citations
When a suggestion directly quotes at length from a known open-source repository, Gemini Code Assist shows a source citation naming the origin (and license, when known) in chat responses and the citation log. Admins can also configure blocking of matched suggestions entirely. Note: citations are not available in agent mode (G06) — a real trade-off to know about.
If a 40-line block lands in your proprietary codebase verbatim from a GPL project, you have a license-compliance problem that no amount of velocity justifies. Citations turn "did the AI copy this?" from an unanswerable anxiety into a reviewable event — and on Standard/Enterprise, Google additionally offers IP indemnification (G11). When you see a citation badge: stop, check the license, and decide deliberately.
Lab: Fix Recipe Box's Broken API
Recipe Box gets its web layer today — but the version below ships with three planted bugs. You'll use /explain, /fix, and /doc to find, fix, and document them. First, install Flask:
pip install flask
Create the broken app.py
Paste this into a new app.py in your recipe-box folder. Yes, it's broken on purpose — don't fix it by eye yet:
from flask import Flask, jsonify, request
import storage
app = Flask(__name__)
storage.init_db()
@app.route("/recipes", methods=["GET"])
def get_recipes():
recipes = storage.list_recipes()
return jsonify(recipes)
@app.route("/recipes", methods=["GET"]) # BUG ?
def create_recipe():
data = request.get_json()
recipe = {
"name": data["name"], # BUG ?
"ingredients": data["ingredients"],
"minutes": data["minutes"],
}
new_id = storage.add_recipe(recipe)
return jsonify({"id": new_id}), 200 # BUG ?
if __name__ == "__main__":
app.run(debug=True, port=5001)
Let the error message lead: run it
python app.py
It crashes immediately with an AssertionError about overwriting an existing endpoint. Select the whole file, open chat, and run:
/fix AssertionError: View function mapping is overwriting an existing endpoint function: get_recipes
methods=["GET"] on the same path — the create endpoint must be methods=["POST"]. Apply the fix (use the response's insert/copy controls or edit by hand) and re-run. The server should now start on port 5001.Hunt the crash-on-bad-input bug
With the server running, send a request that's missing a field (new terminal):
curl -X POST http://localhost:5001/recipes -H "Content-Type: application/json" -d "{\"name\": \"Toast\"}"
You get an ugly 500 with a KeyError traceback in the server log. Select the create_recipe function and ask:
/fix this returns a 500 KeyError when fields are missing. It should validate
the JSON body and return a 400 with a helpful message listing missing fields.
request.get_json(silent=True), validates that name, ingredients, and minutes exist (and have sane types), and returns jsonify({"error": ...}), 400 when they don't. Re-run the curl — you should now get a clean 400 JSON error, and the server log stays traceback-free.Find the silent bug with /explain
One bug remains and nothing crashes. Select create_recipe's final return line and run:
/explain what HTTP status code should a successful resource creation return,
and is this code following that convention?
return ..., 200. Change it to 201. Silent-but-wrong is the most dangerous bug class — /explain as a convention-checker is one of chat's most underrated uses.Document the fixed file with /doc
Select the whole file and run:
/doc add a module docstring and Google-style docstrings for each route,
including the status codes each can return
python app.py, then: curl http://localhost:5001/recipes returns your Masala Chai from G02; a valid POST returns 201 with a new id; an invalid POST returns 400 with a message. All three? Lab complete.You debugged three different bug species with three different tools: an error-message bug with /fix + pasted traceback, an input-validation bug with /fix + a described requirement, and a silent convention bug with /explain as an auditor. Then /doc captured the knowledge into the file. Notice you never paraphrased an error — you fed evidence verbatim. That habit alone will save you hours.
Knowledge Check
1. What makes IDE chat fundamentally different from a chatbot website?
2. You want a clean rewrite of a gnarly function before sending it to human review. Best smart command?
3. The lab's two /fix calls worked well because you…
4. A suggestion arrives with a source citation badge naming a GPL-licensed repository. You should…
5. Why keep separate chat threads for separate topics?
Quiz Complete!
Ready for G04: Refactoring, Tests & Debugging →