CodeCraft - Intelligent Python Editor
An intelligent coding assistant built in Rust that analyzes Python code in real-time using tree-sitter and provides instant code quality improvements.
Features
Real-Time Code Analysis
- Tree-sitter powered parsing: Uses the official Python tree-sitter grammar for accurate syntax analysis
- Live diagnostics: Instant feedback as you type
- Smart pattern detection: Identifies anti-patterns and security issues
Intelligent Suggestions
CodeCraft detects and helps fix:
-
Bare except clauses - Catches dangerous
except:that can hide critical errors- Auto-fix: Converts to
except Exception:
- Auto-fix: Converts to
-
Mutable default arguments - Warns about lists/dicts as default parameters
-
Old string formatting - Suggests using f-strings over
.format() -
List comprehension opportunities - Identifies loops that append to lists
-
Deprecated imports - Flags old modules (imp, optparse)
-
Inefficient loops - Suggests enumerate() over range(len())
-
Security issues - Detects dangerous functions (eval, exec, compile)
One-Click Code Actions
When CodeCraft identifies an issue with an available fix, click the "🔧 Apply Fix" button to automatically refactor your code!
Python Code Execution
- Run code directly from the editor (Ctrl+R)
- Automatic dependency detection - Extracts imports and installs missing packages
- Real-time output - See stdout and stderr as your code runs
- Smart dependency management - Skips standard library modules
Requirements
- Rust 1.70+ (for building)
- Python 3.x (for running code)
- pip (for installing dependencies)
Installation
git clone <your-repo>
cd text_edit
cargo build --release
Usage
Run the application:
cargo run --release
Keyboard Shortcuts
- Ctrl+N: New file
- Ctrl+O: Open file
- Ctrl+S: Save file
- Ctrl+R: Run Python code
UI Components
- Editor Panel (center): Write your Python code with line numbers and issue indicators
- Diagnostics Panel (left): View all detected issues with descriptions and quick fixes
- Output Panel (bottom): See execution results and dependency installation logs
Example
When you write code like this:
def example_function():
try:
result = []
for i in range(len([1, 2, 3])):
result.append(i * 2)
return result
except:
pass
CodeCraft will detect:
- Bare
except:clause (with one-click fix) - Inefficient
range(len())pattern - List comprehension opportunity
Architecture
- analyzer.rs: Tree-sitter integration and Python code analysis
- runner.rs: Python code execution with dependency management
- main.rs: egui-based UI and application logic
Dependencies
eframe/egui: Modern immediate-mode GUI frameworktree-sitter: Incremental parsing systemtree-sitter-python: Python grammar for tree-sitterregex: Pattern matching for import detectionrfd: Native file dialogs
Future Enhancements
- More code actions (convert to f-string, refactor to comprehension)
- Custom rule configuration
- Support for other languages
- LSP integration
- Inline code suggestions with ghost text
License
MIT