The following demonstration shows how you can use Visual Studio Code with the Micro Focus COBOL extension to edit, compile and debug a COBOL applications in a Docker container that has Micro Focus Visual COBOL or Enterprise Developer installed in it.
On the local machine, you only have Visual Studio Code and the sources of your COBOL application. You do not need any Micro Focus products installed locally.
An existing Microsoft technology enables you to connect your local Visual Studio Code to a container, a Linux container in this demonstration. This enables you to mount your COBOL sources from the local machine into the container, and use Visual COBOL or Enterprise Developer installed in it.
This demonstration requires the following:
First, you need to prepare your local machine, install Visual Studio Code and ensure it can connect to a Docker container. The local machine does not need a Micro Focus COBOL product installed on it.
The extension enables you to mount the sample files into the container from the local file system and use Visual COBOL or Enterprise Developer installed in the container. You then work with Visual Studio Code as if you were developing locally on your machine though the source files are now isolated inside the container.
This demonstration uses the HelloWorld demonstration supplied with the COBOL Docker images for Enterprise Developer and Visual COBOL 7.0.
For example, you can find the Program1.cbl file in the Visual COBOL Build Tools Docker image, and in the Examples\Build_HelloWorld\src subfolder supplied with the image archive.
ls -ld . * cob -vx -C anim Program1.cbl -o HelloWorld if [ "$?" -gt 0 ]; then exit $?; fi
Next, you need to add a file to your workspace that prepares it to work with a container.
This adds a devcontainer.json file inside a .devcontainer subfolder of the sample's folder.
{ "name": "COBOL DevHub", "image": "image-name", // Set *default* container specific settings.json values on container create. "settings": { "terminal.integrated.shell.linux": "/bin/bash", // Point to the install location of your Micro Focus product which is installed in the container "microFocusCOBOL.installLocation": "/opt/microfocus/VisualCOBOL" }, "extensions": [ "Micro-Focus-AMC.mfcobol" ] }
Where image-name must be the name of your image exactly as shown in Docker Desktop.
This code specifies which Docker image Visual Studio Code should use, and what settings to apply when you start it. It also installs the Micro Focus COBOL extension for you when the container starts the first time.
In this case, it sets the settings on the remote end automatically.
The microFocusCOBOL.installLocation setting indicates where the Micro Focus COBOL product is installed in the container.
The last part that has Micro-Focus-AMC.mfcobol in the extensions property will enable Visual Studio Code to install the extension from the Visual Studio marketplace when the container is created.
Now that the devcontainer.json file includes the link to the container your folder will be mounted in, you can connect your Visual Studio Code with the container.
This starts the process of reloading Visual Studio Code in container mode, starts the container with the settings you have specified, and volume mounts your local files in the container.
Click Starting in Dev container (show log) in the right bottom corner of Visual Studio Code.
If you see a Desktop - Filesharing dialog appear in the Windows task bar - click Share It.
See the messages in the TERMINAL pane showing Visual Studio Code connecting to the container. Once this is complete, check the Remote connection button - it now shows that Visual Studio Code is connected to your container.
The .devcontainer file includes the instructions to download and install the Micro Focus COBOL extension in Visual Studio Code inside the container. To check that the extension has been installed:
In order to build your application, you need to add a tasks.json file to your folder:
This creates a tasks.json inside a .vscode subfolder in your samples folder, and opens the file in the editor.
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "MyCOBOLBuild", "type": "COBOL-shell", "command": "./bld_src.sh", "group": "build", "problemMatcher": [] } ] }
This performs a build of your program inside the container.
COBDIR set to /opt/microfocus/VisualCOBOL user@adbf71521d5b:/workspaces/DockerSample> ls bld_src.sh HelloWorld Program1.cbl Program1.idy Program1.int Program1.o user@adbf71521d5b:/workspaces/DockerSample>
Debugging with Visual Studio Code in the container is the same as debugging on the local machine. You need to add a launch.json file to your workspace:
This creates a launch.json file in the .vscode folder.
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "cobol", "request": "launch", "name": "COBOL: Launch", "program": "${workspaceFolder}/Program1.int", "cwd": "${workspaceFolder}", "stopOnEntry": true }, ] }
This starts the debugger inside the container.