VS Code / Metals: How to debug Scala sbt project using remote Debugger? - scala

I know the question has been asked before in some variation here, but I simply can not figure out how to debug my scala sbt project in VS Code (WSL). Can someone provide some detailed instruction on how to do that ? What does it mean to debug using (java) remote Debugger ?
When I run Metals doctor, it says that it can not even detect the build tool. From the terminal however I am able to run/compile the code just fine (F.e. saying sbt "testOnly *IngestionTaskTest").
I addded the following launch.json file after entering >Debug: Select and Start Debugging in command Pallette:
"version": "0.2.0",
"configurations": [
{
"type": "scala",
"request": "launch",
"name": "somename",
"mainClass": "somepackage.SparkMain",
"args": [],
"jvmOptions": []
}
But I receive Class: sompackage.SparkMain not found

Ok I found out how to do it. These are the exact steps:
1.) Configure launch.json manually. First go to command pallette and say >Debug: Select and Start Debugging in command Pallette
2.) Then edit launch.json to look like this:
"version": "0.2.0",
"configurations": [
{
"type": "java",
"request": "attach",
"name": "gqd debugger",
"hostName": "localhost",
"port": "8000",
}
]
}
4.) Enable sbt debugger in build.sbt by adding the following line: Test / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"
5.) In the bash terminal say sbt Test/testOnly theTest
6.) Wait a few seconds until project & settings are loaded. Then press putton F5
(Tests refers to my unit tests). Hope it helps.

Related

How to debug a Singer Tap using VS Code

In creating new Singer Taps using the Meltano SDK, it's not always clear how to setup testing in VS Code.
What's the best way to get the VS Code test features working?
First Method: Unit testing with VS Code "Tests" pane
This method makes unit tests (pytest tests) easy to run in the VS Code "Tests" pane.
Prereqs:
Python is installed on your machine.
The Python VS Code extension is installed.
You've run poetry install at least once.
You've set the Python interpreter to the Poetry environment via: "Command Palette" > "Python: Select Interpreter" and then select the matching Poetry environment.
Once the above are complete, the "tests" pane should populate with the list of unit tests and you'll have an option in the VS Code GUI to "Run" or "Debug" each test.
Second Method: Integration test by actually invoking the tap
This method actually runs your tap and sends the output to target-json or a similar sample target.
Prereqs:
Add a main to the bottom of your tap.py to make it invocable:
if __name__ == "__main__":
TapGoogleAnalytics.cli()
Install target-jsonl via pipx install target-jsonl or similar.
Replace tap_foobar with the actual name of your tap's library and then paste this into VS Code's launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/tap_foobar/tap.py",
"console": "integratedTerminal",
"args": ["--config", ".secrets/config.json", "|", "target-jsonl"],
"env": { "PYTHONPATH": "${workspaceRoot}"}
}
]
}

How to set up tasks.json file in VSCODE to compile Fortran programs?

I want to set up VScode (OS: Windows 10) to create and then compile programs written in Fortran 90/95. I can do this by typing in the terminal : gfortran -o Example_exe Example.f90 and then ./Example_exe. I don't want to have to write these lines every time, so I tried to set up my tasks.json file to automate a build routine using gfortran as compiler.
I found this tutorial : https://titanwolf.org/Network/Articles/Article?AID=360e0bde-0507-4de4-960c-2eae8fa8c782#gsc.tab=0 but the tasks.json file given is unclear.
Can I have a tasks.json file setup to automate my build routine please ?
I have installed the following extensions : Modern Fortran, Fortran IntelliSense, Code Runner, Fortran Breakpoint Support
Yes you can. Assuming that you want to execute in debug mode, you should create a tasks.json and a launcher.json and place them in .vscode/ at the root of your workspace.
Assuming the following file structure and a debugging mode with GDB for the execution:
root/
.vscode/
code/
Example_exe
This is what your tasks.json should look like:
{
"version": "2.0.0",
"tasks": [
{
"label": "compile",
"type": "shell",
"command": "gfortran -o Example_exe Example.f90 -g",
"options": {
"cwd": "code/"
}
}
]
}
And then, the launch.json, which will identify tasks.json as a "preLaunchTask".
{
"version": "0.2.0",
"configurations":[
{
"name": "Run my example",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\code\\example_exe.exe",
"args": ["],
"stopAtEntry": false,
"cwd": "${workspaceFolder}\\code",
"miDebuggerPath": "gdb.exe",
"preLaunchTask": "compile",
}
]
}
Launch the debugger by pressing F5 (or in the Run menu).
If you don't want to run in debug mode, have a look at this issue.
Sources:
How to build and run C++ code in Visual Studio Code?
awesome tutorial (for ubuntu, working for me with VSCode-gfortran-Win10)
https://www.youtube.com/watch?v=Rj-kYb9nZ3g&ab_channel=LukasLamm.

How to integrate VSCode with pytest ('test discovery fails')?

I'm unable to integrate my project's unit tests into VSCode. Test discovery fails because source files are not recognized by pytest.
(Just for clarification, this is a question about VSCode, not about pytest. I'm here because VSCode links its question section to SOF. Tests work fine if I run them manually.)
Tooling: pyenv, pipenv, pytest.
Project layout:
/src -> source code
/tests/unit -> test code
.vscode/settings.json:
{
"python.envFile": "${workspaceFolder}/.env",
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false
[...]
}
.env:
PYTHONPATH=./src
(Note: I don't think .env matters here, as per this comment, under Use of the PYTHONPATH variable)
Test discovery fails with:
tests/unit/test_revoke_default_sg.py:7: in <module>
from revokedefaultsg.app import RevokeDefaultSg, UnknownEventException
E ModuleNotFoundError: No module named 'revokedefaultsg'
=========================== short test summary info ============================
ERROR tests/unit/test_revoke_default_sg.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.08s ===============================
This is caused by ./src not being part of the python path, so tests cannot import source code.
I can fix this on CLI/makefile level by adding to PYTHONPATH:
PYTHONPATH=./src pytest
This works as expected.
What's the correct setup for VSCode?
Am I supposed to create a launch configuration for testing? I've started to look into this, but couldn't get it to work nicely with pipenv.
(OP here)
I think the key to integrate into VSCode creating a specific launch configuration for pytest (before, I only had the default launch configuration that's been created with the Python extension).
I now have two configurations (.vscode/launch.json):
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Run Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "./src"
}
},
{
"name": "Python: pytest",
"type": "python",
"request": "launch",
"module": "pytest",
"cwd": "${workspaceRoot}",
"env": {
"PYTHONPATH": "./src"
},
"envFile": "${workspaceRoot}/.env",
"console": "integratedTerminal",
}
]
}
(project on GitHub)
Running this configuration after launching VSCode discovers tests correctly, without raising errors. However, I have not tried it out in different projects yet.
Also, maybe I didn't find the right section of the VSCode documentation, but this feels heavily under-documented. I ended up searching GitHub for gists with launch configs and copied together whatever seemed vaguely helpful...

