IDE integration layer for PySwiftAST - provides Monaco Editor compatible diagnostics, code actions, and validation.
- 🎯 Monaco-Compatible Types - Complete language feature API matching Monaco Editor
- ⚡ Fast Validation - Parse Python on any thread without GIL
- 🔧 Quick Fixes - Auto-generate code actions for common errors
- 📍 Precise Ranges - Line and column information for accurate squigglies
- 🚀 Native Performance - 2.93x faster than Python for validation
- 🎨 Full Language Support - Hover, completion, symbols, formatting, and more
import PySwiftIDE
let code = """
def func()
pass
"""
let validator = PythonValidator(source: code)
let result = validator.validate()
// Get diagnostics for Monaco
for diagnostic in result.diagnostics {
print("Error at line \(diagnostic.range.startLineNumber): \(diagnostic.message)")
// Send to Monaco: monaco.editor.setModelMarkers(model, "python", [diagnostic])
}
// Get code actions (quick fixes)
let actions = validator.getCodeActions(for: diagnostic.range, diagnostics: result.diagnostics)
// Send to Monaco: monaco.languages.registerCodeActionProvider("python", ...)let diagnostics = validator.validate().diagnostics
// Convert to JSON and send to Monaco
let jsonData = try JSONEncoder().encode(diagnostics)
// monaco.editor.setModelMarkers(model, "python", diagnostics)let actions = validator.getCodeActions(for: range, diagnostics: diagnostics)
// monaco.languages.registerCodeActionProvider("python", {
// provideCodeActions: () => actions
// })All types are Codable and Sendable for easy JSON encoding and thread-safe usage.
severity:.error,.warning,.info,.hintmessage: Human-readable error messagerange:IDERangewith line and column positionscode: Optional error code for categorizationsource: "PySwiftAST"
title: "Insert ':'"kind:.quickfix,.refactor, etc.edit:WorkspaceEditwith text changesisPreferred: Whether this is the primary fix
startLineNumber,startColumn(1-based)endLineNumber,endColumn(1-based)- Compatible with
monaco.IRange
Core Types (for diagnostics and quick fixes):
Diagnostic,CodeAction,TextEdit,IDERange
Language Features (full Monaco API):
Hover- Hover information with markdown/code blocksCompletionItem/CompletionList- Auto-completion suggestionsDocumentSymbol- Outline view and breadcrumb navigationLocation/LocationLink- Go to definition supportSignatureHelp- Function signature hints during typingInlayHint- Inline type and parameter name hintsFoldingRange- Code folding for functions/classes/importsFormattingOptions- Code formatting configuration
All types are Codable and Sendable for JSON serialization and thread safety.
// In your Monaco Editor setup
monaco.languages.registerCodeActionProvider('python', {
provideCodeActions: async (model, range, context) => {
// Call your Swift backend
const response = await fetch('/api/python/codeActions', {
method: 'POST',
body: JSON.stringify({
code: model.getValue(),
range: range,
diagnostics: context.markers
})
});
return await response.json(); // Returns [CodeAction]
}
});- PySwiftAST - Core Python parser
- PySwiftCodeGen - Code generation for validation
MIT - Same as PySwiftAST