debug spring project with specific profile on visual studio code - spring

I'm trying to debug a kotlin/spring project in vscode, but I can't find a way to activate the desired profile.
My launch.json file looks like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "kotlin",
"request": "launch",
"name": "Kotlin Launch",
"projectRoot": "${workspaceFolder}",
"mainClass": "my.package.ApplicationKt",
"args": [ "--spring.profiles.active=dev" ]
}
]
}
The app starts but with no active profile. I've seen a lot of answers with different combinations: using vmArgs instead of args, "-Dspring.profiles.active=dev" or [ "--spring.profiles.active", "dev" ] or [ "-Dspring.profiles.active", "dev"] but nothing seems to work.
I'm using VSCode 1.63.0 with kotlin 1.5.30 and spring boot 2.4.4.

I finally figured it out thanks to autocomplete.
VSCode documentation is not ok. All the examples and documentation points to vmArgs option where, supposedly, I could set my -Dspring.profiles.active=dev, but that's not the case, at least for the versions I'm working on.
The correct option is not vmArgs but vmArguments instead.

Related

Cannot debug Rust in Visual Studio Code?

I am trying to debug a Rust program in VS Code, but I get an error:
After clicking OK, VS Code opens "settings.json":
I have these extensions installed:
My program is a simple "hello world" app.
Unfortunately VS Code can't debug Rust out of the box :( But no need to worry, just few steps of configuration will do the work :)
Steps
Install C/C++ extension if you are on windows and CodeLLDB if on OS X/Linux
Click Debug -> Add Configuration, a launch.json file should open, you need to change the program name here manually
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/target/debug/foo.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true
},
{
"name": "(OSX) Launch",
"type": "lldb",
"request": "launch",
"program": "${workspaceRoot}/target/debug/foo",
"args": [],
"cwd": "${workspaceRoot}",
}
]
}
Make sure Allow setting breakpoints in any file is checkend under File -> Preferences -> Settings
For detailed steps and more you can refer the article I used to answer this
Credits- Forrest Smith
From your screenshots, you're on Windows, so here's how to proceed. This assumes you already took care of the basics:
VsCode has the recommended rust-analyzer extension installed.
Your project folder was initialized with cargo init. (Your project's folder name must be the same as the name of your package in Cargo.toml.)
You can cargo run from within your project directory and it works.
As indicated by various locations on the 'Net, you need to install another VsCode extension to make it so you can debug. Since you're on Windows, you want to use the MS C++ DevTools extension for VsCode, instead of the CodeLLDB one.
Next, you need a "launch" configuration setup. Select VsCode's Run >>> Add Configuration... menu item. Choose the C/C++: (Windows) launch option in the drop-down. You'll now have a launch.json file with a single configuration object.
You'll need to change the program property to "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe"; this depends on your package name being the same as the project folder's name. (I also changed the cwd property to "${workspaceFolder}", though I'm not sure it matters.) To be clearer, here's the configuration I have presently in my launch.json file (the preLaunchTask property is for later):
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe",
"preLaunchTask": "rust: cargo build",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal"
}
At this point, as long as you've already built your project at least once, you can hit F5 and debug.
If you want F5 to also save your changes and rebuild your project before debugging, then you also have to add a build task and configure it to run before debugging starts.
To do that, add the build task by opening the Show All Commands box (either F1 or Ctrl+Shift+p) and choosing Tasks: Configure Task. Select rust: cargo build. It'll create a tasks.json file next to your launch.json; the defaults are all you need. My file looks like this:
{
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"command": "build",
"problemMatcher": [
"$rustc"
],
"group": "build",
"label": "rust: cargo build"
}
]
}
Then, to hook everything up, you just need to manually add the preLaunchTask property to your launch configuration with a value equal to the label in your task. E.g. "preLaunchTask": "rust: cargo build",, like what I have in my example launch.json up above.
At this point, whenever you press F5, VsCode will save your work, rebuild your project, then start debugging it.
Visual Studio Code is a general editor, but it can be configured to debug rust code.
Step 1.
Assuming that Visual Code, rust and cargo are installed, the first step is to enable the required extensions:
rust-analyzer
CodeLLDB
These only need to be installed one.
Step 2
The second step is to create the rust code. I have a folder called Rust, in which I keep the rust code. Changing to that folder, I use cargo new hello_world to create a new rust project.
Step 3
The third step is to change the folder for the project. There are two plausible options, but only one of them will work.
I changed to my Rust folder, and then I can edit the source code by following ``hello_world - src`.
To debug the code, it is necessary to create a launch.json file, using Run - Add configuration... However, the file isn't correct, with <your program> where the correct name should be. This is the wrong approach.
{
// 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": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/<your program>",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
The documentation is a bid thin at this point. The correct approach is to pick a different folder, the top level of the project hello_world. The Cargo.toml file is available.
Now, when Run - Add configuration... is used, and the option of LLDB is selected -
the Cargo.toml file can be picked up -
and then the Cargo.toml file is used to correctly build the launch.json file -
{
// 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": "lldb",
"request": "launch",
"name": "Debug executable 'hello_world'",
"cargo": {
"args": [
"build",
"--bin=hello_world",
"--package=hello_world"
],
"filter": {
"name": "hello_world",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'hello_world'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=hello_world",
"--package=hello_world"
],
"filter": {
"name": "hello_world",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
Now, both Run - Start debugging and Run - Run without Debugging both work properly.

"You don't have an extension for debugging 'JSON with Comments'" warning when debugging VS Code theme

I generated the files necessary for creating a color theme in VS Code. I did this with the generator-code node package.
My file structure is as follows
When I run VS Code's debugger, I get this warning that prevents the debugger from running.
Here are the contents of my launch.json file for reference:
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
}
]
}
In case you're wondering what I'm expecting to happen when I run the debugger, here's the moment in the tutorial I was following where I ran into this problem.
Edit: Well, I evaded the problem somehow by deleting the files and starting over. I'm not sure what was causing the problem before.
This popup only appears for me when trying to launch the debugger while having the launch.json or tasks.json file open. Switching to one of my test files and launching the debugger fixes it
I had this error when my launch.json was not according to the version + configurations scheme, I copy pasted the content of configurations to the file instead of putting it in the array.
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
}

Visual Studio Code + Spring Boot Project change spring.properties.additional-location etc

Recently i decided to pass from Eclipse to VS Code , everything is running smoothly for Javascript development but for Spring Boot applications i don't know how to configure them here .
Except of the application.properties file i have one more extra local.properties which i use to run locally the Spring Boot Application .
I see there is a launch.json file :
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - fmApplication",
"request": "launch",
"mainClass": "com.application.zz.app.fmApplication",
"projectName": "file-manager"
}
]
}
In Eclipse i am adding additional configuration to run my Spring Boot Application like shown below :
How can i do that is Vs Code :) ?
Here is the issue on Vs Code Github Page
Unlike JavaScript, Java code needs to be compiled so it wont work out of the box with visual studio code since it's just a glorified text editor.
There are however multiple tools to accommodate for this, and the folks at VS code
have a nice guide for setting you up - https://code.visualstudio.com/docs/java/java-spring-boot
Solution :
So you have an application.properties file and locally you have a application-local.properties(attention , you must name your local properties like that).
Then in your launch.json you add it to your program parameters :
"args": "--spring.profiles.active=local"
So your launch.json file will look like this for example :
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - fmApplication",
"request": "launch",
"mainClass": "com.intralot.l10.app.fmApplication",
"projectName": "file-manager",
"args": "--spring.profiles.active=local"
}
]
}

How to debug iOS react-native app when using visual studio?

I have recently started working on an iOS app that uses react-native. I'm using Visual Studio Code for writing javascript/typescript code. I would like to debug javascript and swift code in parallel.
I have tried using "Start debugging" option in VSCode but it doesn't help me in debugging the Swift code and it seems to fail at times.
I have tried looking at forums and posts but to no avail.
This is what my configuration (launch.json) file looks like:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug iOS",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "ios",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
}
]
}
I am not sure what is the correct setup for debugging Javascript (VSCode) and Swift (Xcode) simultaneously. Any help is appreciated.

Is there way to open DEBUG CONSOLE tab after starting debugging with specified preLaunchTask?

I have debug configuration with preLaunchTask:
{
"type": "node",
"request": "launch",
"name": "index.js - Build then launch",
"program": "${workspaceRoot}/node/dist/index.js",
"cwd": "${workspaceRoot}/node",
"preLaunchTask": "build"
}
And when I start debugging, vscode opens OUTPUT tab instead of DEBUG CONSOLE:
Is there way to open DEBUG CONSOLE after starting debugging? I wanted to create extension with interact with DOM UI, but it turned out that extensions dont have access to DOM UI.
You can set "internalConsoleOptions": "openOnSessionStart" in your launch config to always show the console after starting a debug session.
"internalConsoleOptions": "openOnSessionStart" is not sufficient for python launch configs.
It also requires
"purpose": [
"debug-test"
],
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": [
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": [ //
"debug-test"
],
"console": "integratedTerminal",
"justMyCode": false,
"internalConsoleOptions": "openOnSessionStart"
}
]
}
Is there way to open DEBUG CONSOLE after starting debugging?
As another alternative, VSCode 1.70 (July 2022) offers:
Changing Quick Access for Debug Consoles to Debug Sessions
Quick access menu for debug consoles just lists your debug consoles, but the view menu pretty much lists the same.
Before: Quick access for debug consoles:
VScode 1.70: The quick access should actually just list the debug sessions like the call stack does.
See PR 153727, released today in VSCode insiders.
This can be accessed with the command Select Debug Session
It would look like this (but as a regular quickpick, not a quick access anymore):
for this tree structure:
Or for something different like python (where there are no compact debug sessions):
tree structure:
The structure is pretty generic to support any type of debug session.

Resources