How to debug a Scala application in VSCode
Aug 21, 2025 pm 03:36 PMYes, VSCode can debug Scala applications through Metals extension. First, install the Metals extension and import the Scala project. Make sure to enable the debug adapter and enable metals.enable-debugging-features in the settings. Then set breakpoints in the main method or test. Start debugging through the "Debug" option of F5 or the code lens. Debug parameters can be configured with launch.json to support local running and remote JVM additional debugging. During debugging, pay attention to ensuring that the code is executed and the build has been imported successfully, and finally implement variable checking and single-step execution functions similar to other IDEs.
Debugging a Scala application in VSCode is possible thanks to the Metals extension, which provides rich IDE support for Scala, including debugging capabilities. Here's how you can set up and use the debugger effectively.
Install and Configure Metals
The first step is to ensure you're using the Metals extension for Scala development in VSCode.
- Open VSCode and go to the Extensions view (
Ctrl Shift X
). - Search for "Metals" and install the official extension by Scalameta.
- Once installed, open a Scala project (sbt, Mill, or Dotty project).
- Metals will prompt to import the build. Accept this so it can index your code and dependencies.
Metals uses bsp (Build Server Protocol) to communicate with build tools, enabling features like debugging.
Enable Debug Adapter in Metals
The debugging feature in Metals relies on the Scala CLI Debug Adapter or sbp (Scala Build Protocol) support.
- Make sure you have Java 8 or 11 installed, as debugging runs on the JVM.
- In VSCode settings (
Ctrl ,
), search formetals.server.version
and ensure you're using a recent stable version (eg,0.12.0
or newer). - Confirm that "Metals: Enable Debug Adapter" is checked in the extension settings.
You can also add this to your settings.json
:
"metals.serverProperties": [ "-Xmx2g" ], "metals.enable-debugging-features": true
The enable-debugging-features
flag unlocks breakpoints, step-through, and variable inspection.
Set Breakpoints and Start Debugging
Once Metals is ready (you'll see "Imported build successfully" in the Metals log), you can debug your application.
- Open a Scala file with a
main
method or a test. - Click to the left of a line number to set a breakpoint (a red dot will appear).
- Press
F5
or open the Run and Debug view (Ctrl Shift D
). - Click "Run Debug" or create a launch configuration.
Alternatively, Metals often show a "Run" or "Debug" code lenses above the main
method or test. Click "Debug" directly from there.
If you want to define a custom launch configuration:
- Go to the Run view and click "create a launch.json file".
- Choose "Scala" as the environment.
- Add a configuration like:
{ "type": "scala", "request": "launch", "name": "Debug Main", "mainClass": "com.example.HelloWorld", "args": [], "jvmOptions": [] }
Replace mainClass
with your actual main class path.
Debugging Tips and Common Issues
Breakpoints not hitting?
- Ensure the class has a
main
method or is a test. - Make sure the build was imported successfully.
- Avoid setting breakpoints in code that doesn't execute (eg, wrong branch).
- Ensure the class has a
Debug console not showing output?
Check the "Debug Console" tab in VSCode. Standard output usually appears in the "DEBUG CONSOLE", but sometimes in the integrated terminal.Hot reload not working?
You need to restart the debug session after code changes, unless you're using a tool likesbt-revolver
(not directly integrated).Debugging tests?
You can debug ScalaTest or other tests the same way—just set breakpoints and use the "Debug" lens above the test class ortest
method.Remote debugging?
For remote JVMs, use "attach" configuration:
{ "type": "scala", "request": "attach", "name": "Attach to JVM", "hostName": "localhost", "port": 5005 }
Then start your app externally with:
sbt -jvm-debug 5005 run
Final Notes
Metals continues to improve debugging support, especially with integration from Scala CLI and better JVM tooling. While not as mature as IntelliJ's debugger, VSCode with Metals is quite capable for most debugging tasks—especially if you're already in the VSCode ecosystem.
Make sure you're on the latest version of Metals and reload the window after updates.
Basically, with the right setup, debugging Scala in VSCode works smoothly—set breakpoints, launch via code lens or launch.json
, and inspect variables just like in other IDEs.
The above is the detailed content of How to debug a Scala application in VSCode. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

ArtGPT
AI image generator for creative art from text prompts.

Stock Market GPT
AI powered investment research for smarter decisions

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ToautomaticallyformatPythoncodeinVSCode,installBlackusingpipinstallblack,installtheofficialMicrosoftPythonextension,setBlackastheformatterinsettings.jsonwith"python.formatting.provider":"black",enableformatonsavebyadding"edit

Yes,debuggingaPerlscriptinVSCodeispossibleusingthePerlDebugAdapterandPerlLanguageServerdespitelackingnativesupport.First,ensurePerlisinstalledandverifywithperl-v,theninstallthePerl::LanguageServermoduleviacpanPerl::LanguageServerorcpanmPerl::Language

To debug Python scripts, you need to first install the Python extension and configure the interpreter, then create a launch.json file to set the debugging configuration, then set a breakpoint in the code and press F5 to start the debugging. The script will be paused at the breakpoint, allowing checking variables and step-by-step execution. Finally, by checking the problem by viewing the console output, adding logs or adjusting parameters, etc., to ensure that the debugging process is simple and efficient after the environment is correct.

Yes, VSCode can debug Rust programs, but it requires installing rust-analyzer, CodeLLDB extension and lldb or gdb debugger. After configuring launch.json and setting breakpoints, you can start debugging through F5, check variables, step-by-step execution and evaluate expressions. Although it is not as convenient as JavaScript and other languages, efficient debugging can be achieved through correct configuration.

Yes, VSCode can debug Scala applications through Metals extension. First, install the Metals extension and import the Scala project. Make sure to enable the debug adapter and enable metals.enable-debugging-features in the settings. Then set breakpoints in the main method or test. Start debugging through the "Debug" option of F5 or the code lens. Debug parameters can be configured with launch.json to support local running and remote JVM additional debugging. During debugging, pay attention to ensuring that the code is executed and the build has been imported successfully, and finally implement variable checking and single-step execution functions similar to other IDEs.

Use drag and drop labels, right-click menus, shortcut keys (such as Ctrl\) or command panel to split the editor; 2. After splitting, you can form editing groups with vertical, horizontal or grid layouts; 3. Switch between groups by dragging labels or using shortcut keys (such as Ctrl 1/2/3); 4. You can adjust the segmentation size, move files between panes, and navigate errors across segmentation; 5. Use the right-click menu or the "JoinAllEditors" command to manage and merge segmentation; 6. You can configure the behavior of automatically opening files on the side in the settings; the segmentation editor is flexible, suitable for code comparison, writing and reconstruction, and can be seamlessly integrated into the workflow.

VSCode's portable mode allows running from USB drive or any folder without installing, all data is stored in local folders. 1. Download the ZIP version and decompress it to the target location; 2. Create a folder named data in the same directory as the executable file; 3. After VSCode detects the data folder, it automatically enables portable mode, and saves settings, extensions, caches, etc.; 4. Keep the environment consistent when used across devices, but be careful that the extensions relying on system tools may not work, and the version needs to be updated manually to finally realize a complete portable development environment.

VisualStudioCode supports automatic save function, which can be enabled through settings; after opening the settings, search for "AutoSave", select "Files:AutoSave" and set to "onFocusChange" or "afterDelay" and other modes. If you select "afterDelay", you can further set "files.autoSaveDelay" to adjust the delay time, or directly configure it by editing the settings.json file. After enabling it, it can effectively prevent the loss of work content without affecting the history of revocation. Finally, select the appropriate mode according to the personal workflow.
