Skip to content

repl: add function signature hints - #64610

Open
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/signature-hints-new
Open

repl: add function signature hints#64610
hemanth wants to merge 1 commit into
nodejs:mainfrom
hemanth:repl/signature-hints-new

Conversation

@hemanth

Copy link
Copy Markdown
Contributor

Split from #64443 per review feedback to use idiomatic single-feature PRs.

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

Requires preview to be enabled and the inspector to be available.

Refs: #48164

@nodejs-github-botnodejs-github-bot added needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem. labels Jul 19, 2026
@hemanthhemanth closed this Jul 19, 2026
@hemanthhemanth reopened this Jul 19, 2026
@avivkeller

Copy link
Copy Markdown
Member

@hemanth every time a PR is opened and closed it pings maintainers. May I suggest verifying the branch is correct before opening a PR?

@hemanth
hemanthforce-pushed the repl/signature-hints-new branch from b064b71 to 6beba0cCompareJuly 19, 2026 23:31
Comment threaddoc/api/repl.md Outdated
Comment threaddoc/api/repl.md Outdated
Comment threaddoc/api/repl.md Outdated
Comment threaddoc/api/repl.md Outdated
Comment threadlib/internal/repl/utils.js Outdated
Comment threadlib/repl.js Outdated
Comment threadlib/internal/repl/utils.js

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

Tests?

Comment threadlib/internal/repl/utils.js Outdated
Comment threadlib/internal/repl/utils.js Outdated
@hemanth
hemanthforce-pushed the repl/signature-hints-new branch from fc38014 to ae8b308CompareJuly 21, 2026 06:23
@hemanth
hemanthforce-pushed the repl/signature-hints-new branch from ae8b308 to 7777029CompareJuly 21, 2026 06:25
@hemanth

Copy link
Copy Markdown
ContributorAuthor

Multiple PRs, multiple branches! After splitting the larger PR it has caused few side-effects, cleaned up the branch, please review @avivkeller thank you!

@hemanth
hemanthforce-pushed the repl/signature-hints-new branch from 7777029 to be1b29eCompareJuly 21, 2026 06:29
@hemanth
hemanthforce-pushed the repl/signature-hints-new branch from be1b29e to c4307f5CompareJuly 21, 2026 06:31
Comment threadlib/internal/repl/utils.js Outdated
Comment on lines +926 to +957
// Find the function name before the opening parenthesis.
// Look backwards from cursor for pattern: identifier(
let parenPos = -1;
for (let i = cursor - 1; i >= 0; i--) {
const ch = StringPrototypeCharCodeAt(line, i);
if (ch === 40) { // '('
parenPos = i;
break;
}
// If we hit anything other than whitespace or content after '(',
// stop looking.
if (ch !== 32 && ch !== 9) break; // space, tab
}

if (parenPos < 0) return;

// Extract the expression before the '(' - supports simple names
// (e.g. `foo(`) and dotted access (e.g. `console.log(`).
// Parenthesized expressions like `(fn)(` are not handled;
// the hint is silently skipped in that case.
const nameEnd = parenPos;
let nameStart = nameEnd;
for (let i = nameEnd - 1; i >= 0; i--) {
const ch = StringPrototypeCharCodeAt(line, i);
// Allow identifier chars and dots for property access.
if ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) ||
(ch >= 48 && ch <= 57) || ch === 95 || ch === 36 || ch === 46) {
nameStart = i;
} else {
break;
}
}

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.

How do we get the expression for auto completion? Can we reuse that logic here?

throwOnSideEffect: true,
timeout: 200,
contextId: repl[contextSymbol],
}).then((preview) => {

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.

Would it be cleaner to make this function asynchronous?

Comment threadlib/internal/repl/utils.js Outdated
Comment threadlib/repl.js
Comment on lines +680 to +691
let showSignatureHint;
let clearSignatureHint;
if (preview && this.terminal && process.features.inspector &&
process.env.TERM !== 'dumb') {
({ showSignatureHint, clearSignatureHint } = setupSignatureHint(
this,
kContextId,
));
} else {
showSignatureHint = () => {};
clearSignatureHint = () => {};
}

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.

Rather than setting functions to no-ops, we can use ?.()

Comment threadtest/parallel/test-repl-signature-hints.mjs Outdated

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

I know I'm leaving a lot of reviews, and I'm very sorry, keep in mind, these are just reviews, and you're not obligated to accept them

Comment threadlib/internal/repl/utils.js Outdated
@codecov

codecovBot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.80892% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.13%. Comparing base (0bcc6ef) to head (c4307f5).
⚠️ Report is 15 commits behind head on main.

Files with missing linesPatch %Lines
lib/internal/repl/utils.js88.48%15 Missing and 1 partial ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #64610 +/- ##
==========================================
- Coverage 90.14% 90.13% -0.01% 
==========================================
Files 741 741 Lines 242080 242248 +168 Branches 45563 45593 +30 ==========================================
+ Hits 218213 218343 +130 - Misses 15375 15404 +29 - Partials 8492 8501 +9 
Files with missing linesCoverage Δ
lib/repl.js93.02% <100.00%> (+0.09%)⬆️
lib/internal/repl/utils.js95.77% <88.48%> (-1.16%)⬇️

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

When typing a function name followed by '(', the REPL now displays
a dimmed hint below the input line showing the function's parameters.
For example, typing 'console.log(' shows:
// console.log(...data)
Uses the inspector to safely extract parameter lists via
Function.prototype.toString(), with throwOnSideEffect to prevent
unintended evaluation.
PR-URL: nodejs#64610
@hemanth
hemanthforce-pushed the repl/signature-hints-new branch from c4307f5 to 86623b4CompareJuly 21, 2026 16:56
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ciPRs that need a full CI run.replIssues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@hemanth@avivkeller@jasnell@nodejs-github-bot