vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Improve switch header/source matching

Open sean-mcmanus opened this issue 5 years ago • 15 comments

From https://github.com/Microsoft/vscode-cpptools/issues/618#issuecomment-428177951

I have similar issue. I have the following folder structure (simplified)

componentA/tests/inc/TestDataBuilder.h
componentA/tests/src/TestDataBuilder.cpp
componentB/tests/inc/TestDataBuilder.h
componentB/tests/src/TestDataBuilder.cpp

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.

sean-mcmanus avatar Oct 09 '18 19:10 sean-mcmanus

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.

AHKol avatar Oct 28 '18 16:10 AHKol

@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.

bobbrow avatar Oct 29 '18 16:10 bobbrow

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?

alanbirtles avatar May 08 '19 16:05 alanbirtles

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).

rhaschke avatar Nov 03 '19 01:11 rhaschke

I'm having trouble getting the switch to work at all, even with filenames like {Src,Inc}/module.{cpp,h}

kisielk avatar Dec 04 '19 21:12 kisielk

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.

SteelBlueVision avatar Feb 16 '21 15:02 SteelBlueVision

@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:

image

sean-mcmanus avatar Feb 17 '21 23:02 sean-mcmanus

I also have this problem. I'm using src folder for the sources and include for the headers. From include/parser.hpp it correctly open the source file, but from parser.cpp it opens /usr/included/boost/beast/http/parser.hpp instead. It's quite frustrating. Is it really difficult to prefer files in the workspace?

vnen avatar Apr 03 '21 22:04 vnen

Any news here? I have the same issue!

pettitpeon avatar Aug 24 '22 08:08 pettitpeon

@pettitpeon No news yet, but it looks like the milestone just got changed to "On Deck".

sean-mcmanus avatar Aug 25 '22 18:08 sean-mcmanus

This has been a recurring problem for me. I have a workspace with API headers + implementation headers with the same filenames, and Alt+O simply never chooses the right ones. It's extremely frustrating.

arookas avatar Aug 28 '22 06:08 arookas