Skip to Content
Product Information
Author's profile photo Mariana Naboka

Tips and Tricks for Working with Annotations in CAP Projects using Language Server Protocol (LSP) capabilities

In previous posts, I described how some basic features of the Annotation LSP assist you in building SAP Fiori applications UIs with annotations. Since then, I hope you had a chance to get some hands-on experience with it and can now efficiently add and edit your annotations. In this post, I’ll give you a few tips on how to use the annotation LSP in CAP projects even more effectively and tailor it to your needs and preferences.

Tip 1. Adjust snippets verbosity

CAP CDS annotation syntax is much more flexible than that of ABAP CDS or EDMX. Often there are several ways to write an annotation in that format. For example, you can add annotations and records without providing an explicit Type, as long as it is unique per annotation vocabulary definition.
For example, the annotation snippet with explicit type definition
annotate service.IncidentStatus with @(
   UI.LineItem  : [
           $Type : 'UI.DataField',
           Value : code,
is here equivalent to that with no type definition
annotate service.IncidentStatus with @(
   UI.LineItem  : [
           Value : code,
because it is optional in CAP syntax as long as it can be uniquely derived from the vocabulary definition.
Both of these options have the same effect on your UI and there could be good reasons to use each of them.
The first option lets you clearly see that your UI.LineItem contains the UI.DataField record. The second one though is shorter and can be easier to read in a long annotation file.
By default, code completion results in snippets with more verbose syntax, as it is more transparent and thus also more convenient for the newbies. If however, you prefer shorter and cleaner code, you can always switch to the second option.
For this, go to the User Preferences and switch on the setting Omit Redundant Types in Snippets under the CDS Language Server extension.

Annotation LSP in CAP: Omit Redundant Types in Snippets

Note: Annotation and record types that cannot be uniquely derived from the vocabulary definitions cannot and will not be omitted, even if this option is selected.

Tip 2. Filter completion lists and pay attention to icons

It may sound obvious, but is still sometimes forgotten: it is much faster to find what you need if you narrow down the search area. So, filter your suggestion list by typing in a few characters, if you know what you are looking for. Even one character may filter your list considerably.
It also worth checking the icons accompanying the suggestions, especially when you need to distinguish between similarly named options that differ by the element type.

Annotation LSP: Icon Types in Code Completion

Tip 3. Resolve diagnostic issues based on severity

If you are overwhelmed with validation issues in your annotation files, you might want to concentrate on fixing the errors first and then check the warnings and info messages later. To spot them in the code more easily, just set your editor to display only errors.
For this, go to the User Preferences, find the Diagnostics Severity setting under the CDS Language Server extension and set it to Error.

Annotation LSP in CAP: Display Diagnostics by Severity

When you have your errors resolved, you can switch the setting back to display warnings (default) or even the info messages.
Note: Although the setting description mentions just compiler messages, it also refers to the annotation-related diagnostics.

Tip 4. Display i18n issues when you need it

When you develop your SAP Fiori application in CAP, you want to have it translatable to different languages. When you are satisfied with the look and feel of your app, it is time to prepare the text strings used in your annotations for translation. To quickly find the hard-coded texts that are translation relevant, you can have them highlighted with a warning indication.
For this, go to the User Preferences, and switch on the Mark Missing I18n Default setting under the CDS Language Server extension.


Annotation LSP in CAP: Display missing i18n default setting

Now you have your hard-coded texts in the language-dependent strings highlighted and can use a quick fix action to convert them to translatable texts.
Note: This setting works together with the one mention in Tip 2.
I hope these tips make it easier for you to use the LSP functionality when building SAP Fiori elements apps.
Please let me know if you have additional questions or want to share your tips with the SAP community. Just add a comment below.
For the SAP Fiori tools team, Mariana Naboka

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.