-
Notifications
You must be signed in to change notification settings - Fork 60
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
Jump into header files instead of source file #1592
Comments
The real problem is, I tried to create a new
So we can know that the database is successfully imported here, however the |
Another example, directly open certain file, no error tells
|
I suggest you could develop a tiny demo project to present what you've encountered -- Sorry but we really have no idea what kind of stuff like |
Sorry ,I can hardly do such thing... Because this project is imported from damn Keil, a embedded develop environment, which has something called |
Could you share a full set of logs (from clangd startup, until after you've performed the jump that goes to the unexpected file) please? In addition, please mention the path of the file you expected to jump to. |
Sure, this is the project structure, I'd like to jump from gpio.hpp(here #include "stm32f4xx.h") to stm32f4xx_gpio.c:
|
A couple of follow-up questions:
|
For question1: yes I wonder is there any problem with mixed c/c++ programming, because I use both in this project, maybe the clangd failed to recognize .h file as a c header |
An interesting phenomenon is that if I try to open every source file once, it can jump to correct position then... But if I reload the vscode, it failed again. |
This is actually because how clangd finds definition of a symbol. The following is my explanation (I may be partially wrong as I'm not a clangd dev)
If my theory were correct, you might see output in clangd extension like below:
|
I did't find any clue for "Failed to compile", beside, I tried to delete the
|
By the way, I'd like to provide a typical entry in
|
I have looked into another issue which the problem is caused by mismatch version of clang and clangd, I use armclang for compile and clangd 16.0.1 for database, I wonder whether the critical point is here. |
In theory, a version match between the build compiler and clangd shouldn't be required. In #1348, the bug reporter said they solved the problem by changing clangd version, but we never got to the bottom of why things didn't work with the other version. That said, I don't really have any theories based on the posted information. If you're able to replicate the issue in a project small enough that you can zip up the whole project and share it, I'm happy to try and replicate it locally and investigate further. |
Thanks, I'll find a way to shrink down my project later.
|
The entry looks fine to me. For an
Notice the |
As you asked for, this is a very small project which suffers exactly the same problem, forgive me because the project structure is a little bit different from what I have described upon. |
If you find any confusion about the project struct, please inform me... |
When I run $ make
make: *** No rule to make target 'build/main.o', needed by 'build/temp.elf'. Stop. I'm a bit rusty on my |
I believe this is because I use the armclang compiler, it's cross-compiler, you may have missed it. |
Any way, I have built the project before I upload it, it should contain the |
I don't think I can use your |
Do you mean |
Yes, I do mean |
If you don't mind, you can install this extension and setup following here, then double click the |
I've done that, but I don't see how it helps with the previous issue. I still need to re-generate the |
The |
I took a different approach: I took your Now clangd seems to be able to parse the project files successfully, and I can reproduce the bug! To give a concrete example:
And I will investigate further when I get a chance. |
From #1592 (comment):
Sorry I missed it. So, it is reported that we're jumping into headers all the time unless we manually open the counterpart source at least once. |
Great! |
I DO mean something like that. |
My |
My log shows errors like this:
but the file does exist. Very strange. |
It turns out my problem was that due to the the search-and-replace I had performed in the
and it seems the indexer does not like mixed-slash paths like this. (But, interestingly, in the error message the path is normalized to be all forward slashes! You'd think, that if the machinery for printing the error message can normalize the path like this, then the code for actually processing the file in the indexer could too...) Anyways, after correcting the path to consistently use forward slashes, the bug is fixed: now, the first go-to-def after starting vscode goes directly to stm32f4xx_hal_rcc.c. @Eplankton I am curious if this is the same issue you're experiencing: is your project's |
I quote some part of the log that might be useful to analysis,does it mean that the index process is correct?:
|
Ok, since you do have index files, I guess you're running into a different issue than I was. Unfortunately, I can't reproduce your issue (it works for me after fixing my mixed-slash issue). Perhaps your issue is specific to Windows? Maybe someone else who is a Windows user can try to reproduce and investigate further. |
OK, I'll continue to work on it. |
Well, how about #1138 (comment) ? |
Now I discover a weird way to get the correct jump and requires only steps, i have already tested it with no change to my
|
Also, I wonder whether #1317 (comment) is a problem. |
I don't think #1317 relates to your issue as it was closed early in 2022/11 and the clangd you're using is released a few weeks ago. Neither does #1138 because a workaround for that is to add
But you could take a try, just add it to your |
After days and days of work and check and waste of my life, I have to say that I'm so exhausted to find out the real problem is case-sensitive on Windows platform, it was mentioned here #108 (comment), so there's a very simple way to solve : JUST CHANGE EVERY |
Many people has also complain about it: #102 (comment) |
Happy to hear that you've worked it out. BTW, did you generate your |
Yes, I'm now working on it... |
I have already read many people report that their clangd doesn't jump to defintion unless they open that file for at least one time, I have checked my compile_commands.json and ensure that certain src files are in there,
however, when trying to go to the definition, the log will say something like:
You can see that the clangd start in
template
folder, I set the compiler_commands_dir as nothing to avoid disturb, when I open the main.cpp file, it strangely read the database from USR/build:The text was updated successfully, but these errors were encountered: