Proposal: Inlay Hints with minimal parameters count
See original GitHub issueSuggestion
🔍 Search Terms
Inlay Hints, LSP, VS Code integration
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn’t be a breaking change in existing TypeScript/JavaScript code
- This wouldn’t change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript’s Design Goals.
📃 Motivating Example
From https://github.com/microsoft/vscode/issues/147875
With javascript.inlayHints.parameterNames.enabled: 'all'
, we got
parseInt(/* str: */ '123', /* radix: */ 8)
While in many cases, we only use one parameter when calling a function, for example
parseInt(/* str: */ '123')
console.log(/* message: */ foo)
// Vue's Composition API
const state = ref(/* value: */ 1)
array
.filter(/* predicate: */ Boolean)
.map(/* callbackFn: */ i => i.value)
In those cases, the contexts are less ambitious and the inlay hints become a bit redundant and even verbose.
⭐ Suggestion
Thus I am proposing to introduce a new setting to configure the minimal parameters count required for the inlay hints to enable in each function call.
Able to have this setting fields in VS Code:
"typescript.inlayHints.parameterNames.minCount": 2 /* default: 0 */
To hide the inlay hints when calling functions with a single argument.
Thus we could expose an additional preference entry for
interface InlayHintsOptions extends UserPreferences {
includeInlayParameterNameHintsMinCount: 2
}
I had the implementation ready at https://github.com/antfu/TypeScript/commit/395477592183cf555ab5cea6b0eaa041ae2a757b . Could send a PR if the team agrees on this change.
💻 Use Cases
To provide a cleaner code reading experience for common functions while having the ability to have inlay hints for complex functions.
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:7 (3 by maintainers)
I have no idea what you’re talking about
I like #48899 a lot more than using parameter count as a proxy of whether inlay hints may be helpful. I’ve seen plenty of functions that take a single argument whose purpose is not clear until you look up the argument’s name