How to debug Scala in Visual Studio Code?

1k Views Asked by At

I've created a .scala file and opened it in VS Code. I have Scala (Metals) installed which is a VS Code extension which advertises including a debugger. According to its documentation, it should integrate with VS Code's debugging features. But I can only execute my file from within VS Code with the Run Code (Control+Alt+N) command. Issuing either Start Debugging (F5) or Run Without Debigging (Control+F5) does nothing. The code lenses mentioned in the article don't appear either. Neither does the Import build prompt. Additionally, some Metals' commands don't work, resulting in an error message. E.g. for Run doctor (which I attempted, having read it's supposed to fix errors that may be present in my configuration) it says:

Command 'Metals: Run doctor' resulted in an error (command 'metals.doctor-run' not found)

I've tried reinstalling Metals but to no avail.

My software versions are:

  • Scala 2.13.6-20210529-211702-unknown
  • OpenJDK Runtime Environment (build 1.8.0_292-b10)
  • sbt 1.5.5
  • 5.15.2-2-MANJARO #1 SMP PREEMPT Sat Nov 13 19:25:38 UTC 2021 x86_64 GNU/Linux
  • Visual Studio Code 1.62.3
  • Scala (Metals) v1.10.15
1

There are 1 best solutions below

0
On BEST ANSWER

You probably have run into an issue described here: https://github.com/scalameta/metals-vscode/issues/213

I had the same problem on Win environment - no one Metals command was recognized( E.g. "Run doctor")..

Instead of open just .scala file in VS Code try to open a project directory.