Visual Studio Code

Run F9, done using the Code Runner Extension F2 - Rename

F5 to open the Debugger.

These commands should also be configured for my other IDEs and text editors.

Alt + [ Go back to previous cursor position (super useful after going to reference)

TODO: Find references + go to definition shortcuts Ctrl + Click or Ctrl + ] go to definition

Ctrl + tilda Toggle Terminal (very useful) CTRL/CMD + Tab Toggle Sidebar CTRL/CMD + T Search filename

Navigation Ctrl + 1 Go to pane 1 Ctrl + 2 Go to pane 2 Ctrl + 3 Go to pane 3

Workspace Settings

Fundamental Extensions that are super useful:

  • Clang-format for formatting
  • Gitlens for line authorship + seeing repo tree
  • Trailing Spaces

My thoughts:

  • VSCode is nice to use, but sometimes, on devices that don’t have that much compute, it takes away all of the resources. I experienced this at Comma hackathon

Not to be confused with Visual Studio, which is an IDE that can compile c++.

Should you commit VSCode?

VSCode Debugging

Realized from talking to Chester that linters are actually super useful. What you want to have is formatter file for VSCode, so everything is formatted consistently across a project. And everyone should decide that before the project begins.

So how does the VSCode Debug console work?

  • I can’t just input the next command it seems, like it’s not a copy of GDB
  • You can evaluate expressions,

https://code.visualstudio.com/docs/introvideos/debugging

F11 to step into code Shift + F11 to step out of code? I don’t know how you can go back..?

  • no that’s not what it means.

https://stackoverflow.com/questions/52368009/what-is-the-difference-between-step-in-step-out-and-step-over

Step in: means that if there is a function call, it goes inside the function and you can see how the function is executing line by line till it returns and you go back to the next line right after the function call.

Step over: means that if there is a function call, it just executes it like a black box and returns the result, but you cannot see how the function was executed.

Step out: means that if you have Stepped in a function and now you want to skip seeing how the rest of the function is going to execute, you Step out and the function returns. Then, you go back to the next line, that is the line right after the function call.

Consult this to understand how the debugger actually works:

Configuring VSCode for a new project

There are 3 files that you should have in a .vscode folder in the workspace:

  • tasks.json (compiler build settings)
  • launch.json (debugger settings)
  • c_cpp_properties.json (compiler path and IntelliSense settings)

IntelliSense

VSCode’s Syntax Highlighting and Code suggestion is called IntelliSense.

Formatting

Also learned from Chester is to use a formatter.

https://hackmd.io/@exradr/clang-format

See Clang Formatter for C++ language.

For Python, use Black / Pep8?

Tasks

These are useful to have, unfortunately they don’t have global tasks, so you need to keep specifying the C++ version every time.

https://stackoverflow.com/questions/76141850/how-can-i-set-a-default-tasks-json-file-for-visual-studio-code https://github.com/Microsoft/vscode/issues/5779#issuecomment-214620412

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-std=c++17",
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

Weird Bugs

Weird Bugs: Even though python3 is sourced properly, the conda environment is not sourced properly.