question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Inlay Hints with minimal parameters count

See original GitHub issue

Suggestion

🔍 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:open
  • Created a year ago
  • Reactions:6
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
andrewbranchcommented, Apr 30, 2022

you just might not always remember which arg goes where

I have no idea what you’re talking about

image
2reactions
mjbvzcommented, Apr 30, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

discussion: disable vscode inlay hints by default · Issue #13495
I'd like to proposing that these should not be by-default enabled and so the following settings should default to: "rust-analyzer.inlayHints.
Read more >
Inlay hints | IntelliJ IDEA Documentation - JetBrains
Inlay hints are special markers that appear in the editor and provide you with additional information about your code, like the names of...
Read more >
VS Code API | Visual Studio Code Extension API
VS Code API. VS Code API is a set of JavaScript APIs that you can invoke in your Visual Studio Code extension. This...
Read more >
vim 9 virtual text enables Inlay hints support in ... - Reddit
After working through a number of issues, vim 9.0.200 is about… ... Inlay hints are like little inline annotations that the semantic engine ......
Read more >
Add rust-analyzer's inlay hints - gnome-builder - GitLab
rust-analyzer shows hints for types of local variables names of function arguments types of chained expressions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found