How to jump to build error in Visual Studio Code?

11,269

Solution 1

Have you defined a problem matcher in your tasks.json? There are several built-in ones that can simply be referenced, for instance "problemMatcher": ["$tsc"] will work for TypeScript.

The docs also contain an example for a custom problem matcher for C++:

"problemMatcher": {
    "owner": "cpp",
    "fileLocation": ["relative", "${workspaceRoot}"],
    "pattern": {
        "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "severity": 4,
        "message": 5
    }
}

If there's no built-in matcher for the language you're using, you shoulds still be able to find one with a bit of searching if it's moderately popular.

Solution 2

Did you build your code in TERMINAL window of Visual Studio Code? If so, press down the "Ctrl" key and move the mouse cursor to the filename and line number such as "/home/..../xxx.cpp:123" in the error line, then you can click on it to jump to the corresponding line in the code

It works for me.

Share:
11,269
Etay Meiri
Author by

Etay Meiri

Updated on July 01, 2022

Comments

  • Etay Meiri
    Etay Meiri almost 2 years

    I'm using Visual Studio Code (Version 1.8.1) on Linux. When there is a build error and I click on the line that contains the error it doesn't jump to the corresponding line in the code. Is there a way to make Visual Studio Code behave the same as standard Visual Studio?

  • tupui
    tupui over 6 years
    You should first ask the OP with comments before posting an answer.
  • fengliutie
    fengliutie over 6 years
    I didn't know it's better to ask the OP before posting an answer. It was my first time posting an answer. Thank you for reminding me!
  • tupui
    tupui over 6 years
    Your welcome. Indeed, your should be certain when you write an answer, otherwise comments are a great place for that. Here is a recap How to Answer
  • Scorb
    Scorb over 5 years
    Is there a way to do what you mentioned, but with a keyboard shortcut?
  • br1
    br1 almost 5 years
    Even though formulated as a question, this is the answer!
  • hsandt
    hsandt almost 4 years
    Arg, almost works, but ctrl+click highlights the trailing ":" for me (e.g. "concepts.cpp:37:48:") so I have to type RIGHT, BACKSPACE just to remove it and go to file:line:char, which is now 3 actions...
  • ahcox
    ahcox almost 3 years
    This works for me in 2021 using a vanilla install of VS Code and the MS C++ plugin, after building a simple CMake project by hitting <F7> with the default keybinding for that key.