I have created a task in VsCode to run the autoflake8 tool which removes the unused imports and variables from the python files and task definition looks like this
{
"label": "Run Autoflake8",
"type": "process",
"command": "/Users/rbhanot/.local/bin/autoflake8",
"args": ["-ri", "--remove-unused-variables", "${file}"]
}
The task runs just fine and the file does gets updated but the problem is that VsCode still keeps showing red error markers until I close the file and open it again. So VsCode is not able to detect that file has changed and reload the changed file.
Is there anyway to fix or alter this behaviour because let's say if I have multiple files open I need to reload them again manually which is a pain.
Related
I'd like to be able to use the new vscode tasks feature to open a file in remote vscode. This is useful because I have a bunch of symlinked log files in tmp that I would like to open, and I don't want to type their whole name every time. Ideally it would be something like this:
{
"label": "$(play) open log file",
"type": "shell",
"command": "code /tmp/logfile.INFO",
"group": "build",
},
If I run the same command in the normal vscode terminal, it opens the file correctly. If I run it in the task, the environment doesn't have vscode's bin in the path. If I change code in the task to use the direct path of the remove vscode, it then complains saying "Command is only available in WSL or inside a Visual Studio Code terminal."
I'm unclear if this fails because it is remote vscode or if it fails because it's not possible to open code in a task. Either way it'd be nice to do so :)
I would like to be able to run an existing vscode command or extension and pass arguments to it. From my research so far this is what I would expect the vscode task.json to look like, but it does not work. What am I doing wrong?
{
"label": "open index html in editor",
"command": "${command:workbench.action.files.openFile}",
"args": ["/home/host_user/src/index.html"]
},
{
"label": "liveView index html",
"command": "${command:extension.liveServer.goOnline}",
"args": ["/home/host_user/src/index.html"]
},
If I run the file command it opens a vscode prompt to select a file. If I try to liveView the file, it runs live view on my root workspace (as no path is getting passed to it).
This is the extension I'm trying to open with file with:
https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer
Thanks
Is there any way to set vscode such that double-clicking a .docx file in the embedded file explorer causes the file to be opened in Microsoft Word?
Context
I'm used to PyCharm but I've been migrating to vscode. I'm used to creating Word document files (.docx) and double-clicking them in the file explorer on the left side sub-window to launch Word and see what the document looks like. This works in PyCharm, but in vscode it tries to open the file as a binary and claims it has no editor. Even if it did had an editor, I wanted it to open in my second monitor (or at least to be able to move it to my second monitor). For the time being, I'm opening a file explorer window and double clicking the file there, which has been less than optimal.
It's not quite double clicking, but you could create an open file command as a task, then bind that task to a keyboard shortcut, which amounts to one click and one hotkey.
Creating the open file task
We preferably make this task user-level, so that is accessible in every project.
ctrl+shift+p and search Tasks: Open User Tasks
In the tasks.json file, add the open file task to the tasks array:
// Inside "tasks": [ ... ]
{
"label": "open file",
"type": "shell",
"command": "${file}",
"presentation": {
// Hides the task terminal from showing up
"reveal": "never",
}
}
Change the "command" to whatever the open file command for your shell is (just ${file} works for windows, but change it to xdg-open ${file} for linux)
Assigning a keybinding to the open file task
To bind the task command to a keybinding, ctrl+shift+p and search keyboard shortcuts (JSON), open the file. Add the following to the array (changing "key" to whatever combination you desire)
// [ ... ]
{
"key": "ctrl+alt+l",
"command": "workbench.action.tasks.runTask",
"args": "open file"
}
To open any file, click on it to focus it in a tab (which sets the ${file} defined in tasks.json) and use the assigned hotkey. (As a side note, opening files that have vscode as their default program will open it in the same instance, so it makes it seem like the task isn't doing anything)
To work, Windows users should take care with command quotes
tasks.json :
{
"label": "open file",
"type": "shell",
"command": "'c:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE' '${file}'"
}
I've always used Sublime Text 3 for Python Coding, in which Build Systems were the only way of running a file.
Now I'm starting C++ programming, and I'm using VSCode. The problem I have is that, in that dock where:
PROBLEMS , OUTPUT , DEBUG CONSOLE , TERMINAL
The only thing I've had trouble with, is OUTPUT window, because nothing ever appears, so if I wanna run either Python or C++ code, it won't show anything to let me know what output would the program give. And if I just try to run it (pressing f5) it, it will open terminal and run it from it.
I saw something called Tasks but I don't know how they work, and they seem to be like Build Systems from Sublime Text 3.
I wanna use OUTPUT window, how can I get it working?
to run code in the output section of visual studio code you can use the extension Code Runner
just install, then press CTRL + ALT + N to run the file (supports c++ & python)
I wanna use OUTPUT window, how can I get it working?
As it stands now, you can not use the Output Window as a way to log code, that is reserved for native logs like Window, Main, Shared or Extensions to log their output using channels. There is a good candidate called the Debug Console.
You can log to the Debug Console using a launch.json configurable:
First, create a launch.json for your program.
Then add the following properties, in addition to whatever you need to get your program going:
internalConsoleOptions
Controls when the internal debug console should open
redirectOutput
Both of these used in tandem will open the 'Debug Console' instead of terminal and just provide the necessary output; though it still sends to terminal should you still want it:
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"internalConsoleOptions": "openOnSessionStart",
"redirectOutput": true
}
]
For c++ they have an extensive tutorial on how to debug and run: https://code.visualstudio.com/docs/languages/cpp (in addition to setting up launch.json and tasks.json files respectively https://code.visualstudio.com/docs/cpp/config-mingw#_build-helloworldcpp)
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install formulahendry.code-runner
I've setup the Debugging with Chrome and it works reasonably well. However, every time I make a change & save the .htm file, I have to click the Restart icon in the toolbar for the changes to propagate to the instance of Chrome.
Is there a way for VS Code to "restart" when I save the file?
P.S. I am editing a local file (no web servers involved).
I wanted to do exactly the same thing and accomplished it by installing an extension that allows me to execute a VS Code extension command when a file is saved.
The extension is Save and Run Ext and is a fork off of another extension but allows you to execute VS Code extension commands.
I added the following configuration to my settings.json file:
{
"saveAndRunExt": {
"commands": [
{
"match": "\\.(css$|js$|html$)",
"isShellCommand": false,
"cmd": "workbench.action.debug.restart"
}
]
}
}
What this does is whenever a .css, .js, or .html file is saved, it will restart the debugger. You could of course configure it to do whatever you want.
An alternative (one step) solution is instead of saving the file, just restart the debugger, and it automatically saves all files and changes are propagated to Chrome.