VSCode Junit output not displaying

I'm running Ubuntu 18.04 and just installed VSCode 1.35.1. I installed the Java packages, created a project from maven, and then tried to run the unit tests. The tests run, but none of the print messages are showing anywhere.
My launch.json looks like this,
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch) - Current File",
"request": "launch",
"mainClass": "${file}",
"console": "integratedTerminal"
},
{
"type": "java",
"name": "Debug (Launch)-App<ttt>",
"request": "launch",
"mainClass": "exercises.App",
"projectName": "ttt",
"console": "integratedTerminal"
}
]
}
When I run with F5 or Ctrl-F5, it always runs the main App. When I go to my test file and click on the Run|Debug links, the tests run and generate reports, but I don't see any of the print messages I put in.
What do I need to setup differently?
The Test Output is in the Java Test Runner Output.
You can highlight it with the "Java: Show Test Output" command in the F1 menu
With VSCode 1.64 (Jan. 2022), you won't have to look for that view anymore when launching a debug session.
It allows for VS Code to automatically switch to test explorer when users click 'run tests'.
See issue 140596 / issue 135999, solved by commit a47b55c
You now have the options:
NeverOpen = 'neverOpen',
OpenOnTestStart = 'openOnTestStart',
OpenOnTestFailure = 'openOnTestFailure',

issues debugging polymer straight from IDE/edit tool

I am quite new to Polymer and I would like to be able to debug projects straight from one IDE. I mean, instead of using Chrome debugger, I would prefer debug from Visual Studio Code or Sublime or Atom or another tool (kindly, there is no interest in this question to compare the IDEs available. I just want some way to debug from any IDE).
All subjects I have read so far didn't me drive to any real tutorial which could help me. The only one I found I couldn't make it run.
I followed https://medium.com/collaborne-engineering/debug-polymer-tests-with-vs-code-7646d66d0608 and when I try Run WCT I get Attribute 'program' doesn't exist.
My launch.json is
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run wct",
"program": "${workspaceFolder}\\my-company-component.html",
"args": [
"-p",
"--skip-plugin", "local",
"--plugin", "none",
"--webserver-port", "2000",
"--expanded",
"--simpleOutput", "${workspaceFolder}"
]
},
{
"type": "chrome",
"request": "launch",
"name": "Run chrome for wct",
"url": "http://localhost:2000/components/my-company-component/generated-index.html",
"webRoot": "${workspaceRoot}",
"userDataDir": "${workspaceRoot}/.vscode/chrome"
}
]
}
Today, I have been using gulp to start a local server and then debug using Chrome but, in case it is possible use an IDE + some extension/plugin I would prefer.
program should be either 'wct' if you installed it with -g or
"${workspaceRoot}/node_modules/.bin/wct" if you installed it locally using npm.
That should solve your error, I did not get the other parts to work still though..
Well, after several tentatives and searching for while, I assume that the only way to debug is by using Chrome. I mean, I didn't find any efficient way to debug using Visual Studio Code, Atom or other IDE. I will consider https://github.com/Polymer/polymer/issues/3635 as an answer to my question.