Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch between header/source doesn't find correct file in trivial cases. #1617

Open
akb825 opened this issue May 3, 2023 · 2 comments
Open

Comments

@akb825
Copy link

akb825 commented May 3, 2023

When header and source files are in separate folders, swapping between header and source files fail in trivial situations:

  1. .h and .cpp files with the same name but different folders will fail to swap if the contents are empty.
  2. Similar to the above point, if there are build errors it may fail to execute the swap.
  3. If a header only contains forward declarations and functions (no class definition), it will go to the file that contains the first class declaration.

For an example of point 3, see test-switch.tar.gz. This was tested with Qt Creator 10.0.0, which currently uses the clangd code model to handle header/source switches.

  1. Open Foo.cpp.
  2. Execute Switch Header/Source, it will correctly switch to Foo.h.
  3. Execute Switch Header/Source again from Foo.h, notice how instead of switching to Foo.h it switches to Bar.h as the "source" file.
  4. If you delete the class Bar; forward declare and change the function declaration to void foo(class Bar& bar);, executing Switch Header/Source correctly switches to Foo.cpp.

Logs

log.txt

System information

Output of clangd --version:
clangd version 16.0.2 (https://github.com/llvm/llvm-project 18ddebe1a1a9bde349441631365f0472e9693520)
Features: linux+grpc
Platform: x86_64-unknown-linux-gnu

Editor/LSP plugin: Qt Creator 10.0.0

Operating system: Arch Linux

@akb825 akb825 changed the title Switch between header/source finds incorrect files in trivial cases. Switch between header/source doesn't find correct file in trivial cases. May 3, 2023
@HighCommander4
Copy link

See #1043 for some discussion of how this feature currently works.

I think the "file index" approach discussed in this comment is a promising one and should address the case of files with the same name in different directories, regardless of their contents.

There are probably opportunities to improve the content-based heuristics as well, but the above sounds like the bigger bang for buck overall.

@akb825
Copy link
Author

akb825 commented May 3, 2023

I agree, I think a file index and using heuristics based on that would handle situations like this much better overall. Care would need to be taken if there's multiple files with the same name, though, ideally ties would be broken based on more similar paths. (e.g. if multiple internal projects with a Foo.h and Foo.cpp pair, one heuristic could be to match the companion that has the fewest directories to a common root)

I saw that issue earlier, but it looks like their fix only resolved issues for differing case for case-insensitive filesystems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants