Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
I love JetBrainsâ IDEs. Iâve been a faithful user since PyCharmâs release, seven years ago.
As of late, if Iâm watching a presentation, and someone is writing code in an editor, that editor is almost always VSCode.
Somethingâs up, and Iâm going to get to the bottom of it. People rave about this thing.
Iâll answer some questions for myselfâââand, with luck, maybe I can save the JetBrains-faithful some time and energy. I aim to discover:
- Does it support my key bindings, or will I need to relearn everything?
- Whatâs the analog of a âRun Configuration?â
- Whatâs debugging look like? Howâs the source map support?
- How easy is it to configure?
- Howâs the extension ecosystem?
- How does the VCS (Git) integration differ?
- Whatâs the story on inline errors or warnings?
- How smart is it about types and code completion?
Iâll be looking at this from the standpoint of a JavaScript developer, so Iâll write âWebStorm,â but I really mean âa JetBrains IDE.â
Iâm certainly interested in how VSCode handles Python and C/C++, but Iâm not going to explore it in this post.
First Impressions
I used Homebrew Cask to install it:
$ brew cask install visual-studio-code==> Satisfying dependencies==> Downloading https://az764295.vo.msecnd.net/stable/f88bbf9137d24d36d968ea6b2911786bfe103002/VSCode-darwin-stable.zip==> Verifying checksum for Cask visual-studio-code==> Installing Cask visual-studio-code==> Moving App 'Visual Studio Code.app' to '/Users/boneskull/Applications/Visual Studio Code.app'.==> Linking Binary 'code' to '/usr/local/bin/code'.đș visual-studio-code was successfully installed!
This takes ~4s on my 2016 MBPâââbut I donât have any extensions installed yet.
Iâm greeted with this:
It has also opened a web page in Chrome:
Online tutorials & such for VSCode
I ignore the web page (thanks, but no thanks) and click a few of the âInstall support forâŠâ links under Tools and languages to get some basic extensions installed. I want to avoid customizing too much at the outset. Since C/C++ isnât listed on the âWelcome Pageâ, I dig into to the extensions and ⊠canât help myself from installing a bunch of extensions. Oops.
I am, however, elated to report that the JetBrains IDE Keymap is a thing, and it works great.
I go ahead and open up my Mocha working copyâŠ
Summary
- Install âExtension Packsâ to get started quickly. You will install many extensions.
- Thereâs plenty of tutorials.
- If youâre using the default bindings in WebStorm, you likely want to install the JetBrains IDE Keymap extension.
- Key bindings are at once more powerful and complex than WebStorm. Itâs difficult to discover what a particular keystroke does at any given time, but also supports conditionals, for a nearly absurd level of control.
Close Encounters with Version Control
OK, so I want to edit MochaâsCHANGELOG.md. But I know origin has changes I need to pull.
Happily, VSCode understands this is, in fact, a working copy. To pull, I found a little ârefreshâ button in my status bar, and clicked it. I think it worked? It said âsync.â Whatâs a âsyncâ?
Iâm unsure what just happened. Which changesets did Git pull? I want to look at the history. After searching in vain, I realize that there is no built-in support for Git history, and Iâm going to need to grab an extension for this.
GitLens seems to solve this problem (and others). But there are many Git-related extensions for VSCode. This is a drawback of the âsmall coreâ philosophy of VSCode (this reminds me of the Node.js ecosystem). To VSCodeâs credit, it aids discovery with tags, filters and sorting.
GitLens does some oddball things like âinline blameâ and âcode lensâ (which is another view into âblameâ? I donât get it). I want to turn this noisy stuff off.
Hint: run GitLens: Toggle Code Lens and GitLens: Toggle Line Blame Annotations from the Command Palette.
GitLens then provides Git history in the left sidebar. The presentation of the repo is a little disorienting (there are so many trees, itâs like a forest), but I do see the pulled changesets.
Whew.
Iâve made my changes to CHANGELOG.md, and itâs time to commit. VSCode helpfully marks the file with a big M in the file list. +1.
I find Git: Commit via the Command Palette, and realize I could have used my trusty â-K. But Iâm prompted that the stage is empty.
If you only use WebStormâs built-in version control client (I donât), this will be culture shock. VSCode uses the stage, like literally every other Git client except WebStormâs.
I go ahead and commit everything (including unstaged changes; this would be Git: Commit All if I wanted to avoid the prompt), and push.
Not the nicest initial experience, but Iâm confident itâll be smoother sailing from here.
Next, Iâll run Mochaâs test suites to prepare for publishing.
Summary
- You will likely want to install the Git extension pack, due to VSCodeâs basic client implementation.
- VSCode uses the stage, unlike WebStorm.
- VSCode automatically enables Git support for working copies instead of prompting you into oblivion.
Tasks in VSCode
I think a âTaskâ is perhaps a âRun Configurationâ or âExternal Toolâ.
âTasksâ are not the same as âTasksâ in a WebStorm, which is WebStormâs (leaky) abstraction around issues, staged changes and branching.
Letâs see what âConfigure Tasksâ doesâŠ
Whatâs do you call a widget like this, anyway?
Ooook. that needs some further explanation, but sure. Is it trying to automatically detect my npm scripts? For reference, Mochaâs scripts in its package.json is literally just:
{ "scripts": { "prepublishOnly": "nps test clean build", "start": "nps", "test": "nps test" }}
Iâll roll the dice with npm:Â test.
VSCode creates and opens a .vscode/tasks.json file:
At least itâs not XML, amirite?
Fascinating. I click the link and learn about this file. Itâs unclear whether VSCode intends for the user to commit .vscode/ to VCS (I donât do so; in fact, I add .vscode/ to my .gitignore post-haste).
VSCode likely didnât need me to âconfigureâ the Taskâââit discovered the script itself. I execute Run TaskâŠ, choose npm: test, and the output opens in a terminal, as youâd expect.
Iâm now certain âTasksâ are analogous to âExternal Toolsâ. Like in WebStorm, the user (seemingly) cannot debug a Task, and thereâs little integration. VSCode ships with some helpers for common build tools (unfortunately, nps is not one of them). Like WebStorm, the user has free rein to create a âshellâ-based Task.
Iâm still looking for the analog of a âRun Configuration,â which appears to be a âDebug Configuration,â though itâs just called âConfigurationâ under VSCodeâs âDebugâ menu. Next, Iâll take it for a test-drive. Whatever the hell itâs called.
Summary
- âTasksâ in VSCode are analogous to WebStormâs âExternal Toolsâ.
- Configure tasks via JSON files. This isnât too awesome, but VSCode provides validation/completion when editing, which is better than nothing.
- You must choose whether or not to commit .vscode/ to VCS. Iâve never had success committing any sliver of .idea/ to VCS, but maybe the story is different here. Donât look at me; find some other guinea pig.
Trivia: VSCode recognizes the filetype of tasks.json as âJSON with Commentsâ, which, AFAIK, is unadulterated, imaginary nonsense. Is it JSON5 or not?
Debugging
Photo by Mink Mingle /Â Unsplash
First, I install the Node.js Extension Pack, since I figure Iâll need it to debug properly.
From VSCodeâs menu, I open Debug > Open Configurations. Iâm presented with a new file, .vscode/launch.json. Like tasks.json, this is my config file.
This menu item inexplicably corresponds to the command Debug: Open launch.json.
In Node.js
Do you want the good news or bad news first? I donât care.
The bad news is, I canât just throw npm test in launch.json and expect my breakpoints to get hit. Why not? Because npm spawns nps, which spawns ten different mocha processes in series, each which spawn _mocha, and many of which spawn _mocha again.
This is by no means VSCodeâs fault, but the story around debugging subprocesses in Node.js is a sad one. Iâd be foolish to expect a miracle.
The good news is that if I choose some subset of the tests to run with bin/_mocha, debugging works well (unless I want to debug more child processes). Itâs a solid debugging experience, though lacking some of the bells & whistles of WebStormâs debugger.
In a Browser
Debugging tests with Karma, awkward is.
In a WebStorm, you create Karma-based run configuration, point it to your config file, specify any particular browsers or other extra options, and push the button. It works well, even if you happen to be bundling your code with karma-browserify, which Mocha is.
This is the VSCode experience:
- You need to install the Chrome Debugger extension.
- Create a chrome debug configuration identical to:
{ "type": "chrome", "request": "attach", "name": "Attach to Karma", "address": "localhost", "port": 9333, "pathMapping": { "/": "${workspaceRoot}/", "/base/": "${workspaceRoot}/" }}
- Modify your karma.conf.js (ugh, really?) to add a custom launcher to your setup object. The port below must be the same port as above. Hope itâs not in use!
{ customLaunchers: { ChromeDebug: { base: 'Chrome', flags: ['--remote-debugging-port=9333'] } }}
- Start Karma (you can create a Task to do this): karma start â-browsers ChromeDebug --auto-watch --no-single-run. Leave it running.
- Run your âAttach to Karmaâ debug configuration; choose it from âDebugâ > âRun ConfigurationâŠâ.
At this point, you can set breakpoint(s) by clicking in the editorâs gutter, though they will not immediately be enabled.
There appears a small, odd, quasi-movable toolbar near the top of the window. Within this impish toolbar is a ârefreshâ-looking button; click it to re-run the tests. VSCode will then be able to discover which scripts/files Karma loaded. If youâre lucky, itâll even hit your breakpoint!
The above took a solid hour to figure out, even with a few scattered examples out there.
The last thing I want to evaluate is VSCodeâs âIntelliSenseâ capabilities.
Summary
- âRun Configurationsâ = âDebug Configurationsâ. Iâm calling them âDebug Configurationsâ, so there.
- Configure âDebug Configurationsâ via JSON, like âTasksâ.
- VSCode has very basic breakpoints without support for features such as enabling/disabling based on previous breakpoints, or disabling once hit.
- Debugging in Karma is a poor experience. I couldnât find a Karma-specific extension to help with this.
Code Completion, Inspections, & Intentions (Oh My)
Assuming you use ESLint, install the ESLint extension.
In terms of inspections, I just want ESLint to run on my JavaScript. I donât need any other inspections, so I disable all the random crap WebStorm ships with.
The ESLint extension âjust works,â and the user sees the same type of inline inspections as from ESLint within WebStorm, right down to the intentions, like âFix file with ESLintâ.
The Node.js Extension Pack provides some npm-related âIntelliSense,â which knows important stuff about package.json, like if a package is missing or extraneous, will tell you so, and automatically fix it for you via an intention.
Is âIntelliSenseâ a trademark or something? Itâs a Microsoft-ism, right? I am pretty sure I hate this word.
I believe VSCode uses TypeScript definitions under the hood (not just in TypeScript files) to inspect code, at least in part. This results in extremely accurate and nearly instantaneous code completion, jump-to-declaration, and the like. If thereâs any âkiller featureâ for JavaScript developers, itâs this. You can coax such behavior out of WebStorm, but it will still be much more sluggish.
A âdeep diveâ into this would be an excellent source of information for WebStorm users (think: CSS, HTML, TypeScript, template languages, etc.), but is unfortunately out-of-scope. Iâll end with my final thoughts below.
Summary
- VSCode (and/or its extensions) provide accurate, zippy code-completion and inline docs for JavaScript.
- VSCode does not ship with a bunch of built-in inspections. If you use them, youâll miss them, unless you find alternatives.
- The ESLint experience is strong.
- The npm-related experience is excellent.
VSCode: The Verdict
Photo by chuttersnap /Â Unsplash
Visual Studio Code is better than I expected. Itâs comparable with WebStormâââby way of extensionsâââin terms of feature set. It has a couple notable advantages over WebStorm, however:
- VSCode is generally faster and more responsive than WebStorm
- VSCodeâs JavaScript inspection/completion experience is just plain better
- Free as in beer
- Much exciting!
Notable disadvantages include:
- Poor browser-based debugging experience (for me, anyway)
- Piecemeal (though complete) Git support
- JSON-based configuration
- No customer support
As a developer, my code editor my most important tool. Having spent many years with JetBrains and WebStormâââand having very little dissatisfactionâââa different tool must be incredibly compelling for me to want to pick up.
My advice for WebStorm users? Donât try VSCode unless you are prepared to switch.
This article originally appeared March 9, 2018 on boneskull.com.
VSCode for WebStorm Users was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.