Configure Launch.json Visual Studio Code For Mac C++

Microsoft has released updates for the C/C++ extension in Visual Studio code. As part of the latest update, Microsoft has incorporated several advanced features like code formatting with clang-format, fuzzy auto-complete, Cygwin/MinGW debugging including console application debugging with GDB on the Mac.

Feb 03, 2018  In this video I am going to show, How to Set Up C++ Development With Visual Studio Code on Windows 10. We will use MinGW with VS code as our compiler and debugging tool. VS Code keeps debugging configuration information in a launch.json file located in a.vscode folder in your workspace (project root folder) or in your user settings or workspace settings. To create a launch.json file, open your project folder in VS Code ( File > Open Folder ) and then click on the Configure gear icon on the Debug view top bar. Debugging Angular2 apps in Visual Studio Code. If you’re on a Mac or Linux system, I can’t say whether the solution presented he will work for those environments.). When searching the web about this issue, all of the suggested launch.json code examples from various posts I found all looked very similar in what they suggested was.


It is now possible to format C/C++ code with clang-format from within Visual Studio Code. If the file is not found, the default fallback-style specified in the c_cpp_properties.json file is used. You will be able to control clang-format behavior via the settings file 'c_cpp_properties.json' file. It is also possible to load and edit the file by executing the relevant command.
The latest update also introduces a preview version of a fuzzy Auto-Complete for C/C++ code. Even though it is based on an enhanced tag-parser approach, it will still provide you more than what single-file intellisense provides you today. Moreover, this fuzzy intellisense approach will work with C code as well.
The May update also provides an ability for developers to debug their C/C++ Cygwin/MinGW applications using Visual Studio Code. To work with cygwin or MinGW, the debugger path must be set manually in the launch configuration file launch.json. With the help of the latest update, you will be able to debug console applications on the Mac using GDB.
You can easily update by simpy selecting the ext update from within C/C++ extension. You will have to select the Update Extension button in the lower right for the outdated extension. As soon as the installation is completed, you will be required to restart VS Code.

Recent Posts

ZeroStack Released DevOps Workbench With Enhanced Features
Visual Studio Code 1.19 Gets better With New Features and Improvements
PostgresSQL 10 Gets Better With Advanced Features For Developers

Category

Popular Tags

When writing code, everyone has a preference for their favourite editor of choice. I've been a massive fan of Sublime Text for years now, and although I switched across to Atom earlier this year for a bit of a trial, there were a lot of things I just missed from my setup in Sublime. The debugging package that was suggested stopped working randomly. Responsiveness became an issue the larger the project became (particularly from an autocomplete standpoint), and numerous other niggles. Still, the interface was extremely slick, and the theme support was great, so I persevered with it. That was until a new challenger appeared...

Enter Visual Studio Code...

Configure launch.json visual studio code for mac c++ download

Visual Studio Code reached it's version 1.0 milestone not long ago, and is starting to prove itself to be quite a powerful replacement for either Sublime Text or Atom, particularly for Python development.

Today we'll be looking at how we can optimise the editor with a number of different extensions (or plugins if you're coming from Sublime) that will make writing Python a more enjoyable experience. Extensions are all installed simply by bringing up the command palette (cmd + shift + p) and typing ext install <name>.

Python specific extensions

1. Python

This is the go to extension for all things Python related. As an overview it provides:

  • Linting (PyLint, Pep8, Flake8 with config files and plugins)
  • Intellisense and autocompletion
  • Code formatting (autopep8, yapf, with config files)
  • Renaming, Viewing references, Going to definitions, Go to Symbols
  • View signature and similar by hovering over a function or method
  • Debugging with support for local variables, arguments, expressions, watch window, stack information, break points
  • Debugging Multiple threads (Web Applications - Flask, etc) and expanding values (on Windows and Mac)
  • Debugging remote processes (attaching to local and remote process)
  • Debugging with support for shebang (windows)
  • Debugging with custom environment variables
  • Unit testing (unittests and nosetests, with config files)
  • Sorting imports
  • Managing snippets

2. Jinja

This extension adds support for the Jinja2 template language support to VS Code. This can then be set either via the status bar, or the command palette with Change Language Mode.

3. MagicPython

MagicPython improves the highlighting for Python 3 (in particular 3.5) syntax features including type annotations, string formatting, and regular expressions.

General extensions

Configure launch json visual studio code for mac c++

The following extensions are not specific to Python, but add some great features to VS Code.

1. Project Manager

Manage projects directly from the command palette.

2. Trailing Spaces

Highlights trailing spaces at the end of the line, and can remove them if configured to do so on save.

3. Visual Studio Code Settings Sync

Download Visual Studio Code For Windows

Synchronize Settings, Snippets, launch, keybindings files and extensions Across Multiple Machines using Github GIST.

4. Status Bar Tasks

Displays any tasks that you've configured in the Status Bar (down the bottom left), which can then be run just by clicking on them.

5. VS Code Icons

Configure Launch.json Visual Studio Code For Mac C++ Development

Brings file icons to the Explorer pane.

Configuring the Python extension

There are a couple of changes in your user preferences that you'll want to make to get VS Code working as best as possible. Open up your Preferences (Code > Preferences > User Settings) and then modify the values to the following:

Note: VIRTUALENV_PATH points to whatever directory your preferred virtualenv is located in and must be an absolute path.It's helpful to have a virtualenv in each project, which will allow you to utilise ${workspaceRoot} for tasks.json and launch.json, however this cannot be used in settings.json.

Note: Tabs have been added to the latest update (1.3.0), which is why the explorer.openEditors.visible setting has been added.

Once you've correctly configured the extension as above, you'll find that everything will just start working nicely, such as the code signatures that are displayed on hover.

Debugging

Working with a proper debugger is far more efficient than printing out variables to your console or to a log file, and thankfully VS Code provides great debugging.The Python extension that you've already installed has several templates for different web frameworks that will help you get started (including Watson).Switch across to the debugging tab and then click on the settings icon to choose Python from the list of environments.Additional options will be added to your launch.json file, and will look similar to this:

Git

There are a couple of non standard settings in that snippet above such as pythonPath and exceptionHandling. pythonPath will use the specified virtualenv, where as exceptionHandling allows you to ignore specific exceptions that are raised.

Configure Launch.json Visual Studio Code For Mac C++ Compiler

Unit Testing (and running tasks)

Switching across to your console to run your unit tests after writing them can also be quite annoying. Luckily, it's easy to setup a task (or several) to run the relevant tests. Bring up the command palette and search for Tasks: Configure task runner then select Other from the list. Copy and paste the below snippet in place of the supplied template and you're good to go.

Configure Launch.json Visual Studio Code For Mac C++ Download

You can now run your test task with Cmd+Shift+T (or whatever keybinding you've set workbench.action.tasks.test to) or click on the task name if you've installed the Status Bar Tasks extension.

The Python extension does come with the ability to run tests directly from the command palette. Though I feel that going this route gives you more flexibility with keeping all your tasks located in a single place.

Conclusion

The editor war is still raging pretty hard out there, and there definitely isn't a clear victor yet. That said, Visual Studio Code is a much welcomed addition to the fold, particularly for Python developers it provides a robust and fast editing experience, and with the number of extensions for it growing daily, there's no reason not to give it a try.