Visual Studio Code

Hello my friends,

As you may realized, I am using Visual Studio 2017 community for my C++ development activities. But sometimes, it might be required to find a simple tool to check code samples and to develop scripts which might be a little bit overshoot for Visual Studio. For this purpose, I have been using sublime editor for last couple of years (before that I was using Notepad++) which is very powerful and intuitive.

At some sites that I followed, and especially after a necessity that I will mention at the end of my post, I encounter with Microsoft’s new editor, Visual Studio Code (Well it has been around for 3-4 years 🙂 As it name implies, this tool provide Visual Studio like IDE GUI via sublime like editor.

The tool’s prominent features can be listed as:

  • Free and open source,
  • Support for Windows, linux and mac,
  • The shortcuts of well known IDEs and editors can be used within this tool,
  • Great extension and tool support,
  • Intellisen support for various programming languages (Javascript, JSON, HTML, CSS, TypeScript, C++, Java, PHP, Python, Go, SQL, C#) . This suport covers not only coloring but also code completion,
  • Debugging capabilities with associated compiler plugins,
  • Built-in git support,
  • In my opinion, the most important capability of this tool is  extensibility (Corresponding plugins can be seen in a gallery which can be accessed via ‘Ctrl+Shift+X’).

For more details, you can check out tool’s documentation.  To download the application you can click this link. Honestly, I have been using this tool for one or two weeks and it is not that bad but not enough for me to give up on Sublime 🙂 I really like Visual Studio IDE for programming C++, so if you are developing on Linux or similar platforms, this might be a good choice for you.

Developing C++ Application with VS Code

Before completing my post, let us look at the steps that we need to follow to develop a simple C++ application using VSCode. (By the way, this steps are based on some plugins, so there might be other plugins that you may use for this purpose.)

  • Go and click to Download Link to download application and then install it,
  • Open Extensions either from your browser (by clicking to eklenti adresinden) or clicking to button illustrated below
  • We are going to install three extensions for developing C++ software which are “C/C++“, “Easy C++ projects” and “Doxygen Documentation Generator“. Install these extensions via the links that I provided,
  • By the way, to use “Easy C++ Projects”, you need to install corresponding compilers beforehand. You can find supported compilers and how to use them at the end of post,
  • After installing every extension, you need to activate corresponding extension by clicking to blue “Reload to Activate” button as illustrated below,
  • Now, we prepared our environment to develop C++ application in VS Code. Let us try it via a simple C++ code,
  • If you have used Sublime editor, you may remember that you can logically group your files via folders (like solutions in VS) which is also applicable for Visual Studio Code. So we are gonna create a folder for this purpose. To do so follow “File -> Open folder” and create a folder named “VSCodeExample” at your disk. You “Explorer” panel will be look like below:
  • Open “Command Palette” via pressing F1. A list like below should be shown:
  • Enter “C++”  and then select “Easy Cpp/C++: Create new C++ project”‘. Then a list of compilers will be shown,
  • I am going to select “[MSVC] Windows X64, Visual Studio Build Tools 2017″‘ for this post. After you made your selection, you can observe that necessary files are generated automatically and shown at left “Explorer” panel,
  • Final step is to click “Build & Run” to compile and run our sample. Well, done! You have developed your first C++ application using VS Code 🙂
  • If you encounter with an error as illustrated below in “TERMINAL” then allow cmd.exe shown in “Do you allow shell: “cmd.exe” …” window, or you also follow the steps given in this link.
  • In case of no error, you should see the following lines in your Terminal.

Adding Code Comments with Doxygen

Now let us look at how we can use VS Code to add doxygen compliant code comments. Well, this is the in fact motivation for me to learn this tool. I was looking for a code commenter plugin in Visual Studio but most of them are commercial and could not found a tool in VS. Then I encounter with Doxygen Documentation Generator which I first thought that it is for VS. You can add simple doxygen based comments to your code easily. What you need to do is to move cursor to one line above the code segment that you will add comment and enter “/**”. Then corresponding code comment is added automatically. If it does not, check that no comment added before that line and also ensure that you installed extension and activated it.

options file description Simple Parameter

For more information, you can check out extension page.

“Easy C++ Project” Compiler Installation Directions

Windows

  • You must have MSVC or GCC installed:

GNU/Linux

  • Install GCC, Make and GDB using the package manager of your distribution, these are some of them:
    • Debian/Ubuntu/Mint: sudo apt install g++ make gdb
    • Fedora: sudo dnf install gcc-c++ make gdb
    • Arch Linux: sudo pacman -S gcc make gdb

MacOS

  • GCC: Check out Brew
  • Clang:
    • Open a Terminal
    • Run the command xcode-select --install
    • A dialog will appear telling you that it requires the command line developer tools, and asks if you would like to install them. Click on the “Install” button

References

You can also check out following links for more information about Visual Studio Code.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.