Metals announced that "It is now possible to run and test directly from VS Code using the new "Run", "Test", "Debug" and "Debug test" buttons." There is a nice gif showing what it can do, and I don't know how to get to that point.
I tried to launch VS Code debugger with the following configurations in launch.json
{
// 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": "scala",
"request": "launch",
"name": "Untitled",
"mainClass": "com.playZip.Unzip",
"args": [],
"jvmOptions": []
}
]
}
and got this error message:
Couldn't find a debug adapter descriptor for debug type 'scala' (extension might have failed to activate)
Somebody on Gitter scalameta/metals had this problem and the answer was that he needs Bloop to support utest and I think mine does because there's a file .bloop/play-zip-test.json in my sbt project, but I'm not 100% if my Bloop supports utest and what to do if it doesn't. I tried running bloop utest and it failed because I don't have Bloop CLI installed. I have Bloop that comes with Metals.
Document how to run or debug applications #2005 added official debugging documentation at Running and debugging your code which documents two approaches
via code lenses run | debug
via a launch.json configuration
Here is a hello world example how to debug a test using VSC and Metals via launch.json approach. We will use
lihaoyi/utest library and set a breakpoint in a test.
Execute sbt new scala/scala-seed.g8 to create correct project structure
Open... sbt project with VSC or simply cd into project and execute code .
Replace ScalaTest with utest in build.sbt
libraryDependencies += "com.lihaoyi" %% "utest" % "0.7.2" % "test",
testFrameworks += new TestFramework("utest.runner.Framework")
Replace test/scala/example/HelloSpec.scala with HelloTests.scala
package example
import utest._
object HelloTests extends TestSuite{
val tests = Tests{
test("test1"){
1
}
}
}
Import sbt build with View | Command Palette... | Metals: Import Build
Put a breakpoint at line 8 and click Run and Debug
Select Test Suite for Pick the kind of class to debug
Leave empty for Enter the name of the build target
Write example.HelloTests for Enter the name of the class to debug
Write Debug example.HelloTests for Enter the name of configuration
This should create .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "scala",
"name": "Debug example.HelloTests",
"request": "launch",
"testClass": "example.HelloTests"
}
]
}
Now you should be able to Start Debugging by clicking the green triangle and stop at the breakpoint
Not sure if your problem is solved, but I did see the same issue before. To get more information about the error, you can check the Metals output. See the picture below:
From the output tab, select Metals. More detail of the error should be available.
In my case, the reason I got this error (Couldn't find a debug adapter descriptor for debug type 'scala' (extension might have failed to activate) ) is because the Java installed in my machine does not support JDI.
Message: Debugging is not supported because bloop server is running on a JRE /usr/lib/jvm/java-8-openjdk-amd64/jre with no support for Java Debug Interface: 'JDI implementation is not provided by the vendor'. To enable debugging, install a JDK and restart the bloop server.
I guess your case is probably the same. To solve it, just install a Java implementation supports JDI. For example, openjdk version "11.0.8" 2020-07-14 works fine with Metals on Ubuntu. You can do this to install it.
$ sudo apt install openjdk-11-jdk
If it still not works, make sure Metals: Java Home in VS Code settings points to the right Java version.
I ran into this same problem and it came down to the buildTarget. I have a multiple module project. When I looked at the metals logs this is what I saw:
Caused by: scala.MatchError: scala.meta.internal.metals.debug.BuildTargetNotFoundException: Build target not found: (of class scala.meta.internal.metals.debug.BuildTargetNotFoundException)
My Scala project
/client_accounts
/migrations
/app
Updated the launch.json to "buildTarget": "app", and it worked. Error reporting could be a bit better.
So if you get this error look at the logs for the root cause.
Related
Because of the enormous compilation time on my personal laptop, I decide to compile the .c code on a remote, much more powerful server. So I clone the project repository on the server and compile the target with a makefile, as I would do on my computer.
I send the .elf file back to my laptop and when I try to run debugging on Vscode, a main.cdasm file opens instead of the file I expected to see. The code works as expected, it's just the display on Vscode that is wrong.
Result expected :Debugging result when compiling on my laptop.
Result obtained :
Debugging result screen when compiling remotely
I guess there is a configuration on Vscode to change the location of the debugging entry point. Or maybe, there is a compiler option to change the default location of the .elf and start debugging in the right location.
A part of my json configuration :
"type": "cortex-debug",
"request": "launch",
"name": "LE00 | RAM", //name of the configuration
"cwd": "${workspaceRoot}",
"executable": "${input:elfFile}",
"servertype": "jlink",
"device": "ATSAML10E16A", //name of the device (need to be referenced by JLINK)
"interface": "swd",
"serverArgs": [
"-vd", //Verify after downloading
],
Can someone help me to configure the debugging console when the .elf (and thus the compilation) is done remotely?
In advance, thank you
Class not found exception in Visual studio code because vs-code debug takes output class files form bin directory like eclipse but i am using GRADLE for build so MapperImpl.java which is implementation files in mapper are created in the build folder i don't know how to solve the issue i tried to change the classpath all the solutions i tried but nothing working please i need your help
I am also posting the vs code file launch.json
{
"type": "java",
"name": "Debug (Launch)-Application<RestApi>",
"request": "launch",
"mainClass": "ae.org.nge.Application",
"projectName": "RestApi",
"vmArgs": "-DngeConfig=C:/Users/Manoj.Dhayalan/source/myapp/Application/config/myapp-config.properties -Dserver.port=8081 -Dspring.profiles.active=dev"
}
I don't use Visual Studio Code but I managed to change the location of generated class file by putting this lines into my build.gradle file:
compileJava {
options.setAnnotationProcessorGeneratedSourcesDirectory(file("$projectDir/src/main/generated"))
}
This way gradle will generate MyMapperImpl in src instead of build folder and it should be also recognized by VS Code.
I'm struggling with setting up environment for old tech project with PHP5.
My OS is Windows and I have installed so far VSCode plugins: PHP Debug, PHP Intelephense, PHPUnit, PHPUnit Test Explorer.
I downloaded phpunit-5.7.27.phar and configured VSCode according to documentation.
Settings.json
{
"php.validate.executablePath": "C:/wamp64/bin/php/php5.6.40/php.exe",
"phpunit.phpunit": "C:/wamp64/bin/php/php5.6.40/phpunit-5.7.27.phar",
"phpunit.php": "C:/wamp64/bin/php/php5.6.40/php.exe",
"intelephense.environment.phpVersion": "5.6.40",
"intelephense.environment.includePaths": [
"C:/wamp64/bin/php/php5.6.40/phpunit-5.7.27.phar",
"C:/wamp64/bin/php/php5.6.40/php.exe",
"C:/wamp64/bin/php/php5.6.40/"
]
}
Launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"xdebugSettings": {
"max_children": 256,
"max_data": 500,
"max_depth": 3
}
},
]
}
What works for me fine is breakpointing on running app with xdebug and running unittests with Cmd+Shift+P.
What I need help with are as follows:
Code editor shows error for PHP unit classes and methods (even though unittests are executing fine as is). Do I need to add to path something besides phar file? Is VSCode non-compatible with phar files? The same happens for PHPUnit\Framework\TestCase.
I can't figure out how to configure Test Explorer plugin to show nicely tests tree. Does it require some configuration in Launch.json? Launching tests with Cmd+Shift+P displays results only in terminal.
PHP Intelephense requires installed PHPUnit with composer in workspace.
composer require --dev phpunit/phpunit
PHPUnit Test Explorer has by default Phpunit: Files setting set to {test,tests}/**/*Test.php, so changing it to proper glob should allow plugin to detect all tests.
I want to debug my scala app with vscode.
My gradle run task looks as simple:
task run(type: JavaExec, dependsOn: build) {
debug true
main = mainClassFile
classpath sourceSets.main.runtimeClasspath
classpath configurations.runtime
}
The launch entry:
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 5005
}
Now when I launch the debugger, it waits for the vscode client.
But I am not able to set any breakpoints in vscode in order to stop the debugger. For now it runs until the end, after vscode connected.
I am using the Scala and Scala Language Server.
Does someone know how to add breakpoints?
Latest release of Scala Metals (0.8.0) has a debug support - the release has an animation showing usage of debugging in Visual Studio Code, which works the same way as debugging in other languages.
This is an initial support so some cases might not be supported (see "known limitations" in the release notes of Metals 0.8.0), but you should be able to start using them.
Before that debugging was simply not supported by Scala Metals, and everyone writing Scala in need of such feature was recommended to use IntelliJ with Scala plugin.
I try to set up a launch.json for a vagrant-plugin on windows. My current version look like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Vagrant",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/vagrant",
"args": ["up"],
"env": {
"VAGRANT_CWD": "${workspaceRoot}/development"
}
}
]
}
When starting the plugin now, vagrant misses the external dependencies. So I get the error:
The executable 'curl' Vagrant is trying to run was not
found in the %PATH% variable. This is an error. Please verify
this software is installed and on the path.
Adding the needed dependencies to my path sound like trouble (cp.exe, dir.exe, ...).
I tried:
"env": {
"PATH": "/HashiCorp/Vagrant/embedded/bin;${PATH}",
"VAGRANT_CWD": "${workspaceRoot}/development"
}
But then i get Debugger terminal error: Process failed: spawn rdebug-ide.bat ENOENT.
Is there a way the expend the PATH environment Variable in the launch.json?
For the question of:
Is there a way the expend the PATH environment Variable in the
launch.json?
From the documentation:
You can also reference environment variables through ${env.Name} (e.g.
${env.PATH}). Be sure to match the environment variable name's casing,
for example env.Path on Windows.
At: http://code.visualstudio.com/docs/editor/tasks#_variable-substitution
For example I often use this for Ruby apps in my launch.json in Visual Studio Code:
...
"pathToBundler": "${env.HOME}/.rvm/gems/ruby-2.3.0/wrappers/bundle",
...
#sschoof If you are trying to run VS Code from the windows host machine I'd suggest reading this post.
I've current just started configuring a development workspace for use with nodejs, VS Code, and Azure using my Mac OSX host. My solution is working but I have not a done a windows implementation so I currently cannot offer more experienced advice.