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 4 times, most recently 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 72.92929% with 134 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.20%. Comparing base (14166a5) to head (088a905).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/repl/utils.js 69.95% 133 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64443      +/-   ##
==========================================
- Coverage   90.23%   90.20%   -0.03%     
==========================================
  Files         741      741              
  Lines      241375   242099     +724     
  Branches    45483    45621     +138     
==========================================
+ Hits       217800   218397     +597     
- Misses      15129    15241     +112     
- Partials     8446     8461      +15     
Files with missing lines Coverage Δ
lib/repl.js 94.19% <100.00%> (+0.18%) ⬆️
src/node_options.cc 76.74% <100.00%> (+0.02%) ⬆️
src/node_options.h 98.02% <100.00%> (+<0.01%) ⬆️
lib/internal/repl/utils.js 87.35% <69.95%> (-9.04%) ⬇️

... and 41 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.

@hemanth hemanth force-pushed the repl/experimental-enhancements branch 2 times, most recently from 16ee02c to b749718 Compare July 12, 2026 20:37

@avivkeller avivkeller left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can these be idiomatic PRs?

@hemanth

hemanth commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

@avivkeller for sure! having some challenges on my local machine, so depending on the GH CI to report me the build time errors.

@hemanth hemanth force-pushed the repl/experimental-enhancements branch from b749718 to 1e7bcec Compare July 12, 2026 23:53
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 1e7bcec to 088a905 Compare July 13, 2026 00:01
@hemanth hemanth requested a review from avivkeller July 13, 2026 02:34
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.

3 participants