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

Posted on  by 

  1. Visual Studio Code For Linux
  2. Configure Launch.json Visual Studio Code For Mac C++ Download
  3. How To Use Visual Studio Code For C++
  4. Visual Studio Code Download
  5. Visual Studio

C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS. The extension is still in preview and our focus is code editing, navigation, and debugging support for C and C++ code everywhere that VS Code runs. The extension also supports Remote Development in the Visual Studio Code Insiders build.

If you just want a lightweight tool to edit your C++ files, Visual Studio Code is a great choice. But if you want the best possible experience for editing, testing and debugging your existing Visual C++ projects or debugging on Windows, we recommend Visual Studio. Visual Studio Community is a free edition. It includes:

Last week Microsoft released a new editor 'Visual Studio Code', a cross-platform editor (Windows, Linix, and Mac OSX), to develop ASP.NET 5 and Node.js applications. Being a big sucker for any new development tool, naturally I downloaded and installed it on my Mac.

Visual Studio Code For Linux

  • support for CMake or any other build system
  • support for Clang and GCC as well as the Microsoft C++ compiler
  • support for CTest, Google Test and Boost.Test as well as the Microsoft Native Test Framework
  • C++ code analysis tools including C++ Core Guidelines checkers
  • the state-of-the-art Visual Studio debugger
  • and much more.
How to use visual studio code for c++

If you run into any issues or have suggestions for the Microsoft C/C++ extension, please file issues and suggestions on GitHub. If you haven't already provided feedback, please take this quick survey to help shape this extension for your needs.

Getting Started

To install the Microsoft C/C++ extension:

  1. Open VS Code.
  2. Click the Extensions View icon on the Sidebar.
  3. Search for c++.
  4. Click Install, then click Reload.

To install support for Remote Development:

  1. Install the Visual Studio Code Insiders build. You can install this side by side with the stable build.
  2. Install the Visual Studio Code Remote Development Extension Pack.
  3. If the remote source files are hosted in WSL, download the Remote - WSL extension.
  4. If you are connecting to a remote machine with SSH, download the Remote - SSH extension.
  5. If the remote source files are hosted in a container (i.e. Docker), download the Remote - Containers extension.

Note: The C/C++ extension does not include a C++ compiler or debugger. You will need to install these tools or use those already installed on your computer. Popular C++ compilers are GCC on Linux or in a Mingw-w64 environment on Windows, Clang for XCode on macOS, and the Microsoft C++ compiler on Windows. Make sure your compiler executable is in your platform path so the extension can find it. The extension also supports the Windows Subsystem for Linux.

For instructions on configuring VS Code for specific environments, see:

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...

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

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.

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

3. Visual Studio Code Settings Sync

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

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:

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.

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.

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.

How To Use Visual Studio Code For C++

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.

Visual Studio Code Download

Conclusion

Visual Studio

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.

Coments are closed