-
Notifications
You must be signed in to change notification settings - Fork 113
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
CMD+ALT+Click on a header file opens the source file twice in two separate editors #711
Comments
I can reproduce this, but I don't think it's an issue in vscode-clangd or the clangd server. The only involvement clangd has in this process is that the clangd server responds to The code for sending these requests, and for responding to any clicks on the links and opening any new editors, lives in the |
For good measure, I did double check that in a simple scenario where I open a source file with one #include and then click on the #include, clangd only gets one |
But why does it only happen when clicking a header include? It does not happen when clicking a symbol. When clicking a symbol with ALT+CMD, it just opens the file containing the symbol in the editor to the right, which is exactly the expected behavior. If the issue is in VSCode itself, shouldn't it always misbehave the same way? Are you sending the same data to VSCode in both cases? And I already did file a VSCode issue (microsoft/vscode#232725) as I also thought it probably is the IDE itself handling this case incorrectly but that was before I noticed that it only happens for headers and does work for other symbols. |
Your comment made me realize what is going on here. There are two different editor features at play here:
For Now, it looks like VSCode binds the same shortcut, Ctrl+Alt+Click (or Cmd+Alt+Click on Mac), to both of these editor features. This is why two copies of the target file are opened. I'm not quite sure whether that makes this a VSCode bug or not. I would say clangd has a good reason for supporting both
So, I don't think we'd want clangd to stop doing either of these. I think it would be better if this was fixed on the VSCode side by e.g. making it so that if there is a document link at a given position, then Ctrl+Alt+Click does not also invoke |
By the way, a workaround I can think of is to disable document links (possibly only for C/C++ source files) as discussed in this comment. |
This works, yet requires
but has the downside that when you have includes with paths
now Maybe I can get some feedback from the VSCode devs what they think about it. If they think clangd should not behave that way or if documentLinks must take precedence over definitions (or the other way round). Triggering two distinct actions with only one click just doesn't seem meaningful to me. |
I thought this is a VSCode issue but I can only reproduce that issue when clicking C header files and have the clangd extension enabled (well, without that extension I cannot click C header files to begin with but I don't see that issue when clicking C symbols or symbols in any other language).
Steps to Reproduce:
Expected behavior:
The editor to the right now shows the clicked header file. Alternatively a 3rd editor opens that shows the header file and the middle editor still shows file B. Both could be expected, yet I would expect the first one to happen.
Actual behavior:
The editor to the right now shows the header file but another editor is also opened and this editor also shows header file. The header file is now shown twice in an existing and a new editor.
Screenshots:
Initial situation:
I hold CMD+ALT and click on
em_asm.h
and this is what I get:Note how the editor to the right changes to
em_asm.h
but also note there is also a third editor now that also shows that file.System information
Clangd version (from the log, or
clangd --version
): Apple clangd version 16.0.0 (clang-1600.0.26.3)clangd extension version: v0.1.29
Operating system: macOS 14.6.1
The text was updated successfully, but these errors were encountered: