Vscode-cpptools: C_Cpp.SwitchHeaderSource does not work anymore

Created on 9 Mar 2017  Â·  17Comments  Â·  Source: microsoft/vscode-cpptools

After opening a .cpp or .hpp file, switching to the respective other file via Alt+O does not work anymore.
Both files are located in the same folder, next to each other.
Source file extension: .cpp
Header file extension: .hpp

Pressing Ctrl+Shift+P and selecting "Switch header/source" does not work either.

  • VSCode Version: Code 1.10.2 (8076a19fdcab7e1fc1707952d652f0bb6c6db331, 2017-03-08T14:02:52.799Z)
  • OS Version: Windows_NT ia32 6.1.7601
  • Extensions:

|Extension|Author|Version|
|---|---|---|
|FreeMarker|dcortes92|0.0.8|
|vscode-yaml-validation|djabraham|0.0.1|
|xml|DotJoshJohnson|1.7.0|
|cpptools|ms-vscode|0.10.2|
|diff|rafaelmaiolla|0.0.1|
|missinglineendoffile|riccardoNovaglia|0.1.6|
|annotator|ryu1kn|0.10.1|
|partial-diff|ryu1kn|0.2.0|
|trailing-spaces|shardulm94|0.2.11|
|scope-info|siegebell|0.2.0|
|indenticator|SirTori|0.2.1|
|theme-visualstudio|none|0.0.1|
|theme-visualstudio-2016|none|0.0.1|
|tmlanguage|Togusa09|0.7.1|;


Steps to Reproduce:

  1. Put two files MyClass.hpp + MyClass.cpp in a folder
  2. Open a file named MyClass.hpp
  3. Press Alt+O to switch to MyClass.cpp

The file MyClass.cpp is not opened.

Language Service bug fixed (release pending)

All 17 comments

I'm not able to repro the bug. I suspect another extension is interfering by having another Alt+O command. You can also try right-clicking ad selecting the Switch Header/Source option. Can you repro the bug with the other extensions disabled?

I'm suffering this same issue. In my case the language service crashes 3 times or 5 (I'm not sure) and a message popup at the top saying that the service wasn't going to be restarted again. Is there a way to restart the language service? Can I share some information that might be useful to you? (e.g. a crash log/memory dump?)

I just installed Visual Studio Code (stable) on a different machine (Windows 10 this time).
The app was never installed on this PC before.
Installed just the C++ extension, created two files MyClass.hpp and MyClass.cpp.
Switching between them by pressing Alt+o does not work.
Right-clicking and selecting "Switch header/source" does nothing.

Is there any console or log where I might see a warning or error message?

Have you explicitly opened a folder, or just the individual files? Many of our extension's features are expecting you to open a folder first. This defines the ${workspaceRoot} variable among other things.

We'll add a backlog item to display some sort of message if you try to use a feature that depends on a folder being open.

open folder

I just opened individual files, not a folder.
But that feature worked just fine that way until recently, without opening a folder.

We changed the implementation to require the browse database. Is there a reason you don't open the folder the file is in instead? The open file scenario has been low priority for us, so lots of features don't work with it. It's possible we could get it working though.

Well, I primarily use Visual Studio (the IDE) for development. But since I have to work with many C++ projects, I often use VS Code to look up something in a specific file that is currently not loaded in a Visual Studio instance.
With C++ the need for switching between header and source is self-explanatory.

I'd very much appreciate it if that feature would work without opening a folder again.

Maybe related, I think this feature should work in a simple way: 1) check if there is a file with the same title but with the other extension in the same directory, 2) if that is not the case and we have a folder open, use the new logic. Here is an example about some weird behavior when there are several candidates for the same .h/.cpp file:

invalid-other-file

Instead of selecting the obvious option src/ui/graphics.cpp first, the extension opens src/allegro/src/graphics.c and then switch between src/allegro/include/allegro/graphics.h and src/allegro/src/graphics.c.

@1100101 Sure, since it's a regression in previous behavior we'll increase the priority.
@dacap That is a bug. Thanks for a repro. It's supposed to select the header/source in the same folder first.

@dacap If you're getting a crash, can you attach a debugger and get a dmp? We're still trying to figure out why we're not getting any crash dmps on Windows.

@sean-mcmanus In my case, I'm on macOS, I've several Microsoft.VSCode.CPP.Extension.darwin_2017-03-10...crash files. Is there a place/email address where I can send/upload these files?

Can you email them to [email protected] ?

I've just sent them, I hope it helps!

We just released 0.10.4 with some improvements for switch header/source. Can you install the update and let us know if we've resolved your issues?

Yes, the issue is fixed with the latest version.
Thanks!

I have this problem in 2018.
My .h files are in "${workspaceRoot}/Proj/Public",
.cpp files are in "${workspaceRoot}/Proj/Private",

can't switch by either Alt+O or right click menu.

both these folders exist in browse.path and includePath of c_cpp_properties.json

Any clues?

I have this problem in 2018.
My .h files are in "${workspaceRoot}/Proj/Public",
.cpp files are in "${workspaceRoot}/Proj/Private",

can't switch by either Alt+O or right click menu.

both these folders exist in browse.path and includePath of c_cpp_properties.json

Any clues?

Same here, I have the same, unable to switch header/source, with version 1.32.2 on Windows 10.
the VSCode setup on ubuntu doesn't have this issue.
Cheers.

Was this page helpful?
0 / 5 - 0 ratings