C2ST — C to IEC 61131-3 Structured Text
Convert C code to PLC Structured Text instantly using the Mistral AI API.
Features
- Select C code → press
Ctrl+Alt+S (or Cmd+Alt+S on Mac)
- Result opens in a side-by-side panel with Pascal/ST syntax highlighting
- Conversion notes appended explaining key changes and safety concerns
- Status bar indicator shown on C files
- Secure API key storage (VS Code secret storage — never written in plain text)
Installation
From VSIX
code --install-extension c2st-0.1.0.vsix
From source
git clone <repo>
cd c2st
npm install
npm run compile
# Then press F5 in VS Code to launch the Extension Development Host
Recommended VS Code extension
For better editing and highlighting of .st files, install Structured Text Language Support by Sergey Romanov from the VS Code Marketplace.
Getting a Mistral API Key
- Go to https://console.mistral.ai/
- Sign up / log in
- Navigate to API Keys → Create new key
- Copy the key
Setting your API key in VS Code
Run the command palette (Ctrl+Shift+P) and choose:
C2ST: Set Mistral API Key
Or add it to your VS Code settings.json (less secure, visible in plain text):
{
"c2st.mistralApiKey": "your-key-here"
}
Usage
- Open a
.c file
- Select the C code you want to convert
- Press
Ctrl+Alt+S (Windows/Linux) or Cmd+Alt+S (Mac)
— or open the command palette and run C2ST: Convert C to ST
- The Structured Text result opens in a panel to the right
Settings
| Setting |
Default |
Description |
c2st.mistralApiKey |
"" |
Your Mistral API key (prefer the Set Key command) |
c2st.model |
mistral-large-latest |
Model to use (mistral-large-latest or open-mistral-7b) |
Conversion rules applied
| C |
Structured Text |
= |
:= |
== |
= |
if/else {} |
IF...ELSIF...ELSE...END_IF |
for {} |
FOR...END_FOR |
switch/case/break |
CASE...OF...ELSE...END_CASE |
struct |
TYPE...STRUCT...END_STRUCT |
*ptr param |
VAR_IN_OUT |
malloc |
ARRAY[0..N] (static allocation) |
static |
VAR RETAIN / VAR PERSISTENT |
Troubleshooting
Extension not working / Command not found
Problem: "C2ST: Convert C to ST" command doesn't appear in command palette.
Solutions:
- Reload VS Code window:
Ctrl+Shift+P → "Developer: Reload Window"
- Check that extension is installed:
Ctrl+Shift+X → search "C2ST"
- Verify extension is enabled (not disabled in the Extensions panel)
- Check VS Code version (requires 1.85.0 or higher)
Problem: Extension shows error about missing API key.
Solutions:
- Set your API key:
Ctrl+Shift+P → "C2ST: Set Mistral API Key"
- Get a key from https://console.mistral.ai/ if you don't have one
- Verify key is correctly entered (no extra spaces)
- Check if key is stored:
- Open Settings:
Ctrl+, → search "c2st"
- Or check secret storage (secure) vs settings.json (plaintext)
"Invalid API key (401)" error
Problem: Conversion fails with 401 Unauthorized error.
Solutions:
- Verify your API key is valid at https://console.mistral.ai/
- API key may have been revoked or expired - create a new one
- Re-enter the key:
Ctrl+Shift+P → "C2ST: Set Mistral API Key"
- Ensure no extra whitespace before/after the key
- If key is in settings.json, make sure it's the full key (starts with
sk-)
"Rate limited (429)" error
Problem: Too many requests to Mistral API.
Solutions:
- Wait 1-2 minutes before trying again
- Check your Mistral account limits at https://console.mistral.ai/
- Consider upgrading your Mistral plan if hitting limits frequently
- Use
open-mistral-7b model instead (lower rate limits but faster)
"Request timeout" error
Problem: Conversion takes too long and times out (>60 seconds).
Solutions:
- Select smaller code sections (under 10,000 characters)
- Break large files into smaller chunks
- Check your internet connection
- Try again - Mistral API may be experiencing high load
- Consider using a faster model (
open-mistral-7b)
Empty or incomplete conversion result
Problem: Converted ST code is missing or incomplete.
Solutions:
- Check the input C code is valid and well-formed
- Try converting smaller sections individually
- Review conversion notes at the end of the result
- Some complex C constructs may not convert perfectly - manual review needed
- Try different Mistral models:
mistral-large-latest: Better quality, handles complex code
open-mistral-7b: Faster but may struggle with complex code
Keyboard shortcut not working
Problem: Ctrl+Alt+S (or Cmd+Alt+S) doesn't trigger conversion.
Solutions:
- Make sure you have C code selected (highlight it first)
- Verify you're in a
.c file (status bar should show "C")
- Check for keyboard shortcut conflicts:
Ctrl+Shift+P → "Preferences: Open Keyboard Shortcuts"
- Search for "C2ST"
- Verify the binding or change it to avoid conflicts
- Use command palette instead:
Ctrl+Shift+P → "C2ST: Convert C to ST"
Result file doesn't open
Problem: Conversion succeeds but result window doesn't appear.
Solutions:
- Check for error messages in the bottom-right corner
- Look for the
*_c2st.st file in the same directory as your .c file
- Open it manually from the Explorer panel
- Check file permissions - ensure VS Code can write to the directory
- View Developer Console for errors:
Help → Toggle Developer Tools
Poor conversion quality
Problem: Converted ST code has errors or doesn't match expectations.
Solutions:
- Use
mistral-large-latest model for better quality:
Ctrl+, → search "c2st.model"
- Select
mistral-large-latest
- Simplify your C code before conversion:
- Remove complex macros
- Expand inline functions
- Add comments explaining intent
- Convert smaller, focused sections rather than entire files
- Review and manually refine the output - AI conversion is a starting point
- Check conversion notes at the end of the result for warnings
"Selection too large" error
Problem: Selected code exceeds 10,000 character limit.
Solutions:
- Select smaller code sections
- Break your code into functions or modules
- Convert piece by piece (functions, structs, then main logic)
- Remove unnecessary comments or whitespace to reduce size
Extension slows down VS Code
Problem: VS Code becomes slow or unresponsive after using C2ST.
Solutions:
- Close unused
*_c2st.st files (they accumulate in the same directory)
- Reload VS Code window:
Ctrl+Shift+P → "Developer: Reload Window"
- Clear temp files manually if needed
- Check Developer Console for errors:
Help → Toggle Developer Tools
Getting help
If your issue isn't listed here:
Check the logs:
- Open VS Code Developer Console:
Help → Toggle Developer Tools
- Look for errors in the Console tab
Search existing issues:
Report a bug:
Read the docs:
Building a VSIX package
npm install -g @vscode/vsce
npm run compile
vsce package
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
Changelog
See CHANGELOG.md for version history and release notes.
License
MIT