Skip to content

Code Generation SOP

Fresh

Three methods for generating code with Gemini Code Assist.

Method 1: Quick Pick Menu (Code Transformation)

The most powerful method — shows a diff view so you can review changes before accepting.

VS Code

  1. Press Ctrl+I (Win/Linux) or Cmd+I (Mac)
  2. Type your command and press Enter
  3. Review the diff view
  4. Click Accept or Reject

IntelliJ

  1. Press Alt+\ (Win/Linux) or Cmd+\ (Mac)
  2. Type command > Enter
  3. Review diff > Accept Changes

Transformation Commands

CommandWhat it doesExample
/generateCreate new code/generate function to parse CSV
/fixFix bugs/errors/fix NullPointerException in this method
/docAdd documentation/doc this class with JSDoc
/simplifySimplify code/simplify this nested if-else chain

Method 2: Comment-Driven Generation

Write a natural language comment, then trigger generation.

mermaid
flowchart LR
    A[Write comment describing what you want] --> B[Trigger generation]
    B --> C[Ghost text appears]
    C --> D{Accept?}
    D -->|Yes| E[Press Tab]
    D -->|No| F[Press Esc]

VS Code:

  1. Write comment: // Function to upload file to S3 with retry logic
  2. Press Ctrl+Enter
  3. Preview appears as ghost text
  4. Press Tab to accept

IntelliJ:

  1. Write comment
  2. Press Alt+G or right-click > Generate Code
  3. Press Tab to accept

Method 3: Chat Interface

  1. Click spark Gemini icon in activity bar
  2. Optionally select code for context
  3. Type your prompt:
    • "Write unit tests for the selected function"
    • "Implement the IUserRepository interface"
  4. Copy generated code into your file

Tips for Better Results

Specificity wins

  • Be specific: "Generate a Python function that reads a CSV file and returns a pandas DataFrame, with error handling for missing values and invalid formats"
  • Not vague: "Make a CSV function"
  • Reference specific APIs: "Use boto3 S3 client (not the resource interface)"
  • Include constraints: "Must handle errors without raising exceptions, return Result type"
  • Specify language/framework explicitly when working in a new file
  • Enterprise users: use @REPO_NAME to anchor suggestions to your codebase

Based on official Google Gemini Code Assist documentation.