How to Use AI Actions in JetBrains IDE: Explain, Test, and Modify Code
I was debugging a complex piece of legacy code the other day, constantly copying code snippets to ChatGPT for explanations. The context switching was killing my productivity—switch windows, paste code, explain, switch back, find the next block. There had to be a better way.
That’s when I discovered JetBrains AI Actions, a feature that brings AI capabilities directly into the code editing workflow. No more context switching.
The Problem: Context Switching Kills Productivity
Here’s what my workflow looked like before:
- Find suspicious code block
- Select and copy
- Switch to browser with ChatGPT/Claude
- Paste and ask for explanation
- Read response
- Switch back to IDE
- Repeat for next code block
This dance happened dozens of times per day. Each switch costs maybe 5-10 seconds, but the real cost is mental—it breaks my flow.
The Solution: AI Actions in JetBrains IDE
JetBrains AI Actions provides two ways to access AI features directly in your editor:
Method 1: Selection Toolbar
When you select any code block, a small toolbar appears near your selection:
1. Select code block in editor2. Click "Ask AI" in popup toolbar3. Code automatically appears in AI chat panel4. Type your question or requestThis is the quickest way when you have a specific question in mind.
Method 2: Right-Click Context Menu
For more structured tasks, right-click on selected code:
AI Actions├── Explain # Get code explanation├── Find Issues # Detect potential bugs├── Generate Tests # Create unit tests└── Modify # Request code changesEach option has a specific purpose:
- Explain: Great for understanding legacy code or unfamiliar patterns
- Find Issues: Catches bugs you might have missed
- Generate Tests: Quick unit test scaffolding
- Modify: Natural language code modifications
How I Use Each Action
Explain Code
I was looking at this Hibernate query method and couldn’t figure out why it was slow:
public List<Document> findRecentDocuments(Session session) { return session.createQuery( "FROM Document d WHERE d.status = :status " + "ORDER BY d.updatedAt DESC", Document.class) .setParameter("status", Status.ACTIVE) .setMaxResults(100) .list();}I selected it, right-clicked, chose “AI Actions > Explain”, and instantly got a detailed breakdown including the HQL query translation, parameter binding, and potential N+1 query issues.
Generate Tests
I wrote a utility method for string manipulation:
public static String truncate(String input, int maxLength) { if (input == null) return null; if (maxLength <= 0) return ""; if (input.length() <= maxLength) return input; return input.substring(0, maxLength - 3) + "...";}Selected the method, “AI Actions > Generate Tests”, and got test cases covering:
- Null input handling
- Empty string edge case
- Exact length match
- Truncation with ellipsis
- Negative max length
This saved me from manually thinking through edge cases—I just had to review and adjust.
Find Issues
I ran this on a method and discovered a resource leak I had missed:
public void processFile(String path) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(path)); String line = reader.readLine(); while (line != null) { processLine(line); line = reader.readLine(); } // Bug: reader never closed!}The AI caught that the BufferedReader wasn’t being closed and suggested using try-with-resources.
Modify Code
This is where natural language really shines. I had a method returning ArrayList:
public ArrayList<String> getNames() { ArrayList<String> names = new ArrayList<>(); // ... populate list return names;}I selected it, chose “Modify”, and typed: “Change return type to Set and use LinkedHashSet to preserve order”. The AI rewrote:
public Set<String> getNames() { Set<String> names = new LinkedHashSet<>(); // ... populate list return names;}Common Mistakes to Avoid
Mistake 1: Ignoring the selection toolbar
I initially dismissed the popup toolbar as visual clutter. Big mistake. “Ask AI” is faster than right-click > AI Actions > specific option when you just want to ask a question.
Mistake 2: Typing prompts when shortcuts exist
I used to select code, then type “explain this code” in the chat panel. That’s what the “Explain” shortcut already does. Use the built-in actions first.
Mistake 3: Not exploring all options
“Find Issues” caught bugs I didn’t know about. “Generate Tests” writes better edge cases than I do on first pass. Explore all four actions—they each solve different problems.
Why This Matters
The real value isn’t just the AI capabilities—it’s the integration. No window switching. No copy-paste. The code context is already there, and the response appears in a panel you can keep open while you work.
For debugging sessions, this is transformative. I can explain a function, find its issues, generate tests for it, and modify it—all without leaving the editor.
Key Takeaways
- Selection toolbar for quick questions
- Right-click menu for structured tasks (explain, test, find issues, modify)
- Explore all four actions—each serves a different workflow
- Stay in the editor—no context switching needed
The AI Actions menu transforms JetBrains IDE from just an editor into an intelligent coding assistant. Once you start using it, going back to copy-paste workflows feels primitive.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments