D365 Business Central : Inlay Hints

If you are a D365 Business Central developer who works with AL language in VS Code, one useful new feature that Microsoft has recently introduced is the support for inlay hints. Inlay hints are additional inline information in the source code that can help you understand the code better. In this blog post, I will show you how to enable and customise this feature and why it can be helpful in your AL development.

What are inlay hints?

Inlay hints are small pieces of information that appear next to the code to provide extra information about the source. In AL, this is done by showing the parameter names and return types of AL methods. This can help you understand the meaning of each parameter and return type at a glance.

Suppose you have a procedure called CreateSalesOrder, and it takes four parameters. This procedure returns a boolean.

CreateSalesOrder procedure

When you see a code calling this procedure, you don’t see the parameter names and types are, or the return type is.

You could hover over the method name or look up its definition, but that would take some time and interrupt your work. Instead, you can use inlay hints to see the parameter names and return type of the method inline.

With inlay hints, you can easily see what each parameter means and what type of value the method returns. You can also avoid errors by ensuring that you pass the correct types of values to the method and assign the result to a variable of the correct type. Inlay hints can help you write and understand code faster by providing you with useful information about the source without having to hover over the method name or look up its definition.

How to enable inlay hints?

By default, inlay hints is not enabled. You can enable inlay hints by going to the user or workspace settings. You can search for inlay hints or you can manually type the following setting.

"editor.inlayHints.enabled": "offUnlessPressed"

Enable inlay hints

There are four options available:

  • Off: Disabled
  • OffUnlessPressed: Inlay hints are hidden by default and show when holding Ctrl+Alt
  • On: Enabled
  • OnUnlessPressed: Inlay hints are showing by default and hide when holding Ctrl+Alt

Sometimes, the inlay hints can get in the way, so I prefer to set it as OffUnlessPressed.

Next, you’ll need to enable the specific inlay hints you want to use: AL parameter names and AL return types.

"al.inlayhints.parameterNames.enabled": true,
"al.inlayhints.functionReturnTypes.enabled": true

Enable Parameter or Return inlay hints

You should see the inlay hints now with the three settings.

"editor.inlayHints.enabled": "offUnlessPressed",
"al.inlayhints.parameterNames.enabled": true,
"al.inlayhints.functionReturnTypes.enabled": true,

How to customise inlay hints?

You can customize the appearance of the inlay hints in Visual Studio Code by changing some settings. For example, you can change the font family, font size, and padding.

"editor.inlayHints.fontFamily": "Fira Code",
"editor.inlayHints.padding": true,
"editor.inlayHints.fontSize": 8,

You can also change the foreground and background colors of the inlay hints by modifying the colors on workbench.colorCustomizations.

"workbench.colorCustomizations": {
    // Default Colors InlayHints
    "editorInlayHint.background": "#ffffff",
    "editorInlayHint.foreground": "#0a0a0a",
    // Parameter InlayHints
    "editorInlayHint.parameterBackground": "#00001CCC",
    "editorInlayHint.parameterForeground": "#99FFBBCC",
    // Return Type InlayHints
    "editorInlayHint.typeBackground": "#08000088",
    "editorInlayHint.typeForeground": "#DDEEFF88"
}
Customise the inlay hints appearance

Conclusion

Inlay hints are a new helpful feature. It can help you understand the code faster and more accurately by showing the parameter names and return types of AL methods. Give it a try!

thatnavguy

Experienced NZ-based NAV Developer and Consultant with 15+ years of experience leading multiple IT projects, performing business analyst, developing, implementing, and upgrading Dynamics NAV and Business Central. Passionate to deliver solution that focuses on user-friendly interface while keeping high standard of compliance with the needs.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *