You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When componentB/tests/inc/TestDataBuilder.h is opened and I press Alt+O, the editor jumps to componentA/tests/src/TestDataBuilder.cpp instead of the source file in componentB. When I press Alt+O a second time, it jumps to componentA/tests/inc/TestDataBuilder.h. It seems that the algorithm simply picks the first header it finds in alphabetical order without considering locality.
AHKol, we appreciate your willingness to help out! Unfortunately this is something that is implemented in our language server which is not open source at this time. The bugs that are fixable by the community will be marked with the "help wanted" label.
I'm having similar issues, in my case I have headers with generic names like "Connection.h" "Object.h", when I switch from the cpp file to the header vscode switches to headers with the same name in system libraries (e.g. GCC in the case of Object.h and AWS SDK for Connection.h).
If this issue can't be fully fixed by finding the "nearest" matching file can it at least search workspace files before library files?
I have similar issues: Having multiple matching header files found in c_cpp_properties.json's includePath, it seems to pick the last match (instead of the first one).
This is absolutely insane, you can't use Alt-O (shortcut for C/C++: Switch Header/Source) to switch from header to source, if the two lie in different directories. This is true even if the directory where source files reside is mentioned in the /configurations/browse/path JSON array in c_cpp_properties.json as (for example) "/complete/absolute/path/to/source_files/*" . It should be noted that all of the source files lie in the aforementioned dir - there are no nested subdirectories in .../source_files, hence the single asterisk was used to not perform a recursive search (not that that would have helped anyways - I've tried it out of desperation).
It's so broken that it can't even go from header to source with Alt-O, if the source is already loaded and present in a tab right next to it in the editor, and these are the only two files that are currently open! It has no trouble going from source to header, though, so clearly it seems some sort of connection between the two.
Note: I am using a .hpp extension for headers and .cpp for source files, if that is helpful.
mgoldshteyn This issue is tracking some known limitations with switch header/source in which it'll pick a target with matching name at the unwanted folder, but it sounds like you may be hitting a different issue in which no target is found. Are you able to provide a simple repro? I'm not reproing the issue with the simple repro in this screenshot:
@sweihub There's not currently a way to prioritize an include directory, but you can exclude one via C_Cpp.files.exclude (assuming you don't mind losing global symbols in those files).
Meanwhile, the workaround I found to this issue is to install the extension c-mantic and bind the shortcut to its "Switch Header Source". It seems to work correctly.
Activity
AHKol commentedon Oct 28, 2018
I'm new to the vscode-cpptools repo. Since this looks like a good first bug I will give it a shot.
I managed to replicate it already.
bobbrow commentedon Oct 29, 2018
AHKol, we appreciate your willingness to help out! Unfortunately this is something that is implemented in our language server which is not open source at this time. The bugs that are fixable by the community will be marked with the "help wanted" label.
alanbirtles commentedon May 8, 2019
I'm having similar issues, in my case I have headers with generic names like "Connection.h" "Object.h", when I switch from the cpp file to the header vscode switches to headers with the same name in system libraries (e.g. GCC in the case of Object.h and AWS SDK for Connection.h).
If this issue can't be fully fixed by finding the "nearest" matching file can it at least search workspace files before library files?
rhaschke commentedon Nov 3, 2019
I have similar issues: Having multiple matching header files found in c_cpp_properties.json's
includePath, it seems to pick the last match (instead of the first one).kisielk commentedon Dec 4, 2019
I'm having trouble getting the switch to work at all, even with filenames like
{Src,Inc}/module.{cpp,h}SteelBlueVision commentedon Feb 16, 2021
This is absolutely insane, you can't use Alt-O (shortcut for C/C++: Switch Header/Source) to switch from header to source, if the two lie in different directories. This is true even if the directory where source files reside is mentioned in the
/configurations/browse/pathJSON array inc_cpp_properties.jsonas (for example)"/complete/absolute/path/to/source_files/*". It should be noted that all of the source files lie in the aforementioned dir - there are no nested subdirectories in.../source_files, hence the single asterisk was used to not perform a recursive search (not that that would have helped anyways - I've tried it out of desperation).It's so broken that it can't even go from header to source with Alt-O, if the source is already loaded and present in a tab right next to it in the editor, and these are the only two files that are currently open! It has no trouble going from source to header, though, so clearly it seems some sort of connection between the two.
Note: I am using a
.hppextension for headers and.cppfor source files, if that is helpful.sean-mcmanus commentedon Feb 17, 2021
mgoldshteyn This issue is tracking some known limitations with switch header/source in which it'll pick a target with matching name at the unwanted folder, but it sounds like you may be hitting a different issue in which no target is found. Are you able to provide a simple repro? I'm not reproing the issue with the simple repro in this screenshot:
7 remaining items
sean-mcmanus commentedon Mar 8, 2023
@sweihub There's not currently a way to prioritize an include directory, but you can exclude one via
C_Cpp.files.exclude(assuming you don't mind losing global symbols in those files).mua commentedon Sep 28, 2023
This is one of those things breaks entire keyboard workflow frequently.
StefanoPierini commentedon Feb 9, 2024
Meanwhile, the workaround I found to this issue is to install the extension c-mantic and bind the shortcut to its "Switch Header Source". It seems to work correctly.
sean-mcmanus commentedon Feb 12, 2025
This is fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.24.0 . If there are additional scenarios that are not fixed still we may open a new issue to track that additional improvement.