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

Implementation of Go to Definition in the clangd LSP editor #175

Closed
kolipakakondal opened this issue Aug 10, 2023 · 8 comments
Closed

Implementation of Go to Definition in the clangd LSP editor #175

kolipakakondal opened this issue Aug 10, 2023 · 8 comments
Milestone

Comments

@kolipakakondal
Copy link
Contributor

kolipakakondal commented Aug 10, 2023

Currently, the "Open Declaration" feature(By pressing F3 key) is functional in navigating to header files, but it lacks the ability to navigate to the corresponding source definitions (Open Implementations) of those header files.

Is there a way which we could achieve this for LSP/clangd editors?

Context:
For Make projects - we are able to achieve this using Include Paths configuration
For CMake projects in the core build system - Probably creating a virtual/symbolic link files with in the project for the library sources worked based on the compile_commands.json

Now for Clangd C/C++ based editor - how could we achieve this with the information what we have from compile_commands.json file?

@ghentschke
Copy link
Contributor

Sorry I didn't get it. It works for my test project when header with class declaration and source file with class implementation are in the same project:
image

Steps to reproduce:

  1. Close all open files. LS must be terminated.
  2. Open header file with class or variable definition (here header2.hpp).
  3. Pressing F3 on a class definition opens the source file with the class implementation (here Cmk1.cpp)

I did not had to compile the code after adding #include "/include/header2.hpp to Cmk1.cpp and implementing the class here.

Can you please give an example of your use case?

@kolipakakondal
Copy link
Contributor Author

kolipakakondal commented Aug 10, 2023

Hi @ghentschke Absolutely, you're correct. The functionality works well when the implementation classes reside within the project. However, I'm referring to the navigation of system header implementations and external file includes source code, both of which are already included in the compile_commands.json file

#include <stdio.h>
#include "esp_cpu.h"

void app_main(void)
{
    printf("Hello world!\n");
     esp_cpu_reset(1);
}

For instance, in the given source code, the printf() function is defined in the stdio.h header, which is not included in the project's source code and same goes for esp_cpu_reset() which is an external file include. If we aim to view the source code for printf() and esp_cpu_reset() which is navigating only to the header files but the not the source definition files.

@ghentschke
Copy link
Contributor

If we aim to view the source code for printf() and esp_cpu_reset() which is navigating only to the header files but the not the source definition files.

What would be your expected behavior for i.e. printf? When I press F3 on printf I get to the system header implementation here:
image

@kolipakakondal
Copy link
Contributor Author

That's interesting! In mycase it shows up the header file with the declaration. Do you think should I configure anything else?

cdt_navigation.mov

I tried two different projects, all them shown only header.

printf() navigation
Screenshot 2023-08-11 at 12 19 34 PM

strcmp() navigation
Screenshot 2023-08-11 at 12 19 18 PM

Screenshot 2023-08-11 at 12 21 13 PM

@kolipakakondal
Copy link
Contributor Author

Hi @ghentschke Any pointers to troubleshoot this issue? clangd logs, CDT classes, etc? Thanks for the help

@ghentschke
Copy link
Contributor

ghentschke commented Aug 11, 2023

I am not sure if this already worked in the old editor? I assume that the function definition has been done in a system library (.a or .so). So there is no implementation file to jump into? The linker will fetch the code from there.

I am not sure how to handle the case when the implementation resides in a project in the same workspace. I'll check that on monday.

@ghentschke
Copy link
Contributor

ghentschke commented Aug 14, 2023

The Go-to-Definition (textDocument/implementation) seems to work only if the file which contains the implementation is in the same project or it is already opened in the new LSP based C/C++ editor. It seems to be rather a clangd and not a cdt-lsp or LSP4E issue. (see clangd #789 and #854 )

@kolipakakondal
Copy link
Contributor Author

Thanks you @ghentschke That helps. Agree with you. Feel free to close this issue.

P.S: However, I wonder how CLion and VSCode does this with clangd. I will check further on this.

@jonahgraham jonahgraham added this to the 1.0.0 milestone Sep 18, 2023
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

3 participants