⌂ Home
Gemini Code Assist: AI Pair Programming in Your IDE
Code Assist Track
⏰ 45-60 min Module 4 of 12 🔧 Hands-on lab
💬
Gemini Code Assist Track — G03: Chat, Smart Commands & Smart Actions Move beyond autocomplete: converse with an assistant that sees your code, automate routine asks with slash commands, and fix Recipe Box's deliberately broken API in the lab.

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

Analogy First

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.

Technical Definition

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.

Why It Matters

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

Technical Definition

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.

CommandWhat it doesPro tip
/explainExplains the selected code or current file in plain languageAdd a focus: /explain the error handling path
/fixDiagnoses and proposes fixes for errors in the selection/fileSelect the failing code AND paste the error message
/generateGenerates code from a description, into chat or at the cursorUse the spec-comment formula from G02 in your description
/docWrites documentation (docstrings, comments) for the selectionTell it the style: /doc using Google-style docstrings
/simplifyRewrites the selection to be cleaner and more readableGreat first pass before a human code review
Gotcha

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

Technical Definition

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

Technical Definition

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.

Why It Matters

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:

terminal
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:

app.py — contains 3 planted bugs
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)
WHAT: a two-endpoint Flask API over the storage module you built in G02. WHY it's broken: real debugging practice beats toy examples — these are three of the most common real-world API mistakes. GOTCHA: one bug prevents startup, one crashes on bad input, one is silently wrong but "works".

Let the error message lead: run it

terminal
python app.py

It crashes immediately with an AssertionError about overwriting an existing endpoint. Select the whole file, open chat, and run:

chat
/fix AssertionError: View function mapping is overwriting an existing endpoint function: get_recipes
Expected Gemini identifies that both routes declare 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):

terminal — works on PowerShell 7+ / bash (curl)
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:

chat
/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.
Expected A version that checks 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:

chat
/explain what HTTP status code should a successful resource creation return,
and is this code following that convention?
Expected Gemini explains that REST convention for a successful creation is 201 Created, not 200, and points at your 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:

chat
/doc add a module docstring and Google-style docstrings for each route,
including the status codes each can return
Final verification Re-run 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.
What Just Happened?

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?

It uses a bigger model
Prompts are automatically enriched with your real code context (active file, selection, project), and code stays in a governed channel
It works offline
It can only answer questions about syntax

2. You want a clean rewrite of a gnarly function before sending it to human review. Best smart command?

/doc
/explain
/simplify
/generate

3. The lab's two /fix calls worked well because you…

Provided evidence: the verbatim error in one case, a precise description of wrong behavior + desired behavior in the other
Used the word "please"
Ran them twice each
Had the premium model selected

4. A suggestion arrives with a source citation badge naming a GPL-licensed repository. You should…

Accept it — citation means it's pre-approved
Stop and evaluate: a long verbatim GPL excerpt in proprietary code is a license-compliance decision, not an autocomplete decision
Delete the whole file
Citations only appear for Google-owned code

5. Why keep separate chat threads for separate topics?

Each thread is billed separately
Each chat's history is context for its next answer — mixed topics pollute that context and degrade answers on both topics
Threads can't exceed 10 messages
It's required by the license terms

Quiz Complete!

Ready for G04: Refactoring, Tests & Debugging →