4D v19 R6 brought the support of external source code editors (e.g., Visual Studio Code), allowing them to handle 4D code and provide them with standard functionalities such as syntax highlighting using the Visual Studio Code extension.
4Dv19 R7 brings two new capabilities: Go To Definition and Signature Help.
And best of all — you don’t have to do anything in VS Code; all is automatic. Just follow 4D-Analyzer updates when requested by the extension.
As these two capabilities need to reference project files, they run fine only if the opened 4DM file is placed in the project folder architecture.
Go To Definition
Like most developers, when you are reading or editing code, you often need to check the definition of a code element; with VS Code, you can do this by right-clicking on the code element. This opens a contextual menu containing a “Go to definition” menu item. Select this menu item; your cursor will be placed where the code element is defined. And if the code element is defined in another 4dm file, VS Code will automatically open the corresponding file before placing the cursor at the right place.
Code elements available for this feature are:
- process variables
- local variables
- named parameters
- project methods
- user classes
- user classes functions
In the example below, we did a right-click on a user class function and selected the Go to a definition menu item of the popup:
VS Code opened the corresponding user class file and placed the cursor at the beginning of the function:
Another capability included in 4D v19 R7 is the Signature Help of code elements.
When you place your mouse cursor on a code element, VS Code will display a tooltip containing information about it depending on its type:
- the grammar and a short description for 4D commands
- the grammar and the first mark-down comment line for project methods
- the grammar and a brief description of 4D native classes functions
- the grammar for user classes functions (from host project or component)
- the grammar and the comment placed on the declaration line for all variables
The screenshot below was taken when the mouse hovers a user class function. VS Code displays then a tooltip with function grammar:
Much better, VS Code also displays a tooltip when typing these code elements (except for variables) so that it helps you when coding!
And the cherry on the cake, the edited parameter, is highlighted in the tooltip when you type a parameter!
The screenshot below was taken when typing the second parameter of a user class function. VS Code then displays a tooltip with function grammar and highlights the proper parameter:
If you still need more information, drop us a comment on the 4D Forums.