Skip to content

repl: add syntax highlighting, auto-indentation, and signature hints#64443

Open
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/experimental-enhancements
Open

repl: add syntax highlighting, auto-indentation, and signature hints#64443
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/experimental-enhancements

Conversation

@hemanth

@hemanth hemanth commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Description

Add experimental REPL enhancements behind the --experimental-repl-enhancements CLI flag:

1. Inline Syntax Highlighting

Uses the Acorn tokenizer (already in deps/) to colorize JavaScript input in real-time:

  • Keywords (const, function, if, etc.) → Magenta
  • Strings → Green
  • Numbers → Yellow
  • Booleans/null/undefined → Yellow
  • Regular expressions → Red
  • Comments → Gray

Highlighting is applied at display time only — repl.line remains plain text, so cursor positioning and evaluation are unaffected.

2. Auto-Indentation

Automatically inserts 2-space indentation on continuation lines based on brace/bracket/paren depth when entering multiline input.

3. Function Signature Hints

When the user types functionName(, the function's parameter list is displayed as a dimmed hint below the input line. Uses the V8 Inspector protocol with throwOnSideEffect: true for safety.

Usage

node --experimental-repl-enhancements

All features are off by default — nothing changes for users unless they explicitly pass the flag. Individual features can also be controlled via repl.start() options (e.g., syntaxHighlighting: false).

Motivation

This addresses the feature requests from #48164, which was closed as not planned. However, by gating everything behind an experimental flag with no behavioral changes to the default REPL, the risk profile is minimal. These are quality-of-life improvements that bring the Node.js REPL closer to modern shell experiences (Python's IPython, Ruby's Pry, etc.).

Refs: #48164

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 12, 2026
@hemanth hemanth force-pushed the repl/experimental-enhancements branch 3 times, most recently from 11e1ac8 to 30413de Compare July 12, 2026 06:23
Add experimental REPL enhancements behind the
--experimental-repl-enhancements flag:

1. Inline syntax highlighting using the Acorn tokenizer
   to colorize keywords (magenta), strings (green),
   numbers (yellow), booleans/null (yellow), regular
   expressions (red), and comments (gray).

2. Auto-indentation for multiline input based on
   brace/bracket/paren depth, using 2-space indentation.

3. Function signature hints that display parameter lists
   as dimmed text below the input when the user types a
   function call.

All features are off by default and require the CLI flag
to enable. Highlighting is applied at display time only
so cursor positioning and evaluation are unaffected.

Refs: nodejs#48164
Signed-off-by: hemanth <hemanth.hm@gmail.com>
@hemanth hemanth force-pushed the repl/experimental-enhancements branch from 30413de to 14baff1 Compare July 12, 2026 07:02
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.09756% with 339 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.11%. Comparing base (14166a5) to head (14baff1).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/repl/utils.js 27.99% 318 Missing and 1 partial ⚠️
lib/repl.js 57.44% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64443      +/-   ##
==========================================
- Coverage   90.23%   90.11%   -0.12%     
==========================================
  Files         741      741              
  Lines      241375   241867     +492     
  Branches    45483    45509      +26     
==========================================
+ Hits       217800   217954     +154     
- Misses      15129    15471     +342     
+ Partials     8446     8442       -4     
Files with missing lines Coverage Δ
src/node_options.cc 76.74% <100.00%> (+0.02%) ⬆️
src/node_options.h 97.53% <100.00%> (-0.49%) ⬇️
lib/repl.js 92.90% <57.44%> (-1.11%) ⬇️
lib/internal/repl/utils.js 73.11% <27.99%> (-23.28%) ⬇️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants