Skip to content

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

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

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 REPL enhancements enabled by default:

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

These features are enabled by default when useColors and terminal are true. Individual features can be controlled via repl.start() options (e.g., syntaxHighlighting: false).

Motivation

This addresses the feature requests from #48164, which was closed as not planned. 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 73.65269% with 132 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.20%. Comparing base (14166a5) to head (eec5763).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/repl/utils.js 70.79% 131 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   242165     +790     
  Branches    45483    45628     +145     
==========================================
+ Hits       217800   218454     +654     
- Misses      15129    15247     +118     
- Partials     8446     8464      +18     
Files with missing lines Coverage Δ
lib/repl.js 94.19% <100.00%> (+0.18%) ⬆️
src/node_options.cc 76.65% <100.00%> (-0.08%) ⬇️
src/node_options.h 98.02% <100.00%> (+<0.01%) ⬆️
lib/internal/repl/utils.js 87.56% <70.79%> (-8.83%) ⬇️

... and 56 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 2 times, most recently from 1e7bcec to 088a905 Compare July 13, 2026 00:01
@hemanth
hemanth requested a review from avivkeller July 13, 2026 02:34
@edsadr

edsadr commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

this one has been in my list forever; I thik this should dogfood util.styleText and make use of everything about coloring already existing in core

@hemanth

hemanth commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Agree. util.styleText reminded me of #43371

Comment thread doc/api/cli.md Outdated
@avivkeller

Copy link
Copy Markdown
Member

Also note that #64034 makes some behind-the-scenes improvements as well, and may conflict with these idiomatic PRs code-wise

@hemanth
hemanth force-pushed the repl/experimental-enhancements branch 2 times, most recently from ea23882 to 192fcb1 Compare July 18, 2026 20:57
Signed-off-by: hemanth <hemanth.hm@gmail.com>
@hemanth
hemanth force-pushed the repl/experimental-enhancements branch from 192fcb1 to a7bf2be Compare July 18, 2026 21:10
@hemanth

hemanth commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main, removed the --experimental-repl-enhancements flag — features are now on by default.

Highlighting, auto-indent, and signature hints are all display-only (repl.line stays plain text), so they are safe to ship ungated. Each can still be disabled via repl.start() options or TERM=dumb.

Adapted to the new getReplInspector API and the refactored line queue from recent main changes.

cc @avivkeller @RafaelGSS @edsadr

@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.

As I said previously, I think these should be idiomatic PRs

@hemanth

hemanth commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Split into idiomatic single-feature PRs per @avivkeller's review:

  1. repl: add inline syntax highlighting #64609repl: add inline syntax highlighting
  2. repl: add auto-indentation for multiline input #64607repl: add auto-indentation for multiline input
  3. repl: add function signature hints #64608repl: add function signature hints

Closing this monolith PR in favor of the above.

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.

5 participants