Skip to content
Dominik Mayrhofer edited this page Dec 11, 2025 · 11 revisions

title: VSCode

Developing CFS with Visual Studio Code

Visual studio code is developed as open source under MIT license at https://github.com/microsoft/vscode. The product offered by Microsoft contains branding and telemetry features and comes under a different license. The open source vscodium project offers binaries for download without these additions.

Prerequisites

After installation of vscode/vscodium you need to add extensions and set up your workspace. Compile, debugger etc., are not included in vscode and must be installed separately (see https://code.visualstudio.com/docs/languages/cpp).

Install Extensions

The following extensions are required (for the later description to work):

You might also want to install (to enhance vscode):

  • XML for XML validation and autocompletion with schema support
  • GitLab Workflow for integration of merge request, CI-file linting, ...
  • GitLens for additional git info like blame, file history, ...
  • Markdown All in One for editing and previewing markdown files.

Setup the Workspace

Use the source directory (git repo) as your workspace to take advantage of the git-features of vscode. Just open vscode and choose File->Open Folder ... or code <source directory>.

VScode uses the directory .vscode within your workspace to store workspace settings (overriding user settings). Settings are saved to settings.json, we have a template in share/vscode.

  1. Copy the template to <source directory>/.vscode/settings.json, and set the setting "cmake.buildDirectory": "<build-directory>" to your build directory.
  2. Select the cmake generator via "cmake.generator": "Ninja" or Unix Makefiles.
  3. Adapt the config options "cmake.configureArgs": \\\\\\\["-DBUILD_TESTING=ON","-DDEBUG=ON"\\\\\\\] to your taste.
  4. Configure: on the CMake extension panel select configure_, or hit Ctrl+Shift+P and select CMake: Configure
  5. Build: on the CMake extenstion panel selcet build, or hit F7.
    • for the Ninja generator you need to build the target cfsdeps seperately first: hit Shift+F7 and select cfsdeps

You can keep the setting "cmake.buildDirectory": "${workspaceFolder}/.vscode/build-dir-link and define the symlink build-dir-link which needs to point to the desired build directory. One should use a <build-directory> outside the workspace, since vscode monitors the workspace for changes, and the build dir is too large for that to work properly. Currently ignoring stuff does not seem to work. The symlink can be created via the tool ln e.g.:

ln -s <build directory> <source directory>/.vscode/build-dir-link

Code Navigation

The Explorer gives basic overview over the folder structure and files, while the Outline displays the classes and functions in the currently opened file.

Search (Ctrl+F) within files and Global Search (Ctrl+Shift+F) can be very powerful tools to find the right place in the code. Try searching the /source directory by "geometryType" to find where the domain parses this option. You can not only use strings of the input .xml to find the places in the code where they are parsed, but you can also look into the .info.xml and search for the tags used there, to find where they are written out.

Debug

Besides debugging, also logging can be a great tool to track your code. Check out how logging in cfs works.

The debug settings in VSCode are defined via the launch.json file. An example is given here:

{
 "version": "0.2.0",
    "configurations": [
        {
            "name": "debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "~/code/cfs_debug/bin/cfs",
            "args": ["-f","${fileBasenameNoExtension}"],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb"
        },
    ]
}

You can define a launch configuration with the settings file launch.json. We have a template in share/vscode.

  • Place the template in <source directory>/.vscode/launch.json, or
  • On the Run and Debug panel (Ctrl+Shift+D), in the top drop down menu, select Add Configuration ..., which opens launch.json for editing
    1. select the template C/C++ : (gdb) Launch
    2. set the binary to launch by "program": "/path/to/your/cfs"
    3. specify arguments "args": \\\\\\\["-f","-p","${fileBasename}","dbg"\\\\\\\], i.e. which XML input to use
    4. set working directory "cwd": "${fileDirname}"

The used variables in ${} reference the currently selected file (for details see the variables reference). For debugging, just open the XML input you want to run, and on the Run and Debug panel (Ctrl+Shift+D) select the launch configuration and click launch (green play button).

Set breakpoints in source files by clicking on the line number. In the debug panel you find variables, the call-stack and breakpoints. The basic navigation controls are:

  • F5 – start debugging
  • F5 – Continue (when already debugging)
  • F10 – Step over
  • F11 – Step into
  • Shift+F11 – Step out

XML-autocompletion

  • Use the extension redhat.vscode-xml.
  • Specify the schema, e.g. by xsi:schemaLocation="http://www.cfs++.org/simulation https://opencfs.gitlab.io/cfs/xml/CFS-Simulation/CFS.xsd".
  • Start typing, hit Ctrl+Space for suggestions.
  • Hover over tag to show Documentation (if <annotation><documentation> is present for the element in the schema).
  • To upade schema cache: options (command-shift-p): XML: refresh all opened xml files

Optional Notes

GitLab Workflow extension configuration

  • You need to define "gitlab.instanceUrl" in settings.json.
  • Create an access token and input it.
  • Multiple remotes in the repository only work after a GitLab command has been run (it will ask for preferred remote)

A sample section from settings.json.

    "gitlab.instanceUrl": "https://cfs-dev.mdmt.tuwien.ac.at",
    "gitlab.ignoreCertificateErrors": true,
    "gitlab.pipelineGitRemoteName": "origin",
    "git.autofetch": true,
    "gitlab.repositories": {
        "/home/ftoth/openCFS/CFS": {
            "preferredRemoteName": "origin"
        },
        "/home/ftoth/openCFS/CFS/Testsuite": {
            "preferredRemoteName": "origin"
        }
    }

References

Clone this wiki locally