Is there a VSCode problemMatcher for elm-make? - visual-studio-code

I would like to run elm-make as a task in VSCode and have the results show up in the PROBLEMS window. I've been able to set up a task that is working for me as follows.
{
"version": "0.1.0",
"command": "elm",
"isShellCommand": true,
"args": ["make", "Index.elm"],
"showOutput": "always"
}
The problem however is that this dumps the text results to the OUTPUT window with no color and no support for navigating the results with editor.action.marker.next. Is there an existing problemMatcher for elm-make output? If not then is there a straight forward way to specify a custom one to do the job perhaps based on a regular expression?

Related

"No matching commands" for custom VS Code task

I'm trying to figure out how to create and use custom tasks.
I have been able to create a tasks.json file, but when I try to run the task from the command palette, nothing shows up.
My current .vscode/tasks.json file contains:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
}
]
}
I have also tried:
{
"version": "2.0.0",
"tasks": [
{
"label": "New Test Task",
"type": "shell",
"command": "echo 'hello new task'",
"windows": {
"command": "echo 'hello new task'"
},
"presentation": {
"reveal": "always",
"panel": "new"
}
}
]
}
And I have also tried the following combinations of folder/file:
.vs/tasks.json
.vs/tasks.vs.json
.vscode/tasks.vs.json
.vscode/tasks.json
Despite all of this, I keep getting a "No matching commands" error message. Is there something that I have overlooked or am doing wrong? Any guidance will be much appreciated.
Screenshot:
From the command palette, it requires 2 (or 3) steps/commands.
First, you need to get "Tasks: Run Tasks" in the command palette.
(By just entering "tasks", you should see it)
Then, after selecting that, it should list you all the tasks defined in your .vscode/tasks.json (yes, this is the correct folder/file combination as seen from the example in the Custom Tasks section of the VS Code docs). Specifically, all the label's defined in your tasks.json:
Now, depending on the task, it may prompt a third selection, like this one for your echo task:
If you want a single-step/command, you can use the other options of the Tasks: command group such as re-running the last run task or configuring a default task:
Or instead of the command palette, use a keybinding/shortcut to run your task: Is it possible to assign different shortcuts to different tasks in VS Code?.
you can add shortcut bindings to vscode's run task tasks.json by As in the following steps.
My OS environment is macOS
Use the shortcut "shift+command+P" to open the console
Then configure the shortcut key command as follows
{
"key": "f8",
"command": "workbench.action.tasks.runTask",
// "args": "echo", // You can also define your task label directly
"args": "${input}",
}
Finally, enter the shortcut key Use the shortcut key F8 to see the results of the task output
A bit simple but might help someone!
My colleague had by mistake clicked on Run Test Task and there nothing appeared. When clicking Run Task the stuff from .vscode/tasks.json appeared.

VS Code task to open VS Code's simple browser with a url

I intend to write a task, that first runs a dev server command, and parallely opens VS code's Simple Browser (Command Pallette -> Simple Browser) to the url.
I dont need the task to dynamically get the url from the dev server.
I've managed to make task to open the Simple Browser using input variable
{
"version": "2.0.0",
"tasks": [
{
"label": "open simple browser",
"command": "${input:openSimpleBrowser}"
}
],
"inputs": [
{
"id": "openSimpleBrowser",
"type": "command",
"command": "simpleBrowser.show",
"args": ["https://xkcd.com"]
}
]
}
One thing that I didn't find the documentation of is to find the name of the command. I found the name simpleBrowser.show by chance in VSCode itself. Apparently, you can get the name of each command in the command palette by:
search the command in the palette first
select the Configure Binding cog icon, which will take you to Keyboard Shortcuts
in the search bar, the name of the command will be written, e.g. #command:simpleBrowser.show
you'll only need the name after : for input variable

How do I run the AAA command through the command interface?

for example, I will take the command to export a document to htiml using the asciidoc extension.
What command can be written in the terminal to run it through vscode?
Or maybe you can make a task for the command, which I usually run through the command pallet (Ctrl+Shift+P)?
p.s. I'm not interested in how you can simulate a command. I want to execute it with vscode tools.
This task (in tasks.json) will run that command:
"tasks": [
{
"label": "asciiDoc to html", // whatever name you wish
// find the command name from the extension or from Keyboard Shortcuts
"command": "${command:asciidoc.saveHTML}",
"type": "shell",
"problemMatcher": []
}
}
Run the task with the asciiDoc file you want converted as the current editor. That task can be assigned to a shortcut if you wish (in keybindings.json):
{
"key": "alt+r", // whatever keybinding you want
"command": "workbench.action.tasks.runTask",
"args": "asciiDoc to html" // same name here as in your task
}

