VSCode - how to keybind an external command - visual-studio-code

Im trying to run "puppet-lint -f (currently open file)
The Puppet extenstion provides puppet-lint check, but doesnt auto fix any issues, it just gives warnings. How can I add a keyboard shortcut to run "puppet-lint -f" on a file Im currently editing?
Thanks

I don't know anything about the Puppet extension but in general here is how you can bind a shell command to a keychord:
Make a task for it (.vscode/tasks.json):
{
"version": "2.0.0",
"tasks": [{
"label": "node version",
"command": "node",
"args": [
"-v"
],
"type": "shell"
}]
}
In the args you may use ${file} for the current file.
Then add this option to your keybindings.json (you can find them in Command Palette under “Preferences: Open keyboard shortcuts (JSON)”):
{
"key": "shift+escape",
"command": "workbench.action.tasks.runTask",
"args": "node version"
},

co-author of the extension here. You can have the Puppet VSCode Extension run puppet-lint fix on the current file by using the Format Document command. You can then configure VSCode to run format on save.

Related

What is the flutter command to clear app data?

Sometimes we need to run app by clearing app data and cache. It is a hassle to do it manually every time going to setting screens.I saw maximum stack-overflow answers recommending it programmatically but I don't need it. Is there any flutter command or plugin to do that?
There is actually no flutter command to clear app data.
However, you could use prelaunch tasks to run shell command before launching your app.
You must have adb command in your environment PATH variable for Android apps
For example, in VsCode, you can add a task in the tasks.json file like this :
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "clear app data",
"type": "shell",
"command": "adb shell pm clear com.package.app || true;xcrun simctl uninstall booted com.package.app",
"problemMatcher": []
}
]
}
Then, add the preLaunchTask in your launch.json file like this :
{
// 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": "my_app",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"preLaunchTask": "clear app data",
}
]
}
I don't know how to do this in IntelliJ but I'm sure you can do the same thing

How to add --no-sound-null-safety on a single run/debug on vscode (Flutter)?

On vscode, when try run or debug using "Run" or "Debug" button, the runner doesn't add --no-sound-null-safety argument.
How to configure vscode to add --no-sound-null-safety argument?
If using vscode. create .vscode/launch.json in project root and add
"args": [
"--no-sound-null-safety"
]
complete code :-
"version": "0.2.0",
"configurations": [
{
"name": "YOUR_PROJECT_NAME",
"program": "lib/main.dart",
"request": "launch",
"type": "dart",
"args": [
"--no-sound-null-safety"
]
}
]
}`
For IDE run arguments/configuration
Search for "Flutter run additional args"
in your user settings and add --no-sound-null-safety .
Paste the command in the item field and click ok as we already added one command.
For Test configuration
Search for "Flutter test additional args" in your user settings and add --no-sound-null-safety . Do the same process as on the above picture and add this command.
after all, you will be able to run unsound null or hybrid apps with debug button
I added these items to the settings.json file.
{
"dart.flutterTestAdditionalArgs": ["--no-sound-null-safety"],
"dart.flutterAdditionalArgs": ["--no-sound-null-safety"],
"dart.vmAdditionalArgs": ["--no-sound-null-safety"]
}
follow these instruction
Goto:
File -> Preferences -> Settings
Then search:
Flutter run additional args
Then Add new arg like this
--no-sound-null-safety
Then simply run
Also can follow image
then do this

How to use a remote python interpreter in remote development - ssh in VSCode

Microsoft recently released remote development support for SSH.
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh
However, in python, if you click "select python interpreter". The interpreter available to be chosen is only for a set of python interpreters in anaconda.
The interpreter available to be chosen are in:
~/anaconda3/*
/usr/bin/python
I have a custom python interpreter in a custom location. My interpreter is in ~/projects/myproject/bin/python
How do we configure a remote python interpreter by giving it a path?
Note: I have configured setting.json
"python.pythonPath": "${workspaceFolder}/bin/python",
But it does not seem to respect it
managed to make it work with
update vscode
my files:
# settings.json
{
"python.pythonPath": "/custom/bin/python"
}
# launch.json
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"pythonPath": "${config:python.pythonPath}"
},
...
restarted vscode
F1 -> select Interpreter

Use Visual Studio Code Tasks with Gulp 4.0

I am in the process of switching a project from Gulp 3.9.1 (npm install gulp) to Gulp 4.0 (npm install gulp-4.0.build), but when I do this, Visual Studio Code is no longer able to auto-detect the tasks in my gulpfile.js. In both cases, gulp is installed locally.
My .vscode/tasks.json looks like:
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"showOutput": "always"
}
Looking at the Tasks output, I see the following message:
Running gulp --tasks-simple didn't list any tasks. Did you run npm install?
Can you use Gulp 4.0 with VS Code and have it autodetect the tasks? If so, what steps do I need to follow to get it setup?
Yes, you can use vscode and gulp4.0. I would look at how to upgrade to gulp4.0.
Did you uninstall gulp3.9.1 first?
You should also install gulp4.0 both locally and globally!
Then run
gulp -v
to make sure it worked. vsCode should detect both tasks in your tasks.json file and from your gulpfile.js. You are using the older tasks.json version 0.1.0. Here is an example of a tasks.json file which allows me to type "gulp sync" in the command line from anywhere in the workspaceRoot and run that task:
{
"version": "2.0.0",
"tasks": [
{
"label": "Start server and process files",
"command": "gulp",
"args": [
"sync"
],
"type": "shell",
"options": {
"cwd": "${workspaceRoot}"
}
}
]
}
It runs the "sync" task I defined in my gulpfile.js. In fact you can assign a hotkey combo to that such as:
{ "key": "shift+escape",
"command": "workbench.action.tasks.runTask",
"args": "Start server and process files"
},
in your keybindings.json.

Task with 'runner' not working as expected in VS Code

In VS Code 1.13.1, running in Windows Creator Update, I have defined this task in tasks.json:
{
"version": "0.1.0",
"runner": "terminal",
"command": "echo",
"isShellCommand": true,
"args": ["Hello world"],
"showOutput": "always"
}
When I run the task I see this message in the integrated terminal:
Terminal will be reused by tasks, press any key to close it.
But I don't see "Hello world". Why?
I don't know if you solved it yet, but I was having the same problem until I changed the terminal on settings.json from
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
to
"terminal.integrated.shell.windows": "C:\\WINDOWS\\Sysnative\\cmd.exe"
If your settings.json file does not have this line you can add and see if the problem goes away.