IntelliJ Task Management: deal with your tickets like a pro

When I submit a patchset for review, I don’t shut down and wait for the requisite shipits to roll in – I move on to the next item on my backlog. Unfortunately, I’ll probably need to go back to the files in that patchset and act on my peers’ feedback, which means I’ll have to clean up my workspace and reopen the files I had earlier. I’ll want to have my editor split, with the code on one side and the tests on the other, and when I’m done addressing the feedback, I’ll have to clean up again, start the other task’s work again, and cross my fingers that I don’t have revisit that original patchset.

Switching between tasks is taxing, but lucky for us, IntelliJ has Task Management built in. Here’s how you set it up, get started, and make your life easier.

  1. Hit cmd-shift-A and type in “Configure Servers”. There are multiple “Configure Servers” actions, so select the “Tasks & Contexts” one.
    Screen Shot 2016-08-24 at 10.17.02 PM
  2. Hit the + icon and select the issue tracking server where your bugs live. For this example, I’ll use a project on my personal GitHub account, but as shown below, all the major issue tracking systems are supported (I usually use my work’s JIRA instance)
    Screen Shot 2016-08-24 at 10.18.46 PM
  3. Enter your repo credentials and details, test it out, then hit OK.
    Screen_Shot_2016-08-24_at_10_20_36_PM
  4. Now the fun starts. Hit option-shift-t, and the task switcher window will appear. Make sure “Open Task” is selected, and hit Return.
    Screen Shot 2016-08-24 at 10.24.13 PM
  5. Voila! All the open issues from your GitHub project will appear. Select the bug you want to work on and hit Return.
    Screen Shot 2016-08-24 at 10.25.03 PM
  6. You’ll get a few options on how to set up your workspace. I like to start each branch with a clean slate, so I select “Clear current context”, but uncheck it if you’d prefer to keep your current files open. With the “VCS Operations” checkboxes, you can switch to a new or existing branch for your code.
    Screen Shot 2016-08-24 at 10.26.49 PM
  7. Hit “OK” and do your work as normal. If you selected “Clear current context”, all the files that were previously open will be closed.

From now on, whenever you switch tickets, make sure to do “Open Task” from step 4. When you switch back to a ticket you worked on previously, IntelliJ will reopen the files that were open last time the ticket was active. They’ll be right where you left them – it’ll even remember if you had multiple panes open. No more tedious cleanup and setup!

This approach has made context-switching between tasks almost painless for me, and as a result of adopting it I have considerably increased my productivity. If you can relate to the frustration in the first paragraph, I highly recommend you try out the IntelliJ task management functionality. Enjoy!

3 Awesome Ways to Use Pycharm/IntelliJ/Webstorm Live Templates

The IntellIJ family of IDEs (IntelliJ IDEA, WebStorm, RubyMine, PyCharm etc) all support Live Templates, which I find extremely helpful to my work. In JetBrains’ own words:

Live templates let you insert frequently-used or custom code constructs into your source code file quickly, efficiently, and accurately.

In summary: you type a shortcut, you press your “expansion key” (usually tab), and the template expands. Here are three ways I use Live Templates to boost my productivity.

Conforming to coding standards

My team prefers our mocha test cases be written in a “should… when” style, ie it('should X when Y', function() { /* stuff goes here */ } ). I’ve been rumbled in code review a few times on this, so I made a Live Template that helps me adhere to the standard. Here’s how it looks:


it('should $SHOULD$ when $WHEN$', function() {
 $BODY$
});

I’ve abbreviated this block so that whenever I’m in a JS file and I type it followed by tab, it expands as follows:

Notice that when I hit tab, it goes to the next placeholder in the template. Easy!

Fast, sloppy debugging

Before I discovered this next technique, I would pepper my serverside code with debug statements like var_dump('here'); or var_dump('foo'); while trying to diagnose an issue. Coming up with unique dumb strings for var_dump gets tricky after the first ten, so I decided to let IntelliJ name them for me.

In this next example, I take advantage of IntelliJ’s ability to run Groovy code in Live Templates. I don’t know Groovy at all, but it’s a JVM language, so you can use the standard Java library. The template, which I have abbreviated to vvaarr, looks like:

var_dump("$RANDO$");

In the “Edit Variables” pane, I’ve set the $RANDO$ variable as follows:

groovyScript("String.format('%X', new Random().nextLong())")

This generates a random number and formats it as a hex string. The result looks something like var_dump("E41C2F2794389D6B"); Here’s how it looks in practice:

Now I don’t need to think about the strings to put in my debug statements. I can hit vvaarr-tab all over my code, look at the program output, and immediately connect the breakage to a location in the code.

(yes, I know I should set up a PHP debugger…)

Surrounding code

This technique takes advantage of Live Templates’ reserved $SELECTION$ variable, which represents whatever is currently selected in the editor. Sometimes when I write JavaScript I want to wrap a block of code in a function, so I can reuse it elsewhere. This is super easy with Live Templates. Here’s what the template looks like:


function $FN_NAME$ () {
$SELECTION$
}

In action:

Don’t forget to set “Reformat according to style”, so that the block is indented per your settings.

In conclusion

I hope this post has given you some inspiration on how you can use IntelliJ Live Templates to make your coding life more productive. Enjoy!