Tech Tip: Optimizing the launch.json configuration for 4D Debugger in VS Code
PRODUCT: 4D | VERSION: 20 R8 | PLATFORM: Mac & Win
Published On: February 10, 2025
With the introduction of the 4D Debugger extension for Visual Studio Code, developers can now debug 4D applications more efficiently. A key part of this setup is the launch.json file, which allows you to customize how VS Code interacts with your 4D Server. Here’s how to configure it for optimal debugging.
{
"version": "0.2.0",
"configurations": [
{
"type":"4d",
"request":"launch",
"name":"Launch 4D Server",
"project":"${workspaceFolder}/Project/${workspaceFolderBasename}.4DProject",
"program": "${workspaceFolder}/Sources/MainMethod.4dm",
"execArgs": ["--debug"],
"exec": "C:/Program Files/4D/4D Server/4DServer.exe",
"port": 19815 // server port + 2
},
{
"type": "4d",
"request": "attach",
"name": "Attach to Running 4D Server",
"port": 19815, // server port + 2
"program": "${file}"
}
]
}
For more details, refer to the official : 4D Debugger documentation
Understanding launch.json in 4D Debugger
The launch.json file is used to configure how the debugger attaches to or launches a 4D Server. Depending on your workflow, you can use one of the following approaches:- Attach: Connect to a running 4D Server instance.
- Attach and Run: Attach to an active 4D Server and execute a specific 4D method.
- Launch: Start a new 4D Server instance before debugging.
- Launch and Run: Launch a 4D Server, attach the debugger, and run a predefined method.
Essential launch.json configuration
Below is a sample configuration that includes both launching a new server and attaching to an existing one:{
"version": "0.2.0",
"configurations": [
{
"type":"4d",
"request":"launch",
"name":"Launch 4D Server",
"project":"${workspaceFolder}/Project/${workspaceFolderBasename}.4DProject",
"program": "${workspaceFolder}/Sources/MainMethod.4dm",
"execArgs": ["--debug"],
"exec": "C:/Program Files/4D/4D Server/4DServer.exe",
"port": 19815 // server port + 2
},
{
"type": "4d",
"request": "attach",
"name": "Attach to Running 4D Server",
"port": 19815, // server port + 2
"program": "${file}"
}
]
}
Best Practices for launch.json
- Use the Right request Type: If your 4D Server is already running, use "attach" instead of "launch" to prevent conflicts.
- Define the program Property: For "Attach and Run" or "Launch and Run" modes, specify the 4D method to execute immediately upon debugging.
- Customize execArgs: Add debugging options like "--debug" for more verbose output.
- Set the exec Path When Needed: If you’re working with multiple 4D Server versions, define the absolute path in the exec property.
- Check the Port Configuration: The default port is 19815, but it’s determined dynamically based on your 4D Server configuration (Application Server port + 2).
Final insights
By fine-tuning your `launch.json`, you can streamline your debugging workflow and eliminate unnecessary setup time. Whether you’re launching a new instance or attaching to an active one, properly configuring this file ensures smooth debugging in VS Code.For more details, refer to the official : 4D Debugger documentation