Is it possible to launch a vscode extension with a set of custom settings? - visual-studio-code

I'm developing a vscode extension, and while testing it out I've hit a bit of a snag. Some functionality depends on custom settings that I define in the configuration of package.json. I would like to be able to launch a new VSCode window with the settings set to particular values, but I can't find how to do that.
What I have in launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceRoot}"
],
"ns.customSetting": "customValue"
},
{
"name": "Extension with another value",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceRoot}"
],
"ns.customSetting": "anotherValue"
}
]
}
That hasn't been working, but hopefully the idea is clear. I want that new window to open with the custom setting already set to the value I want. How do I do that?

Related

Use preLaunchTasks in flutter launch config

I am trying to run a preLaunchTask to define environment vars. The problem is that the tasks runs in a separate terminal while the flutter launch runs in the Debug Console.
Is there a way to launch the tasks in the debug console?
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "LoadEnvVars",
"command": "pwsh.exe",
"args": [
"-ExecutionPolicy",
"Bypass",
"-File",
"${workspaceFolder}/load_env_vars.ps1"
],
},
]
}
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": "makon_front (pwsh)",
"request": "launch",
"type": "dart",
"args": ["--dart-define",
"FIREBASE_WEB_CONFIG=${env:FIREBASE_CONFIG_WEB}",
"--dart-define",
"USE_FB_EMULATOR=${env:USE_FB_EMULATOR}"],
"preLaunchTask": "LoadEnvVars"
},
{
"name": "makon_front (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "makon_front (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
],
}
I have tested the actual string in dart pad, and it works fine. I have also ran const bool.hasEnvironment in the Debug Console, it returns a false. Clearly the env vars are not loading in the debug console before dart launch. How do I do that?

White window when debugging Electron forge "typescript + webpack" app from VSCode - MAIN_WINDOW_WEBPACK_ENTRY variable is not being set

I created an Electron forge project as described in the forge guide using the "typescript + webpack" template:
> yarn create electron-app debugging-test --template=typescript-webpack
The generated app works fine when running npm start. Then I wanted to configure VSCode debugger for this template so I followed the debugging section of the forge guide and created launch.json file with this content:
{
"type": "node",
"request": "launch",
"name": "Electron Main",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-nix",
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-win.cmd"
},
// runtimeArgs will be passed directly to your Electron application
"runtimeArgs": [
"foo",
"bar"
],
"cwd": "${workspaceFolder}"
}
This does not really work for me. After clicking F5 the debugger starts but it doesn't break on any breakpoints in the main process nor no window appears. Then I tried the launch.json from Microsoft's vscode-recipes:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Electron: Main",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"runtimeArgs": [
"--remote-debugging-port=9223",
"."
],
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
}
},
{
"name": "Electron: Renderer",
"type": "chrome",
"request": "attach",
"port": 9223,
"webRoot": "${workspaceFolder}",
"timeout": 30000
}
],
"compounds": [
{
"name": "Electron: All",
"configurations": [
"Electron: Main",
"Electron: Renderer"
]
}
]
}
This one, after hitting F5, starts the Electron window fine and even breakpoints in the main process are hit but no content is loaded to the window. The window is white. When breaking on line 21 in index.ts:
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
I see that the MAIN_WINDOW_WEBPACK_ENTRY variable is not set and that's why there is no content loaded to the window.
What's the correct VSCode setup to debug "typescript + webpack" electron's forge template?
I found this is a bug in Windows that is tracked here on Github. The workaround is to remove the fork-ts-checker-webpack-plugin. E.g., in webpack.plugins.js remove the new ForkTsCheckerWebpackPlugin() from the array for now until it is fixed:
//const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = [/*new ForkTsCheckerWebpackPlugin()*/];
After that debugging both, main and renderer, processes work great!

Blazor client WASM launch configuration for VSCode

Where can I find an example of the .NET Core Launch (Blazor Standalone) launch configuration? And before you refer me to this https://learn.microsoft.com/en-us/aspnet/core/blazor/debug?tabs=visual-studio-code&view=aspnetcore-3.1#vscode I have already been there. No actual example of the configuration file is present.
I struggled with this too; Just debug with ".Net Core" should be first choice; should auto generate:
{
// 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": ".NET Core Launch (Blazor Standalone)",
"type": "coreclr",
"request": "launch",
"program": "dotnet",
"args": [
"run"
],
"cwd": "${workspaceFolder}/src/Project.UI",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
{
"name": ".NET Core Debug Blazor Web Assembly in Chrome",
"type": "pwa-chrome",
"request": "launch",
"timeout": 30000,
"url": "https://localhost:5001",
"webRoot": "${workspaceFolder}/src/Project.UI",
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
}
]
}
You need to create a build task (task.json) first for the blazor WebAssembly
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/BlazorSVgTest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
]
}
And then create a launch task (launch.json) with debug enabled
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/BlazorSVgTest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
]
}
Okay, after revisiting this I now understand. in the launch.json I needed to add a line for "url": "https://localhost:{PORT}" and use the first port mentioned in Properties/launchSettings.json.
To get the browser to open I added "browser": "edge" but it does not automatically open the page so I do still need to manually navigate to the url but I can live with that. If anyone figured out how to get the working feel free to share. My launch.json looks like the following:
{
// 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": "Launch and Debug Standalone Blazor WebAssembly App",
"type": "blazorwasm",
"request": "launch",
"url": "https://localhost:7051",
"browser": "edge"
}
]
}

Flutter: add flavors configuration into Visual Studio

My flutter application has different flavors.
In Android Studio everything is setup in the flavor configuration panel, but where can I do that in Visual Studio Code?
I guess I have to edit the configuration.json but I cant find any reference online on how to do it.
I do not want every time to type flutter run --flavor app1 -t lib/main_app1.dart
You can pass additional arguments using a launch.json. If you don't already have one, click the Cog icon in the Debug sidebar and then select Flutter in the snippet-completion list. You can then add an args section, like this:
{
"name": "Flutter",
"request": "launch",
"type": "flutter",
"args": [
"--flavor",
"app1"
]
}
You have to edit your launch.json file
{
"name": "dev", // you can add nickname for it
"request": "launch",
"type": "dart",
"args": [
"--flavor", //flavor name
"dev",
"-t", // if your have different main file
"lib/main_dev.dart"
]
},
{
"name": "App Dev",
"cwd": ".",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
"program": "lib/main_dev.dart",
"args": ["--flavor", "dev"],
}

Running two projects at once in Visual Studio Code

I develop web project. Server is node.js application written in TypeScript. Client also written in Typescript. I need two ability:
to compile different projects with different compiler options in different folders.
to debug both projects at the same time.
How can I do this?
See our documentation on multitarget debugging: https://code.visualstudio.com/Docs/editor/debugging#_multitarget-debugging
In your launch.json, just create a compounds section that contains the targets you want to debug
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Server",
"program": "${workspaceRoot}/server.js",
"cwd": "${workspaceRoot}"
},
{
"type": "node",
"request": "launch",
"name": "Client",
"program": "${workspaceRoot}/client.js",
"cwd": "${workspaceRoot}"
}
],
"compounds": [
{
"name": "Server/Client",
"configurations": ["Server", "Client"]
}
]
}