Blog

What is the 'inlay' for vs-code ?



Inlay hints in Visual Studio Code (VS Code) are small annotations that provide additional context and information about your code directly in the editor. They help you understand the types, parameter names, or other details without cluttering your code with comments or explicit annotations. They can show things like:

  • Parameter names for function arguments
  • Return types for functions or variables
  • Types of variables inferred by the language
  • Other helpful hints, depending on the language or extension you're using

Inlay hints are particularly useful in strongly typed languages like TypeScript, C#, or Rust, where understanding the types of variables and function signatures can help clarify the code's behavior.

Common Uses of Inlay Hints:

  1. Parameter Names: When you're calling a function, inlay hints can show the names of the parameters, making it clear what values you're passing.

    • Example: myFunction(5, true) might display as myFunction(age: 5, isActive: true).
  2. Type Annotations: Inlay hints can display inferred types for variables or expressions, especially in dynamically typed languages or when type inference is being used.

    • Example: let user = getUser() might display as let user: User = getUser().
  3. Return Types: They can show the return type of a function, helping you understand what kind of value is being returned.

    • Example: function getUser() might display as function getUser(): User.


How to Enable/Disable Inlay Hints in VS Code

You can manage inlay hints via VS Code settings. Here's how:
  1. Open VS Code.
  2. Go to File > Preferences > Settings (or use Ctrl + ,).
  3. Search for "Inlay Hints."
  4. You'll see options for controlling different kinds of inlay hints (like parameter names, types, etc.).
        
Or Shortlly go to Settings and search "inlay", then you can on or off also can edit as you want 

Examples of Extensions that Support Inlay Hints:

  • TypeScript and JavaScript: The built-in TypeScript extension provides inlay hints for parameter names and type annotations.
  • C#: The C# extension (OmniSharp) provides inlay hints for types and parameter names.
  • Rust: The Rust Analyzer extension offers inlay hints for inferred types, lifetimes, and more.

Inlay hints make the code easier to understand at a glance by providing extra contextual information without cluttering the actual code.