Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 8, 2025

This PR implements keyboard shortcut support for converting cells to raw type, addressing the missing functionality in the VS Code Jupyter extension. Previously, attempting to convert cells to raw type would throw a "Cell Type raw not implemented" error.

Changes Made

Core Functionality

  • Added jupyter.changeCellToRaw command with ctrl+; r keybinding, following the existing pattern (ctrl+; c for code, ctrl+; m for markdown)
  • Implemented changeCellToRaw() method in CodeWatcher class with proper telemetry support
  • Enhanced changeCellTo() method to handle conversions between all three cell types (code, markdown, raw) intelligently

Pattern Recognition

  • Extended CellMatcher class to recognize # %% [raw] cell markers using new PythonRawCellMarker regex pattern
  • Added isRaw() method and updated getCellType() to properly detect raw cells
  • Updated isCell() method to include raw cell detection

Cell Generation

  • Added generateRawCell() function to create raw cells with proper metadata
  • Updated generateCells() function to handle raw cell generation in addition to code and markdown cells

Infrastructure

  • Added command registration in CommandRegistry with proper async handling
  • Updated TypeScript command mapping to include the new command for type safety
  • Added telemetry support with ChangeCellToRaw event tracking

Usage

Users can now convert cells to raw type using the keyboard shortcut ctrl+; r in Python files with #%% cell markers. Raw cells use the format:

# %% [raw]
This is raw text content
No syntax highlighting or execution

Testing

Added comprehensive unit tests for raw cell functionality:

  • 5 new CellMatcher tests for raw cell pattern recognition
  • Verification of getCellType() method returning correct types
  • All existing tests continue to pass (27/27 tests passing)

The implementation maintains backward compatibility and follows established patterns in the codebase.

Fixes #16158.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 8, 2025 01:26
- Add ChangeCellToRaw command and keybinding (ctrl+; r)
- Implement changeCellToRaw() method in CodeWatcher
- Update changeCellTo() to handle raw cell conversions
- Add raw cell pattern recognition in CellMatcher
- Update cell factory to generate raw cells
- Add telemetry support for raw cell operations

Co-authored-by: DonJayamanne <[email protected]>
- Add unit tests for CellMatcher raw cell detection
- Verify raw cell pattern recognition works correctly
- Ensure all cell types (code, markdown, raw) work properly
- Add test coverage for getCellType method

Co-authored-by: DonJayamanne <[email protected]>
@Copilot Copilot AI changed the title [WIP] Keyboard shortcut to toggle between raw and code cell Add keyboard shortcut support for raw cell type conversion Sep 8, 2025
@Copilot Copilot AI requested a review from DonJayamanne September 8, 2025 01:34
Copilot finished work on behalf of DonJayamanne September 8, 2025 01:34
Copy link
Contributor

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requirement is to change a Code to RAW cell in a Jupyter Notebook and vice versa.
This has nothing to do with interactive windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keyboard shortcut to toggle between raw and code cell

2 participants