Bind a keypress to a shell command that uses the current file in visual studio code

Is there a way to create a keybinding to execute a shell command on a file?
something like:
{
"key": "ctrl+shift+e",
"command": "run",
"command": "touch $file",
"when": "editorTextFocus"
}
I don't want to use tasks as this needs to be global for the whole editor, not to a particular workspace.
[See my edit below - this is now much easier to do.]
I figured out a way to do what you want but it is a bit of a hack. As you probably know it is easy to bind a task if you can create the task in .vscode/tasks.json and use something like the following:
{
"key": "shift+escape",
"command": "workbench.action.tasks.runTask",
"args": "Start server and process files"
},
It is much trickier to run a script via a keybinding without a pre-existing task. However, you can try the following which takes advantage of the "workbench.action.terminal.runSelectedText", command. But we need to get the script into a selection first so:
Use the macros extension (which is a little rough) so that we can tie together multiple commands. In your user settings:
"runCommandInTerminal": [
{
"command": "type",
"args": {
"text": "node -v"
}
},
{
"command": "cursorMove",
"args": {
"to": "wrappedLineStart",
"by": "wrappedLine",
"value": 1,
"select": true
}
},
"workbench.action.terminal.runSelectedText",
"editor.action.clipboardCutAction",
// "workbench.action.terminal.focus"
],
This is a general example of a setting "runCommandInTerminal" that you can then bind to any key chord you wish in keybindings.json, like
{
"key": "ctrl+shift+e",
"command": "macros.runCommandInTerminal"
},
Your example is a little harder because you want to access something like ${file} which you cannot do in the settings, only tasks.json and launch.json. Fortunately, there is a command which will get the current file: "copyFilePath". So try
"runCommandInTerminal": [
"copyFilePath",
{
"command": "type",
"args": {
"text": "touch "
}
},
"editor.action.clipboardPasteAction",
{
"command": "cursorMove",
"args": {
"to": "wrappedLineStart",
"by": "wrappedLine",
"value": 1,
"select": true
}
},
"workbench.action.terminal.runSelectedText",
"editor.action.clipboardCutAction",
// "workbench.action.terminal.focus"
],
First get the file path, then output the first part of your script command "touch".
Next append the filepath to the end of the command.
Move the cursor to select the preceding.
Run the selection in the terminal.
Cut the selection from the editor.
This can be run with your keybinding. You will see the flash of the script being typed and cut but your editor code will be unaffected. It is best to run it from a blank line in the editor but you can run it from the beginning of a line of unrelated code if you wish (but indentation may be lost for now).
It is hacky but seems to work. I would love to know if there is an extension or another way to do this cleaner.
EDIT May, 2019:
Since my original answer (as #Jeff indicated) vscode has added the sendSequence command. And the ability to use variables with that command. So now the OP's question is much easier to accomplish:
{
"key": "alt+x",
"command": "workbench.action.terminal.sendSequence",
"args": {"text": "touch ${file}"}
}
in your keybindings.json file. See variables with a sendSequnce command.
with Marks answer here I could resolve my case that was run an android command with some shortcut.
After that I decided to create an guide on my GitHub, hope that helps.
GitHub: LucasMMota
Run Shell Script with Keyboard Shortcuts
In this example I set a keyboard shortcut to run android reload on my react native project.
Install the macros extension to execute multiple commands.
After installed go to Preferences>Settings (or cmd+,)
Find Macros Configuration and use to edit in User Settings, or simply add the following in your user settings:
{
//... other configs you could have
"macros": {
"runCommandInTerminal": [
"editor.action.insertLineAfter", // go to new line below
{
"command": "type",
"args": {
"text": "adb shell input text \"RR\" " // exec cmd to reload android device (could be any else)
}
},
// select text typed above
{
"command": "cursorMove",
"args": {
"to": "wrappedLineStart",
"by": "wrappedLine",
"value": 1,
"select": true
}
},
"workbench.action.terminal.runSelectedText", //run command
"editor.action.clipboardCutAction", // remove cmd typed
//"editor.action.deleteLines", //couldn't use. When uncommented, command doesn't work
],
}
}
Now that we have the command set, we need to set a trigger shortcut. So go to Preferences>Keyboard Shortcuts (or cmd+k), open keybindings.json and edit like this:
{
"key": "alt+s",
"command":"macros.runCommandInTerminal"
}
Save your User Settings customizations and keybindings.json, respectively
Bind file format and indenting with save shortcut
keybindings.json:
{
"key": "cmd+s",
"command": "macros.saveContentAndIndent",
"when": "editorTextFocus && !editorReadonly"
},
User Settings:
"macros": {
"saveContentAndIndent": [
"editor.action.formatDocument", // format
"workbench.action.files.save", // as I used Save shorcut, I add the save bind again.
],
//....
}
UPDATE 2:
VS Code now provides variables for integrated terminal commands. https://code.visualstudio.com/updates/v1_32#_variable-support-in-send-sequence-command
If you'd like to do more powerful tasks such as running them in the background (instead of just sending text to the current terminal) get the Command Runner or macro-commander extension
Original:
I created an extension macro-commander to solve this with a non-hacky solution. It is an improved version of the macros extension that runs the commands in order (synchronously) and lets you inject the filepath/folderpath into the command. Commands can be run in the user's VS Code terminal or a hidden background terminal.
UPDATE 1:
As of today (months later) I realized, much to my dismay, there was an existing extension that can probably do what you (and I) wanted. It is Command Runner written by edonet. If I had known about it I probably would've never made my extension.
Command Runner doesn't have as much generic possibilities (multiple commands, user input, or javascript) but it has a better UX and is probably the extension you (the reader) should try first. However, if Command Runner can't do what you're looking for, then macro-commander probably can, albeit with less elegance.
Whenever I decide to do a full update to macro-commander I'll talk with edonet and see if we can combine/add the functionality into his extension, in which case I'll update the macro-commander README to redirect to his/her extension.

How to get rid of "Terminal will be reused by tasks, press any key to close it." behaviour?

Upon executing a task (cargo build in this case), the following appears in the VSCode terminal:
> Executing task: cargo build <
(output of the task here)
Terminal will be reused by tasks, press any key to close it.
Annoyingly, this takes me out of the normal terminal and then I have to acquire focus of the terminal window and press a key to get back. And when I do so, the output of cargo build disappears.
How do I stop this behaviour?
How do I get rid of the first and last lines of text?
Check if the new feature from VSCode 1.57 (May 2021, 2.5 years after the OP) could help:
Automatically close task terminals
The task presentation property has a new close property.
Setting close to true will cause the terminal to close when the task exits.
{
"type": "shell",
"command": "node build/lib/preLaunch.js",
"label": "Ensure Prelaunch Dependencies",
"presentation": {
"reveal": "silent",
"revealProblems": "onProblem",
"close": true
}
}
[EDIT: 18-08-2018] Making it switch into the Problems tab is better when using the close option as that ensures the task terminal is closed, but the problems are properly highlighted. This is from VSCode 1.59.0.
To be clear, executing a task will always create a new integrated terminal in VS Code. There is no way around that. The most important thing is for the original terminal to be displayed instead of the newly created integrated terminal. (We want the original terminal revealed.)
#Gregory Cosmo Haun's solution will suppress the message "Terminal will be reused by tasks, press any key to close it". However, it still reveals the new integrated terminal instead of the normal terminal. (so you still have to press "any key" to close that terminal and reveal the original terminal)
A better solution would be to set "reveal": "silent", which will still create a new integrated terminal, but not reveal it unless there is an error while executing your task. I also set "clear": true (which is optional) so that the terminal is cleared before executing the task. I deliberately omit "showReuseMessage": false (which is optional) but you can add it. Who cares if the prompt is suppressed or not? The most important thing is that the newly created terminal is not revealed so I don't have to "press any key" to close it.
"presentation": {
"reveal": "silent",
"clear": true
}
BTW, you can also set "reveal": "never", but you would normally want to see the error message if there is a problem with executing your task.
In my opinion, this is the best possible solution. Yes, a new integrated terminal will always be created when executing a task, but at least it won't be revealed (unless there is an error) and you can safely ignore it without having to press any key to close it.
There is a new presentation option called showReuseMessage. Add the following to your task definition.
"presentation": {
"showReuseMessage": false
}
An alternative solution is to set the output window to auto-focus.
Add this to the task definition:
"presentation": {
"focus": true
}
Then it's not that annoying anymore because you can dismiss the compiler output with a single key press.
The benefit of this is that the task output is visible, so you can see if there were any errors or warnings.
One possibility is to add the following command to the "tasks":
"presentation": {
"panel": "new"
},
as
"tasks": [
{
"label": "python",
"type": "shell",
"command": "python",
"presentation": {
"panel": "new"
}
}
]
This does not fully solve the problem but at least does not pile all the results one after the other in the panel.
Inspired by https://github.com/Microsoft/vscode/issues/35642
After upgrading to VSCode 1.69.0 I started seeing this. I found the simplest change is to add this to my tasks.json file:
"presentation": {
"showReuseMessage": false
},
It's described here as:
/**
* Controls whether to show the `Terminal will be reused by tasks,
* press any key to close it` message.
*/
showReuseMessage?: boolean;