Main image of article How Does Visual Studio Code for Linux Work?

Screen Shot 2016-04-04 at 3.21.25 PM As names go, Visual Studio Code (VSC) is perhaps a little misleading. Visual Studio is a cross-platform integrated development environment (IDE) produced by Microsoft, a company not exactly known for opening up the code of its core products for all to see. And to answer the inevitable question: no, Microsoft has not open-sourced Visual Studio, at least not in the traditional way. Unlike the commercial version of Visual Studio, VSC is free, streamlined and compatible with a broad range of plugins, extensions, and themes. In a certain sense, Microsoft has invented a better Eclipse, by starting with a code editor and pumping it with steroids. Instead of looking at VSC in Windows, as I usually would, I installed it in Linux, specifically Ubuntu 14.04 LTS running under VirtualBox, to see how Microsoft fares outside its usual comfort zone.

Getting Started

Installing VSC via Linux starts off with a 40 MB download, followed by unzipping into a folder. Click the ‘Code’ file, then follow the instructions to run it from a terminal (‘code .’ starts it in the current folder). VSC is a pretty barebones IDE, with four icons for File Explorer, Search, Git and Debug—clicking on any of these opens a side window. The editor defaults to text file; clicking on Text File on the Status bar gives you a choice of syntax highlighting for most programming languages plus CSS, DockerFile, XML, JSON, Markdown and HTML. (If you open a .py file, it auto-selects Python and highlights it.) Unlike the full Visual Studio, there are no explicit concepts of project files. Instead, it's all done by folder.

What Features Does VSC Have?

vsc_ide VSC’s GUI can have up to three editors side-by-side. This is a different approach than the multi-tab model used in Visual Studio. There's a built-in file comparison that can show differences side-by-side or in-lined in one window. There are many more commands built in; just press F1 to open a command line with a scrollable list. It includes commands forgit pull, tab to/from space conversion and many more. This command line is also where you paste the commands to install extensions and themes from the marketplace; it’s what really makes VSC very special. As part of my experimenting, I opened a Python file and changed the settings for a different font and font size. I also switched back to a lighter-toned Visual Studio GUI (call me old-fashioned, but I find dark text on light background much easier to read than the modern white text/dark background). The menu File/Preferences/User settings opens both the Default Settings (as read only) and settings.json. You just copy the settings you want from the Default settings into the settings.json file.

The VSC Marketplace

This is where VSC shines. The marketplace is reminiscent of Nuget, or maybe the JavaScript npm package manager. From the F12 command line, type this in, making sure it ends with a space:

ext install

Or you can search and view on the Website for the Visual Studio Code Marketplace. For example, the languages category features roughly 200 extensions, including programming languages such as Go, C# and Python (among others); so far, everything I've seen there is free, although it’s not outside the realm of possibility that paid components will eventually appear (such as with the Xamarin components store, which is now Microsoft-owned.) Each extension has its own page with an install command, just like in Nuget. There's also a ‘copy’ button that copies it to the clipboard—just paste it in to the F1 command line in VSC, press enter, and it installs. It's very slick, and the only thing missing is some kind of progress indicator. I tried out the Python extension (the description is "Linting, Debugging (multi-threaded, remote), Intellisense, auto-completion, code formatting, snippets, and more”). Opening a python file adds it to the Working Files section at the top of the dashboard. Clicking the Debug icon brings up launch.json. This is a config file generated by VSC, and it needs a little bit of configuring. For example, with Python, you get the choice of running a Python application, a Python Console Application or Django; each has its own section in the launch.json. The IDE lets you put breakpoints against any line. When the program stops at a breakpoint, you can see Variables and Watched Variables as well as the call stack. Sadly, I was unable to debug the program in both Ubuntu 14.04 LTS and Ubuntu 15.04. This may be due to a misconfiguration. In both cases I got the error "Debug adapter process has terminated unexpectedly" before the program started. There was no output in the Debug console. Digging around, I found out how to create a task runner to run it, courtesy of Steve Fenton’s Website. I've adapted my version below. Press F1, then type “tasks,” and you should see Configure Task Runner. It sets up to run TypeScript files, but ignore that and overwrite it with this:

{

"version": "0.1.0",

"command": "/usr/bin/python",

"args": ["${file}"],

"problemMatcher": {

"fileLocation": ["relative", "${workspaceRoot}"],

"pattern": {

"regexp": "^(.*)+s$",

"message": 1
}
}
}

Change the command path if you are on Windows, or have Python in a different location from the default (on Ubuntu). After saving, with your file open in VSC, type ctrl+shift+B to run it.

Conclusion

run-code VSC works pretty well, though I had a minor glitch or two and the debug failure (which may be my misconfiguration or the Python extension issue). I think Microsoft have done a pretty good job, though more documentation along the lines of, "Here's how you do this" would be handy. The IDE was rock-solid.