Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions IMPLEMENTATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Implementation Summary: SageMath Notebook Support

## Overview
Successfully implemented comprehensive notebook support for the SageMath VS Code extension, addressing the user request for SageMath code highlighting and execution in Jupyter notebooks.

## Features Implemented

### 1. Notebook Kernel Support
- **`SageMathNotebookController`**: A dedicated notebook controller class that:
- Registers as a notebook kernel for Jupyter notebooks
- Supports both 'sage' and 'python' languages
- Provides execution ordering and proper cell lifecycle management
- Handles temporary file creation and cleanup

### 2. Code Execution
- **Cell Execution Engine**:
- Creates temporary .sage files for each cell
- Executes using the configured SageMath interpreter
- Handles both stdout and stderr output
- Supports existing WSL configuration for Windows users
- Automatic cleanup of temporary files (.sage and .sage.py)

### 3. Configuration
- **New Settings**:
- `sagemathEnhanced.notebookKernelEnabled`: Enable/disable notebook kernel
- Reuses existing interpreter path and WSL settings

### 4. Error Handling
- **Robust Error Management**:
- Displays execution errors in notebook cell outputs
- Handles timeout scenarios (30-second limit)
- Provides informative error messages
- Graceful handling of missing SageMath installation

### 5. Integration
- **Seamless Extension Integration**:
- Added notebook controller to main extension activation
- Maintains compatibility with existing .sage file functionality
- Proper disposal and cleanup on extension deactivation

## Package.json Updates
- Added `notebooks` contribution for Jupyter notebook support
- Extended grammar support for notebook contexts
- Added new configuration properties
- Maintained backward compatibility

## Documentation
- **Updated README.md**: Added notebook usage instructions and features
- **Created NOTEBOOK_SUPPORT.md**: Comprehensive guide for notebook functionality
- **Sample Notebook**: Created `test-notebook.ipynb` with diverse examples

## Testing
- Enhanced test suite with extension activation tests
- Created comprehensive test notebook with various SageMath examples
- Verified TypeScript compilation and build process

## Key Benefits
1. **Syntax Highlighting**: SageMath syntax highlighting automatically works in notebook cells
2. **IntelliSense Support**: Language features extend to notebook context
3. **Execution Integration**: Uses existing SageMath runner infrastructure
4. **Configuration Consistency**: Respects all existing extension settings
5. **Error Feedback**: Clear error reporting for debugging
6. **Cross-Platform**: Supports Windows (with WSL), macOS, and Linux

## File Structure
```
src/
├── extension.ts # Main extension with notebook controller integration
├── notebookController.ts # Notebook kernel implementation
└── test/
└── extension.test.ts # Enhanced tests

out/ # Compiled JavaScript files
NOTEBOOK_SUPPORT.md # Notebook documentation
test-notebook.ipynb # Sample notebook
```

## User Experience
Users can now:
1. Open .ipynb files in VS Code
2. Select "SageMath" from the kernel picker
3. Write SageMath code with syntax highlighting
4. Execute cells and see output directly in notebooks
5. Debug errors with proper error reporting
6. Use all existing extension configuration options

This implementation provides a complete notebook experience that integrates seamlessly with the existing SageMath Enhanced extension functionality.
41 changes: 41 additions & 0 deletions NOTEBOOK_SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SageMath Notebook Support

This extension now provides enhanced notebook support for SageMath code in Jupyter notebooks within VS Code.

## Features

### Notebook Kernel
- **SageMath Kernel**: A dedicated notebook kernel for running SageMath code in Jupyter notebook cells
- **Cell Execution**: Execute SageMath code directly in notebook cells with proper output handling
- **Error Handling**: Display execution errors and warnings in notebook cell outputs
- **Syntax Highlighting**: SageMath syntax highlighting works automatically in notebook cells

### Configuration
- **Enable/Disable Kernel**: Control notebook kernel availability via settings
- **Interpreter Path**: Use the same SageMath interpreter path setting for both files and notebooks
- **WSL Support**: Notebook execution respects WSL settings for Windows users

## Usage

1. **Open a Jupyter Notebook** (`.ipynb` file) in VS Code
2. **Select SageMath Kernel**: Choose "SageMath" from the kernel picker in the notebook interface
3. **Write SageMath Code**: Write SageMath code in notebook cells (language should be set to "sage" or "python")
4. **Execute Cells**: Run cells to execute SageMath code and see the output

## Settings

The following settings control notebook behavior:

- `sagemathEnhanced.notebookKernelEnabled`: Enable/disable the SageMath notebook kernel (default: true)
- `sagemathEnhanced.interpreterPath`: Path to SageMath interpreter (default: "sage")
- `sagemathEnhanced.useWSL`: Use WSL for SageMath execution on Windows (default: false)

## Example Notebook

The extension includes a sample notebook (`test-notebook.ipynb`) demonstrating SageMath functionality in notebooks.

## Requirements

- Visual Studio Code with Jupyter extension
- SageMath installed and accessible from command line
- Proper configuration of `sagemathEnhanced.interpreterPath` setting if SageMath is not in PATH
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Enhance your SageMath coding experience in Visual Studio Code with the SageMath
## Features

- **Run SageMath Code**: Directly execute `.sage` files from the editor with a simple click.
- **Jupyter Notebook Support**: Execute SageMath code in Jupyter notebook cells with dedicated kernel support.
- **Syntax Highlighting**: Enjoy enhanced syntax highlighting tailored for SageMath-specific operations and functions.
- **Integrated Terminal**: Interact with SageMath directly within VS Code's integrated terminal.
- **Automatic `.sage.py` File Cleanup**: Automatically deletes the temporary `.sage.py` file generated after running a SageMath script, keeping your workspace clean.
Expand Down Expand Up @@ -66,9 +67,17 @@ Using the SageMath Enhanced extension is simple and intuitive, providing a seaml
3. **Automatic Cleanup**: If enabled in the extension settings, the temporary `.sage.py` file generated during execution will be automatically deleted after the script finishes running.
4. **WSL Support**: If you're on Windows and have WSL installed, the extension can run SageMath scripts inside WSL for enhanced compatibility.

### Using SageMath in Jupyter Notebooks

1. **Open a Jupyter Notebook**: Open any `.ipynb` file in VS Code (requires the Jupyter extension).
2. **Select SageMath Kernel**: In the notebook interface, click on the kernel picker and select "SageMath" from the available kernels.
3. **Write SageMath Code**: Write SageMath code in notebook cells. The syntax highlighting will work automatically.
4. **Execute Cells**: Run individual cells or all cells to execute SageMath code and see the output directly in the notebook.

### Viewing Output

- **Integrated Terminal**: The output from your SageMath script, along with any errors or warnings, will be displayed in VS Code's integrated terminal. This allows for easy debugging and interaction with your code.
- **Notebook Output**: For notebooks, output appears directly below each executed cell, similar to other Jupyter kernels.

## Requirements

Expand All @@ -95,6 +104,7 @@ This project is licensed under the AGPL-3.0 License - see the [LICENSE](LICENSE)

## TODO (Also Known As "Need Help")

- [x] **Notebook Support**: Enable SageMath code execution and syntax highlighting in Jupyter notebooks.
- [ ] **Code Completion**: Enhance code completion for SageMath-specific syntax.
- [ ] **Interactive Plots**: Enable rendering of interactive SageMath plots within VS Code.
- [ ] **Documentation Integration**: Provide direct access to SageMath documentation via hover tooltips.
Expand Down
34 changes: 24 additions & 10 deletions out/extension.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion out/extension.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading