Skip to content

Introduce VSCode native Ruby REPL #3562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Introduce VSCode native Ruby REPL #3562

wants to merge 1 commit into from

Conversation

dgalarza
Copy link

Introduce VSCode Native Ruby REPL

Overview

This PR introduces a comprehensive, first-party Ruby REPL integration directly into the VSCode Ruby LSP extension, providing developers with a seamless interactive Ruby experience without leaving their editor.

✨ Features

🖥️ Multiple Launch Options

  • Terminal Profiles: Launch IRB or Rails console directly from VSCode's terminal interface
  • Command Palette: Quick access via Ruby LSP: Start Ruby REPL
  • Integrated Experience: No need for external terminal windows

📝 Code Execution

  • Command Palette: Execute selected code with Ruby LSP: Execute in Ruby REPL
  • Context Menu: Right-click selected code and choose Execute in Ruby REPL
  • Keyboard Shortcuts:
    • Cmd + Enter / Ctrl + Enter: Execute single line in scratchpad
    • Cmd + Shift + Enter / Ctrl + Shift + Enter: Execute multi-line selection in scratchpad

🗒️ Interactive Scratchpad

  • Opens automatically when starting a REPL
  • Full Ruby LSP integration (autocomplete, syntax highlighting, diagnostics)
  • Perfect for experimenting and prototyping
  • Seamless code execution from scratchpad to REPL

⚙️ Configuration Settings

rubyLsp.replSettings

New configuration section for customizing REPL behavior:

{
  "rubyLsp.replSettings": {
    "showWelcomeMessage": true,
    "executionFeedbackDuration": 3000,
    "autoOpenScratchPad": true
  }
}

Settings Options:

Setting Type Default Description
showWelcomeMessage boolean true Show welcome message with tips when starting REPL
executionFeedbackDuration number 3000 How long to show execution feedback decorations (in milliseconds). Range: 1000-10000ms
autoOpenScratchPad boolean true Automatically open the scratch pad when starting REPL

Terminal Profiles

Two new terminal profiles are automatically available:

  • Ruby REPL (IRB): Quick access to IRB
  • Rails Console: Direct Rails console access

Commands Added

Command Purpose
Ruby LSP: Start Ruby REPL Launch a new REPL instance
Ruby LSP: Execute in Ruby REPL Send selected code to active REPL
Ruby LSP: Interrupt Ruby REPL Interrupt running REPL processes
Ruby LSP: Start Ruby REPL (IRB) Start IRB terminal
Ruby LSP: Start Rails Console Start Rails console terminal

Keyboard Shortcuts

Shortcut Context Action
Cmd/Ctrl + Enter Ruby scratchpad Execute current line
Cmd/Ctrl + Shift + Enter Ruby scratchpad Execute selection

Key Components:

  • ReplManager: Central coordination of REPL instances
  • TerminalRepl: Terminal-based REPL integration
  • ReplScratchPad: Interactive scratch file functionality
  • TerminalProfileProvider: Custom terminal profile management
  • Command handlers for all user interactions

🧪 Testing

Complete test suite covering:

  • All command handlers
  • REPL manager functionality
  • Scratchpad interactions
  • Terminal profile provider
  • Integration scenarios

🎯 User Experience

This feature transforms the Ruby development workflow in VSCode by:

  • Eliminating context switching between editor and external terminals
  • Providing immediate feedback for code experimentation
  • Leveraging existing Ruby LSP capabilities in interactive scenarios
  • Supporting both quick one-liners and complex multi-line explorations
  • Offering configurable behavior to match user preferences

📖 Usage

  1. Start a REPL: Use Command Palette → Ruby LSP: Start Ruby REPL
  2. Execute Code: Select code → Right-click → Execute in Ruby REPL
  3. Use Scratchpad: Write code with full LSP support, execute with keyboard shortcuts
  4. Terminal Integration: Access via terminal dropdown for IRB/Rails console
  5. Customize: Adjust settings in rubyLsp.replSettings to match your workflow

@dgalarza dgalarza requested a review from a team as a code owner May 30, 2025 13:45
Copy link

graphite-app bot commented May 30, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This expands the VSCode extension to provide a first party Ruby REPL.

Features:

- Custom terminal profiles to allow you to open an IRB or Rails console
  directly from the terminal interface
- Ability to launch a REPL from the command palette, search `Ruby LSP:
  Start Ruby REPL`
- Send code to execute in the REPL via the command palette with `Ruby
  LSP: Execute in Ruby REPL`
- Send code to execute in the REPL via context menu, select code, right
  click and select `Execute in Ruby REPL`
- Open a scratchpad by default when opening a REPL. This allows you to
  write code, utilize built in VSCode code completion / ruby-lsp and
  more. Send code to the REPL via cmd + enter for a single line or cmd +
  shift + enter for multi-lines.
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.

1 participant