How to link directories for VS Code problem matcher










1















I am writing a new build task for compiling C++ in VS Code. The task involves compiling the code inside of a Docker container. For example



docker exec -it my_container make


Here is what I have in my task.json file




"version": "2.0.0",
"tasks": [

"label": "build",
"type": "shell",
"command": "docker",
"args": [
"exec",
"-it",
"my_container",
"make"
],
"group": "build",
"presentation":
"reveal": "always",
"panel": "dedicated"
,
"options":
"cwd": "$workspaceRoot"
,
"problemMatcher":
"base": "$gcc",
"fileLocation": "absolute"


]



I'm able to run the task, and everything compiles correctly. However, VS Code cannot find the files that have build errors in them. That is because the output for an looks something like this:



/host/my_project/src/my_file.cpp:105:46: error: passing 'const SomeClass' as 'this' argument discards qualifiers [-fpermissive]


The path that is listed is the absolute path to the file in the Docker container. When you click on one of the files in the Problems tab, it tries to jump to /host/my_project/src/my_file.cpp, but it doesn't exist. Instead, the file lives in /home/me/projects/my_project/src/my_file.cpp.



I've tried a few things to fix this, none of which seem to work. I tried changing the problemMatcher to the one outlined in the documentation and trying to use a different regex that would remove the absolute part of the path (e.g. convert /host/my_project/src/my_file.cpp to /src/my_file.cpp, and set the fileLocation to relative). However I'm not well-versed enough in regex to get it right. Referencing some regex from here, I came up with this



"problemMatcher": 
"owner": "cpp",
"fileLocation": ["relative", "$workspaceFolder"],
"pattern": error):\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5




I also tried the other options in that answer, but none of them work. Another thing I tried was creating a symlink between the folders by running ln -s /host ~/projects. This also did not work, and still tried to open the file in the Docker container



Does anyone have any suggestions?










share|improve this question
























  • related: stackoverflow.com/questions/47775169/…

    – Florian Castellane
    Nov 14 '18 at 9:34















1















I am writing a new build task for compiling C++ in VS Code. The task involves compiling the code inside of a Docker container. For example



docker exec -it my_container make


Here is what I have in my task.json file




"version": "2.0.0",
"tasks": [

"label": "build",
"type": "shell",
"command": "docker",
"args": [
"exec",
"-it",
"my_container",
"make"
],
"group": "build",
"presentation":
"reveal": "always",
"panel": "dedicated"
,
"options":
"cwd": "$workspaceRoot"
,
"problemMatcher":
"base": "$gcc",
"fileLocation": "absolute"


]



I'm able to run the task, and everything compiles correctly. However, VS Code cannot find the files that have build errors in them. That is because the output for an looks something like this:



/host/my_project/src/my_file.cpp:105:46: error: passing 'const SomeClass' as 'this' argument discards qualifiers [-fpermissive]


The path that is listed is the absolute path to the file in the Docker container. When you click on one of the files in the Problems tab, it tries to jump to /host/my_project/src/my_file.cpp, but it doesn't exist. Instead, the file lives in /home/me/projects/my_project/src/my_file.cpp.



I've tried a few things to fix this, none of which seem to work. I tried changing the problemMatcher to the one outlined in the documentation and trying to use a different regex that would remove the absolute part of the path (e.g. convert /host/my_project/src/my_file.cpp to /src/my_file.cpp, and set the fileLocation to relative). However I'm not well-versed enough in regex to get it right. Referencing some regex from here, I came up with this



"problemMatcher": 
"owner": "cpp",
"fileLocation": ["relative", "$workspaceFolder"],
"pattern": error):\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5




I also tried the other options in that answer, but none of them work. Another thing I tried was creating a symlink between the folders by running ln -s /host ~/projects. This also did not work, and still tried to open the file in the Docker container



Does anyone have any suggestions?










share|improve this question
























  • related: stackoverflow.com/questions/47775169/…

    – Florian Castellane
    Nov 14 '18 at 9:34













1












1








1








I am writing a new build task for compiling C++ in VS Code. The task involves compiling the code inside of a Docker container. For example



docker exec -it my_container make


Here is what I have in my task.json file




"version": "2.0.0",
"tasks": [

"label": "build",
"type": "shell",
"command": "docker",
"args": [
"exec",
"-it",
"my_container",
"make"
],
"group": "build",
"presentation":
"reveal": "always",
"panel": "dedicated"
,
"options":
"cwd": "$workspaceRoot"
,
"problemMatcher":
"base": "$gcc",
"fileLocation": "absolute"


]



I'm able to run the task, and everything compiles correctly. However, VS Code cannot find the files that have build errors in them. That is because the output for an looks something like this:



/host/my_project/src/my_file.cpp:105:46: error: passing 'const SomeClass' as 'this' argument discards qualifiers [-fpermissive]


The path that is listed is the absolute path to the file in the Docker container. When you click on one of the files in the Problems tab, it tries to jump to /host/my_project/src/my_file.cpp, but it doesn't exist. Instead, the file lives in /home/me/projects/my_project/src/my_file.cpp.



I've tried a few things to fix this, none of which seem to work. I tried changing the problemMatcher to the one outlined in the documentation and trying to use a different regex that would remove the absolute part of the path (e.g. convert /host/my_project/src/my_file.cpp to /src/my_file.cpp, and set the fileLocation to relative). However I'm not well-versed enough in regex to get it right. Referencing some regex from here, I came up with this



"problemMatcher": 
"owner": "cpp",
"fileLocation": ["relative", "$workspaceFolder"],
"pattern": error):\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5




I also tried the other options in that answer, but none of them work. Another thing I tried was creating a symlink between the folders by running ln -s /host ~/projects. This also did not work, and still tried to open the file in the Docker container



Does anyone have any suggestions?










share|improve this question
















I am writing a new build task for compiling C++ in VS Code. The task involves compiling the code inside of a Docker container. For example



docker exec -it my_container make


Here is what I have in my task.json file




"version": "2.0.0",
"tasks": [

"label": "build",
"type": "shell",
"command": "docker",
"args": [
"exec",
"-it",
"my_container",
"make"
],
"group": "build",
"presentation":
"reveal": "always",
"panel": "dedicated"
,
"options":
"cwd": "$workspaceRoot"
,
"problemMatcher":
"base": "$gcc",
"fileLocation": "absolute"


]



I'm able to run the task, and everything compiles correctly. However, VS Code cannot find the files that have build errors in them. That is because the output for an looks something like this:



/host/my_project/src/my_file.cpp:105:46: error: passing 'const SomeClass' as 'this' argument discards qualifiers [-fpermissive]


The path that is listed is the absolute path to the file in the Docker container. When you click on one of the files in the Problems tab, it tries to jump to /host/my_project/src/my_file.cpp, but it doesn't exist. Instead, the file lives in /home/me/projects/my_project/src/my_file.cpp.



I've tried a few things to fix this, none of which seem to work. I tried changing the problemMatcher to the one outlined in the documentation and trying to use a different regex that would remove the absolute part of the path (e.g. convert /host/my_project/src/my_file.cpp to /src/my_file.cpp, and set the fileLocation to relative). However I'm not well-versed enough in regex to get it right. Referencing some regex from here, I came up with this



"problemMatcher": 
"owner": "cpp",
"fileLocation": ["relative", "$workspaceFolder"],
"pattern": error):\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5




I also tried the other options in that answer, but none of them work. Another thing I tried was creating a symlink between the folders by running ln -s /host ~/projects. This also did not work, and still tried to open the file in the Docker container



Does anyone have any suggestions?







c++ regex visual-studio-code






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 '18 at 18:03







TFischer

















asked Nov 9 '18 at 17:30









TFischerTFischer

65921434




65921434












  • related: stackoverflow.com/questions/47775169/…

    – Florian Castellane
    Nov 14 '18 at 9:34

















  • related: stackoverflow.com/questions/47775169/…

    – Florian Castellane
    Nov 14 '18 at 9:34
















related: stackoverflow.com/questions/47775169/…

– Florian Castellane
Nov 14 '18 at 9:34





related: stackoverflow.com/questions/47775169/…

– Florian Castellane
Nov 14 '18 at 9:34












1 Answer
1






active

oldest

votes


















1














It looks like you just have to include the container name plus slashes: /host/ in the regex (and treat the path as relative), so here goes:



The slashes must be escaped, so you have to add /host/ after the beginning of that regex.



Try this config, I can run it as a task (control-shift-B) and generate problems with it (control-shift-M). However it doesn't let me control-click the errors in the console, I guess one would need to edit the c++ extension's regex for this.




// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"echoCommand": true,
"tasks": [

"label": "build",
"command": "YOUR BUILD COMMAND HERE",
"type": "shell",
"group": "build",
"presentation":
"reveal": "always",
"panel": "dedicated"
,
"options":
"cwd": "$workspaceRoot",
,
"problemMatcher":
"base": "gcc",
"fileLocation": ["relative", "$workspaceRoot"],
"pattern":
"regexp": "^/host/(.*):(\d+):(\d+):\s+(warning


]



However, the path detection in the terminal is unaffected. I wish this regex would let us control+click the GCC messages to jump to the code.






share|improve this answer

























  • Thank you! I had to slightly modify /host/ to match my folder structure, but it works. I also links back to the correct file when I click a problem in the list

    – TFischer
    Nov 15 '18 at 14:14











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230663%2fhow-to-link-directories-for-vs-code-problem-matcher%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














It looks like you just have to include the container name plus slashes: /host/ in the regex (and treat the path as relative), so here goes:



The slashes must be escaped, so you have to add /host/ after the beginning of that regex.



Try this config, I can run it as a task (control-shift-B) and generate problems with it (control-shift-M). However it doesn't let me control-click the errors in the console, I guess one would need to edit the c++ extension's regex for this.




// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"echoCommand": true,
"tasks": [

"label": "build",
"command": "YOUR BUILD COMMAND HERE",
"type": "shell",
"group": "build",
"presentation":
"reveal": "always",
"panel": "dedicated"
,
"options":
"cwd": "$workspaceRoot",
,
"problemMatcher":
"base": "gcc",
"fileLocation": ["relative", "$workspaceRoot"],
"pattern":
"regexp": "^/host/(.*):(\d+):(\d+):\s+(warning


]



However, the path detection in the terminal is unaffected. I wish this regex would let us control+click the GCC messages to jump to the code.






share|improve this answer

























  • Thank you! I had to slightly modify /host/ to match my folder structure, but it works. I also links back to the correct file when I click a problem in the list

    – TFischer
    Nov 15 '18 at 14:14
















1














It looks like you just have to include the container name plus slashes: /host/ in the regex (and treat the path as relative), so here goes:



The slashes must be escaped, so you have to add /host/ after the beginning of that regex.



Try this config, I can run it as a task (control-shift-B) and generate problems with it (control-shift-M). However it doesn't let me control-click the errors in the console, I guess one would need to edit the c++ extension's regex for this.




// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"echoCommand": true,
"tasks": [

"label": "build",
"command": "YOUR BUILD COMMAND HERE",
"type": "shell",
"group": "build",
"presentation":
"reveal": "always",
"panel": "dedicated"
,
"options":
"cwd": "$workspaceRoot",
,
"problemMatcher":
"base": "gcc",
"fileLocation": ["relative", "$workspaceRoot"],
"pattern":
"regexp": "^/host/(.*):(\d+):(\d+):\s+(warning


]



However, the path detection in the terminal is unaffected. I wish this regex would let us control+click the GCC messages to jump to the code.






share|improve this answer

























  • Thank you! I had to slightly modify /host/ to match my folder structure, but it works. I also links back to the correct file when I click a problem in the list

    – TFischer
    Nov 15 '18 at 14:14














1












1








1







It looks like you just have to include the container name plus slashes: /host/ in the regex (and treat the path as relative), so here goes:



The slashes must be escaped, so you have to add /host/ after the beginning of that regex.



Try this config, I can run it as a task (control-shift-B) and generate problems with it (control-shift-M). However it doesn't let me control-click the errors in the console, I guess one would need to edit the c++ extension's regex for this.




// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"echoCommand": true,
"tasks": [

"label": "build",
"command": "YOUR BUILD COMMAND HERE",
"type": "shell",
"group": "build",
"presentation":
"reveal": "always",
"panel": "dedicated"
,
"options":
"cwd": "$workspaceRoot",
,
"problemMatcher":
"base": "gcc",
"fileLocation": ["relative", "$workspaceRoot"],
"pattern":
"regexp": "^/host/(.*):(\d+):(\d+):\s+(warning


]



However, the path detection in the terminal is unaffected. I wish this regex would let us control+click the GCC messages to jump to the code.






share|improve this answer















It looks like you just have to include the container name plus slashes: /host/ in the regex (and treat the path as relative), so here goes:



The slashes must be escaped, so you have to add /host/ after the beginning of that regex.



Try this config, I can run it as a task (control-shift-B) and generate problems with it (control-shift-M). However it doesn't let me control-click the errors in the console, I guess one would need to edit the c++ extension's regex for this.




// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"echoCommand": true,
"tasks": [

"label": "build",
"command": "YOUR BUILD COMMAND HERE",
"type": "shell",
"group": "build",
"presentation":
"reveal": "always",
"panel": "dedicated"
,
"options":
"cwd": "$workspaceRoot",
,
"problemMatcher":
"base": "gcc",
"fileLocation": ["relative", "$workspaceRoot"],
"pattern":
"regexp": "^/host/(.*):(\d+):(\d+):\s+(warning


]



However, the path detection in the terminal is unaffected. I wish this regex would let us control+click the GCC messages to jump to the code.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 9:42

























answered Nov 14 '18 at 9:14









Florian CastellaneFlorian Castellane

225620




225620












  • Thank you! I had to slightly modify /host/ to match my folder structure, but it works. I also links back to the correct file when I click a problem in the list

    – TFischer
    Nov 15 '18 at 14:14


















  • Thank you! I had to slightly modify /host/ to match my folder structure, but it works. I also links back to the correct file when I click a problem in the list

    – TFischer
    Nov 15 '18 at 14:14

















Thank you! I had to slightly modify /host/ to match my folder structure, but it works. I also links back to the correct file when I click a problem in the list

– TFischer
Nov 15 '18 at 14:14






Thank you! I had to slightly modify /host/ to match my folder structure, but it works. I also links back to the correct file when I click a problem in the list

– TFischer
Nov 15 '18 at 14:14




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230663%2fhow-to-link-directories-for-vs-code-problem-matcher%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo