COBOL Language Server

Important: This functionality requires a licensed version of a Micro Focus Enterprise Developer product on the same machine. See Installation for details.

A number of advanced editing and navigation features of the Micro Focus Enterprise extension are provided by COBOL Language Server - a feature available when you also have a licensed Enterprise Developer product. The COBOL Language Server features make editing and navigation in your COBOL code more similar to that of Visual Studio or Eclipse.

Features available through the COBOL Language Server

The COBOL Language Server enables the following functionality in your extension and must be running in order for them to work:

  • Context-aware code completion as you type.
  • Hover pop-ups for data items - hovering data items in the source provides a basic description of the data item.
  • Go to/Find/Peek definition and references - provide quick navigation from a data item to its definition or to other locations where the code references it.
  • Go to/Peek definition for copy statements - hover COPY statements to view their full path.
  • Collapsible regions in the editor - you can collapse sections of code in the editor.
  • OUTLINE view - a tree-view outline of a COBOL program that shows the divisions, sections, and data items defined in the program.
  • Error highlighting and reporting - compilation errors are highlighted in the editor and shown in the PROBLEMS section.
  • Rename command available across multiple files.
  • Specify a main file for a copybook.

See Scope of the Support in This Version for details about the limitations of the COBOL Language Server.

Enable the COBOL Language Server

To enable the Language Server, ensure that the Micro Focus COBOL: Install Location is set to the install location of a licensed Enterprise Developer product. Micro Focus COBOL: Language Server must also be enabled. See Additional Software Requirements.

Start or stop the COBOL Language Server

The Micro Focus COBOL Language Server status icon, , in the language toolbar status item {} in the bottom right corner of Visual Studio Code shows whether the COBOL Language Server is running:

  1. Click Options on the line for the Micro Focus COBOL Language Server.

    This shows the Task Picker with the available commands:

    • Shutdown - click this if you want to disable the Language Server features temporarily. For example, you might want to switch off the functionality for projects for which the Language Server is not supported.
    • Restart - click this to restart the Language Server.
    • Show output - click this to view any trace messages from the Language Server in the OUTPUT view.
  2. If you switched off the Language Server, click its status icon again to access the Start command.

Determine the Compiler directives

When running, COBOL Language Server determines automatically the Compiler directives for your code. As a result, the Dialect or Source format options in the status bar command are disabled and it is not possible to change them manually.

COBOL Language Server determines directives as follows:

  • It checks the source code for $set statements. This works only for the supported COBOL dialects.
  • It searches for cobol.dir files in the same directory as the source files.
  • It checks if the $COBCPY and $COBDIR environment variables are set before you launch Visual Studio Code. If any of these are set, the Language Server uses them to resolve the location of any copybooks.
  • If a project file is not available, Visual Studio Code takes the directives for background parse from the Default Directives extension setting.

In some circumstances, updating any external files does not automatically trigger a background parse of the files. To manually trigger background parse, right-click in the editor, and click Update syntax reporting.

Automatic directives determination using project files

If the workspace includes any .cblproj files, the COBOL Language Server scans the project files and any COBOL files that are listed in a project get associated with the project.

Note: A file in the workspace can only have one project association. If multiple projects reference the same file, it can only be associated with the first project that is scanned.

When COBOL Language Server is running, the Visual Studio Code status indicates the project the file you edit is associated with in the Project: projname.cblproj field.

This project association means that the background parse uses the Compiler directives and any dependency path information which is available in the project file.

Specify a main file for a copybook

If more than one COBOL programs in the workspace reference the same copybook, you can choose which main COBOL program will provide the context for the copybook. You can do this as follows:

  1. Open the copybook in the editor.
  2. In the language toolbar, click {} in the bottom right corner of Visual Studio Code next to the COBOL language item.
  3. Click Configure on the line for Context file.

    This shows the Task Picker at the top of Visual Studio Code with the list of COBOL programs available to choose as a context.

  4. Select the preferred COBOL program.

    This will be displayed next time you check the context of the copybook with the {} selector.