1

I'm separating the functions from main.c to func1.c func2.c, then I'm using util.h to store the prototype (all name of all functions).

PROBLEM

when I try to go to implementation, lsp leading me into util.c, but i want to leading to func1.c

main.c

#include "util.h"

int main(){
  int x = fun||c1(); // here || is cursure location !
  int y = funct2();
  //...
}

util.c

#define TRUE 1
#define FALSE 0
int func1();
int func2();
//...

func1.c

int  func1(){
  //...
}

Makefile

all: main

main: func1.o func2.o ... main.o
    gcc func1.o func2.o ... main.o -o main

func1.o: func1.c util.h
    gcc func1.c

func2.o: func2.c util.h
    gcc func2.c
#...

my env:

i use:

  • neovim as ide
  • lspconfig plugin handle lsp
  • ccls/clangd is tow lsp for c/cpp
  • :lua vim.lsp.buf.implementation() go to implementation but lead me to util.h
  • :lua vim.lsp.buf.definition() go to definition but lead me to util.h too

2 Answers 2

1

The location of the implementation depends on the way the project is built. You can tell clangd about this using compile_commands.json.

You can generate this file using bear: bear -- make.

Bear is probably available in your package manager.

2

As far as I know, clangd is not able to jump to func1() via "Go To Definition" or "Find References" capabilities because there is not a direct link to func1.c.

As an alternative, you can use tags. You will need to install one of the flavors available (:h ctags). I recommend the package universal-ctags. Run ctags -R . in your root directory and simply type <c-]> to go to the first match or g <c-] to show a list if there are several matches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.