4D 20 R5 brings a new capability to the Visual Studio Code editor through the 4D-Analyzer extension: Say hello to Workspace Syntax Checking, designed to significantly reduce developer errors and streamline coding precision.
What is a workspace?
In VS Code, a workspace is a set of folders opened in a single window. Each workspace folder can contain one 4D project.
The workspace is valuable when using several projects simultaneously. Note that a single 4D project open in a VS Code window is considered a workspace.
Syntax checking is a way of helping developers make their code more secure.
Checking the syntax of the document being edited has been available since 4D 20.
Starting with 4D 20 R5, syntax checking can be performed on the entire current 4D project, as soon as a 4D method/class file is opened. This means you can see errors and warnings in the whole project at a glance!
Errors and warnings found in the workspace are displayed in the dedicated pane to the left of the VS Code status bar. The number of errors is on the left, and the number of warnings is on the right.
VS Code offers the option to view error and warning details. Simply click on the pane described above, and the problems pane opens. You can also open it via the “View/Problems” menu. Errors are marked in red and warnings in orange.
The problems pane displays all errors and warnings in the workspace, grouped by method file. Simply double-click on a line to open the corresponding file in the code editor pane, with the cursor positioned on the error/warning line.
It’s so easy to use!
The best part? You don’t have to do a thing—it’s all automatic. Simply open a 4D method/class file, and syntax checking is performed on the corresponding project. The same applies as soon as a modification is saved.
In VS Code, syntax errors and warnings are also displayed inline: the part of the code generating the error or warning is underlined. When you move the mouse over it, a tooltip appears, showing the same explanation of the error or warning as in the 4D code editor:
As some developers don’t like to see their code underlined by the editor, we’ve followed the example of other VS Code language extensions by making this feature optional. You can enable or disable syntax checking in the extension settings:
We’ve also added a VS Code command called “Check Workspace Syntax” for manual execution. So, if the size of your project slows down the code editor too much, you can disable automatic syntax checking or set it to check only the current document and then manually check the workspace syntax whenever you like!
We strive to provide our users with the best possible experience, and we encourage you to share your thoughts and comments on the 4D forum. Your feedback helps us understand your needs and continually improve our products and services.
Happy coding!