Skip to content

PolyForm is a VS Code extension that transforms your editor into an infinite canvas where you can write, execute, and visualize code in a spatial environment. Think Excalidraw meets Jupyter Notebooks.

License

Notifications You must be signed in to change notification settings

hridesh-net/PolyForm

Repository files navigation

PolyForm

A Spatial Computing IDE for Visual Programming

PolyForm is a VS Code extension that transforms your editor into an infinite canvas where you can write, execute, and visualize code in a spatial environment. Think Excalidraw meets Jupyter Notebooks.

PolyForm Demo

πŸ“‘ Table of Contents

✨ Features

  • Infinite Canvas: Pan, zoom, and organize your code spatially using the Tldraw engine
  • Executable Code Nodes: Write and run JavaScript and Python code directly on the canvas
  • Real-time Execution: See output instantly in a terminal-style display below each code node
  • Excalidraw Aesthetic: Hand-drawn, sketch-like styling with the Virgil font
  • Polyglot Support: Switch between languages with a dropdown selector
  • Resizable Nodes: Adjust code blocks to fit your workflow
  • Syntax Highlighting: Powered by Prism.js for clear, readable code

πŸš€ Quick Start

Prerequisites

  • VS Code 1.60.0 or higher
  • Node.js (for JavaScript execution)
  • Python 3 (for Python execution)

Installation

From Source

  1. Clone the repository:

    git clone https://github.com/yourusername/polyform.git
    cd polyform
  2. Install dependencies:

    npm install
  3. Compile the extension:

    npm run compile
  4. Open in VS Code and press F5 to launch the Extension Development Host

Usage

  1. Create a new file with the .canvas extension (e.g., myproject.canvas)
  2. Click the + Code Node button in the bottom-right corner
  3. Write your code in the editor
  4. Select the language (JavaScript or Python) from the dropdown
  5. Click Run to execute
  6. See the output appear below the code block

πŸ“Έ Screenshots

JavaScript Execution

console.log("Hello World");
// Output: Hello World

Python Execution

a = 5
b = 6
print(f"{a} + {b} = {a + b}")
# Output: 11

πŸ—οΈ Architecture

PolyForm uses a dual-environment architecture:

  • Webview (React): Renders the infinite canvas and code nodes
  • Extension Host (Node.js): Executes code using system interpreters

Communication happens via VS Code's postMessage API. See ARCHITECTURE.md for detailed technical documentation.

🌍 Environment Detection

PolyForm automatically detects and uses your project's development environment:

Python Virtual Environments

  • βœ… VS Code Python extension's selected interpreter
  • βœ… Workspace virtual environments (venv, .venv, env)
  • βœ… VIRTUAL_ENV environment variable
  • βœ… Falls back to system python3

Node.js Local Modules

  • βœ… Local node_modules/.bin/node
  • βœ… Falls back to system node

Working Directory: Code runs with your workspace folder as the working directory, allowing you to import local modules and packages.

See ENVIRONMENT_DETECTION.md for complete documentation and examples.

πŸ› οΈ Development

Project Structure

PolyForm/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ extension.ts              # Extension entry point
β”‚   β”œβ”€β”€ PolyFormEditorProvider.ts # Webview & execution handler
β”‚   └── webview/
β”‚       β”œβ”€β”€ index.tsx             # Webview entry point
β”‚       β”œβ”€β”€ App.tsx               # Canvas component
β”‚       └── shapes/
β”‚           └── CodeShape.tsx     # Code node implementation
β”œβ”€β”€ dist/                         # Compiled output
β”œβ”€β”€ package.json                  # Extension manifest
└── webpack.config.js             # Build configuration

Build Commands

# Compile TypeScript
npm run compile

# Watch mode (auto-recompile on changes)
npm run watch

# Run extension in debug mode
# Press F5 in VS Code

Adding New Languages

See ARCHITECTURE.md for a step-by-step guide on adding support for Ruby, Go, Rust, or any other language with a CLI interpreter.

🎨 Customization

Styling

The Excalidraw aesthetic is achieved through:

  • Virgil font for hand-drawn text
  • Rough borders with box-shadow: 4px 4px 0px #000
  • Tldraw CSS overrides in src/webview/tldraw-styles.css

Code Editor

The code editor uses react-simple-code-editor with Prism.js. To customize:

  1. Change theme: Import a different Prism theme in CodeShape.tsx
  2. Adjust font: Modify the fontFamily in editor options
  3. Add languages: Import Prism language components

πŸ”’ Security

⚠️ Warning: PolyForm executes code directly on your system without sandboxing.

Risks:

  • File system access
  • Network requests
  • System commands

Recommendations:

  • Only run code you trust
  • Consider using Docker for isolation
  • Review code before execution

See ARCHITECTURE.md for detailed security information.

πŸ› Troubleshooting

Code Node Not Executing

  1. Verify the interpreter is installed:

    node --version
    python3 --version
  2. Check the Debug Console (View β†’ Debug Console) for errors

  3. Open Webview Developer Tools:

    • Command Palette β†’ "Developer: Open Webview Developer Tools"

Canvas Not Loading

  1. Reload the window: Ctrl+R / Cmd+R
  2. Check for compilation errors: npm run compile
  3. Verify all dependencies are installed: npm install

Syntax Highlighting Not Working

Ensure Prism language components are imported in CodeShape.tsx:

import 'prismjs/components/prism-javascript';
import 'prismjs/components/prism-python';

πŸ—ΊοΈ Roadmap

  • Multi-file projects (import/export between nodes)
  • Package manager integration (npm, pip)
  • Debugger support (breakpoints, step-through)
  • Collaborative editing (live sharing)
  • Cloud execution (serverless functions)
  • More languages (Ruby, Go, Rust, etc.)
  • LSP integration (IntelliSense, autocomplete)
  • Export to Jupyter Notebook
  • Canvas templates (algorithms, data structures)

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“§ Contact


Built with ❀️ for visual thinkers and creative coders

About

PolyForm is a VS Code extension that transforms your editor into an infinite canvas where you can write, execute, and visualize code in a spatial environment. Think Excalidraw meets Jupyter Notebooks.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published