• VS Code Language Support Notes

    Note

    This is an excerpt of my personal notes that I’ve cleaned up a little for documenting my non-gamedev work and for sharing with others. -Terry

    Web-oriented tech stack languages like JavaScript or TypeScript ship directly with Visual Studio and have built-in support. Extensions are only needed to further enhance the developer experience when working with specific frameworks.

    Other languages or frameworks like C++ or C# can be incrementally added via other first-party extensions maintained by Microsoft of third-party extensions from others.

    Since the task system allows you to execute shell commands, anything that offers a CLI app or script for building it can be built by VS Code. Instead, the focus of this article will be to identify languages that can support the following:

    1. Language Server Support (LSP) for auto-complete/IntelliSense
    2. Task Configuration for triggering builds, executing tests
    3. Launch Configuration for launching and debugging

    The ability to generate configurations is preferred over using specialized commands for projects that follow the “write, build, run” paradigm would allow you to maintain the same UX regardless of project type instead of remembering specific commands for specific types of projects.

    The process of creating a new project in VS Code is complex as it requires human intervention, may differ greatly between project types, and may automate certain steps in some cases or not in others. Users seeking a turnkey experience that allows then to hit “New Project” and have few, if any steps, to follow to achieve something ready to work with should consider alternatives like Visual Studio or JetBrains Rider.

    Additionally, installing dependencies for working with various languages or project types is often left to the user. Some languages can automatically download runtimes or SDKs as needed; results will vary.

    C++ #

    CMake-based projects are well supported by using a combination of the C/C++ extension and the CMake Tools extension, both maintained by Microsoft (the latter was originally created by vector-of-bools). You can create one directly from VS Code with the above extension by running the “CMake: Quick Start” command to spawn a “Hello World” project.

    Overall, I recommend using the CMake Workflow (Commands) for enabling a write-debug-test workflow that requires minimal setup.

    Note

    CMake is a significant hurdle as it has its own language for describing your project on top of C++’s need for you to understand how the underlying build tools works (such as when prompted to select a compiler or kit for CMake).

    Single file projects are also somewhat well-supported and are introduced in the quick start tutorials from Microsoft on C++ in VS Code. They focus on building and debugging by directly invoking the build tools and debugger through the task and launch configurations. They are included since they are a part of the official instructions, but I don’t personally use it since a CMake project is a little more portable.

    CMake Workflow (Commands) #

    CMake projects with CMakeLists.txt files can define targets that can be built, launched, and debugged using CMake Tools’ commands.

    • Extensions
    • Minimal Setup
      1. Open a workspace that contains a project with a populated CMakeLists.txt file
      2. Select a kit
      3. Run Command: “CMake: Build” can be used to simply build
      4. Run Command: “CMake: Debug” to build and debug your project

    The CMake Tools extension can work with CMake to provide commands that provide easy configuration, building, and debugging of CMake-compatible projects.

    Toolbar UI #

    CMake Tools also adds a lot of UI to VS Code that mimics the experience you might find in other IDEs, allowing you to build/debug with your mouse instead of your keyboard.

    • Activity Bar gets a “CMake” activity that lets you inspect project status, browse project files, or run pinned commands.
    • Status Bar gets a variety of actions like building, debugging, selecting a kit, or changing the project configuration.

    CMake Workflow (Configuration) #

    CMake projects with CMakeLists.txt files can also be built/run/debugged with task configurations that invoke CMake Tools and launch configurations that are partially resolved by CMake Tools.

    Info

    Creating a launch.json will tie you to a specific debugger, which can be unideal if you want a cross-platform launch configuration or if you want different debuggers on different platforms.

    Manual Workflow #

    The introduction tutorials from Microsoft on C++ in VS Code focus on building and debugging by directly invoking the build tools and debugger through the task and launch configurations.

    • Extensions
    • Minimal Setup
      1. Create a workspace
      2. Add and open a Main.cpp file in that workspace
      3. Run Command: “C/C++: Debug C/C++ File” to generate a working tasks.json file
        • You will be prompted to select your compiler.
      4. Run Command: “C/C++: Add Debug Configuration” to generate a working launch.json file
        • You will be prompted to select your compiler again; this should be the same as the last one you picked.

    Additional properties for working with the debugger are available on VS Code’s page on C++/Configure Debugging.

    CodeLLDB Workflow #

    See also CodeLLDB, a mature third-party debugger primarily for C++ and Rust powered by LLDB. It has its own extensive documentation on its GitHub repository.