Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-run Last Task #25310

Closed
o-lim opened this issue Apr 25, 2017 · 12 comments · Fixed by #62645
Closed

Re-run Last Task #25310

o-lim opened this issue Apr 25, 2017 · 12 comments · Fixed by #62645
Assignees
Labels
feature-request Request for new features or functionality tasks Task system issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@o-lim
Copy link

o-lim commented Apr 25, 2017

  • VSCode Version: 1.11.x
  • OS Version: all

There does not appear to be a way to re-run the previously executed task. You can either run "the build" using ctrl+shift+b, or you must explicitly select a task to run. In Atom and Eclipse, you can hit F9 to re-run your last build. This is very handy, and easily what I want to do 80%-90% of the time, just re-run my last build/task command. However, vscode does not appear to allow you to map any hot-key to the last build/task command. So if I want to run task foo, I would, effectively, have to type task foo into the command pallet every time. Things would go a lot faster if I could just type task foo into the command pallet just once, then hit a hot-key to repeat the last task.

@dbaeumer dbaeumer added tasks Task system issues feature-request Request for new features or functionality labels Apr 26, 2017
@dbaeumer dbaeumer added this to the On Deck milestone Apr 26, 2017
@dbaeumer
Copy link
Member

Good suggestion. What you can do right now is to bind a keyboard shortcut to the task foo if you want to start the same task over and over again. Here is an example on how to do this:

	{
		"key": "ctrl+h",
		"command": "workbench.action.tasks.runTask",
		"args": "foo"
	}

@nathanpalmer
Copy link

Thanks for the suggestion @dbaeumer -- Though it doesn't seem to solve the problem I'm looking for. The task I want to re-run is dependent upon both the file and lineNumber. While I'm working in other files I want to keep re-running the previous task and include those previous values and not my current values.

Common problem here is red-green testing where I run a failing test first and then modify the main body of code to fix the test. In the current flow I have to keep switching back to the test to run it which is a lot more time intensive than other platforms I've used for the same purpose (sublime and atom both have plugins for it.)

@dbaeumer
Copy link
Member

dbaeumer commented Sep 4, 2017

@nathanpalmer this should have improved as well by VS Code now sorting the task list in a LRU fashion. So running the last task is no Run Task (which you can bind to a keyboard shortcut) and then pressing enter.

@nathanpalmer
Copy link

Just tried that, had to arrow down once to hit the last task. However the problem still remains that it takes the parameters of the current file and line I'm on and not for the previous run. So unfortunately it doesn't work as needed.

@dbaeumer
Copy link
Member

dbaeumer commented Sep 5, 2017

Just to clarify. You want to run the task in the same state so with the variables as resolved when last run. Is this correct.

@hendrics
Copy link

hendrics commented Sep 5, 2017

@dbaeumer i would say 'yes' to that statement. This is my explanation and workaround of the usecase i am (and it seems that @nathanpalmer too) after...
https://github.com/hendrics/python-vscode-pytest-example#running-only-subset-of-tests

@nathanpalmer
Copy link

@dbaeumer Yes, running the last task using the same state including variables. In my use-case it's a unit test as I'm working in other parts of the code I want to quickly re-run that same exact test.

Thanks for the suggestion @hendrics. Not exactly a perfect solution as this will run a set of tests instead of a single one. But it's good to hear what others are doing.

@thorn0
Copy link

thorn0 commented Mar 11, 2018

It'd be also great to have another similar command: "Terminal: Rerun Last Command".

@deanrather
Copy link

New to VSCode, agree with @thorn0 's suggestion above; wondering how simple it is to make a keybinding, macro, plugin, whatever that achieves the above. effectively focus terminal -> press up arrow key -> press enter -> focus whatever I was on before.
If I could bind that to a key-press, I think it'd save me precious seconds.. thousands of times a day :)

@kevin-dong-nai-jia
Copy link

kevin-dong-nai-jia commented Sep 29, 2018

@thorn0 @deanrather Here is a workaround solution.

Step 1: Override the default terminal keybinding from triggering to toggling.

    {
        "key": "ctrl+`",
        "command": "workbench.action.terminal.focus",
        "when": "!terminalFocus"
    },
    {
        "key": "ctrl+`",
        "command": "workbench.action.focusActiveEditorGroup",
        "when": "terminalFocus"
    }

Step 2: Override the F5 key, which can be altered to any key combination as you like. On Unix-like OS with X11, the script below checks the focused window and then send key sequences, which will re-run the last command belonging to the last focused terminal, if the focused window is VSCode; otherwise, the F5 key does what it is supposed to do as usual. There should exist some similar method for other OSes.

#!/bin/bash

# Get The Focused Window Name
WNM="$(xdotool getwindowfocus getwindowname)"

if [ -n "$(grep 'Visual Studio Code$' <<< "$WNM")" ]; then
	# VSCode: Run The Last Command
	xdotool key ctrl+grave Up Return ctrl+grave
else
	# Default F5 Behaviour
	xdotool key --window "$(xdotool getactivewindow)" F5
fi

Step 3: Register this script in the custom keyboard shortcut, which is in the System Settings on Ubuntu.

alexr00 added a commit that referenced this issue Oct 23, 2018
@alexr00 alexr00 self-assigned this Oct 23, 2018
@alexr00 alexr00 modified the milestones: On Deck, October 2018 Oct 23, 2018
@alexr00 alexr00 modified the milestones: October 2018, November 2018 Oct 30, 2018
alexr00 added a commit that referenced this issue Nov 5, 2018
alexr00 added a commit that referenced this issue Nov 20, 2018
@nathanpalmer
Copy link

Amazing! Thanks @alexr00

@alexr00 alexr00 added the verification-needed Verification of issue is requested label Dec 5, 2018
@alexr00
Copy link
Member

alexr00 commented Dec 5, 2018

Verification steps: Run a task using the Run Task command. Then run the Rerun Task command. Also try specifying runOptions: { reevaluateOnRerun: false } in the task definition and run the Rerun Task command.

@roblourens roblourens added the verified Verification succeeded label Dec 5, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality tasks Task system issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants