Code Review
Review AI-generated changes with the diff view
Code Review
Every change AI suggests goes through a review process. You're always in control of what gets applied to your code.
The Diff View
When AI generates or modifies code, the changes appear in a diff view that shows:
- Red lines - Code that will be removed
- Green lines - Code that will be added
- Gray lines - Unchanged context
FUNCTION_BLOCK FB_Motor
VAR_INPUT
bStart : BOOL;
bStop : BOOL;
+ bReset : BOOL; // New input added by AI
END_VAR
VAR_OUTPUT
bRunning : BOOL;
- bError : BOOL;
+ bError : BOOL;
+ nErrorCode : INT; // New output for error details
END_VARReview Workflow
Step 1: Review the Changes
Carefully examine each change:
- Does the code do what you asked?
- Are the variable names appropriate?
- Is the logic correct?
- Does it follow your coding standards?
Step 2: Make a Decision
You have three options for each change:
| Action | Description |
|---|---|
| Accept | Apply the changes to your code |
| Reject | Discard the changes entirely |
| Edit | Modify the changes before accepting |
Step 3: Accept or Reject
- Click Accept to apply all changes
- Click Reject to discard all changes
- Use the edit feature to make modifications first
Editing Before Accepting
Sometimes AI gets it mostly right, but you want to make small adjustments:
- Click Edit in the diff view
- Make your modifications in the editor
- Click Accept to apply your edited version
This is useful for:
- Fixing variable names
- Adjusting constants
- Adding comments
- Minor logic tweaks
Partial Acceptance
For larger changes, you may want to accept some parts and reject others:
- Review the complete diff
- Use the section controls to accept/reject individual hunks
- Each hunk can be handled independently
Review Best Practices
Take Your Time
Don't rush through reviews. AI can generate plausible-looking code that has subtle bugs.
Check Logic Flow
Verify that:
- Conditions are correct (AND vs OR, > vs >=)
- Edge cases are handled
- State transitions make sense
Verify Data Types
Ensure:
- Variable types match their usage
- No implicit conversions that could cause issues
- Array bounds are appropriate
Look for Common Issues
Watch out for:
- Infinite loops
- Missing initialization
- Unhandled error conditions
- Off-by-one errors
History
PLC Studio AI keeps a history of all changes:
- Go to History in the sidebar
- See all accepted and rejected changes
- Revert changes if needed
Reverted changes will need to be re-applied in CODESYS to take effect.
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Enter | Accept changes |
Escape | Reject changes |
E | Edit changes |
N | Next change |
P | Previous change |
See the keyboard shortcuts reference for more.