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

@hemanthhemanth 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-botnodejs-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
hemanthforce-pushed the repl/experimental-enhancements branch 4 times, most recently from 30413de to 14baff1CompareJuly 12, 2026 07:02
@codecov

codecovBot 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 linesPatch %Lines
lib/internal/repl/utils.js70.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 linesCoverage Δ
lib/repl.js94.19% <100.00%> (+0.18%)⬆️
src/node_options.cc76.65% <100.00%> (-0.08%)⬇️
src/node_options.h98.02% <100.00%> (+<0.01%)⬆️
lib/internal/repl/utils.js87.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
hemanthforce-pushed the repl/experimental-enhancements branch 2 times, most recently from 16ee02c to b749718CompareJuly 12, 2026 20:37

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

Copy link
Copy Markdown
ContributorAuthor

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

@hemanth
hemanthforce-pushed the repl/experimental-enhancements branch 2 times, most recently from 1e7bcec to 088a905CompareJuly 13, 2026 00:01
@hemanth
hemanth requested a review from avivkellerJuly 13, 2026 02:34
@edsadr

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

Copy link
Copy Markdown
ContributorAuthor

Agree. util.styleText reminded me of #43371

@hemanth
hemanthforce-pushed the repl/experimental-enhancements branch from 088a905 to eec5763CompareJuly 13, 2026 17:38
Comment threaddoc/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
hemanthforce-pushed the repl/experimental-enhancements branch 2 times, most recently from ea23882 to 192fcb1CompareJuly 18, 2026 20:57
Signed-off-by: hemanth <hemanth.hm@gmail.com>
@hemanth
hemanthforce-pushed the repl/experimental-enhancements branch from 192fcb1 to a7bf2beCompareJuly 18, 2026 21:10
@hemanth

Copy link
Copy Markdown
ContributorAuthor

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

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

Copy link
Copy Markdown
ContributorAuthor

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 freeto 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 / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@hemanth@nodejs-github-bot@edsadr@avivkeller@RafaelGSS