5

I'm currently Studying Computer enginering and taking embeded systems class, My isuse is that we use a custom library then compile it in a old version of Codewarrior.

how I would go about creating an include path for my lsp with nvim

I was woundering how I would go about creating an include path for my lsp with nvim, when I am not compiling the code localy but later compiling it with an old IDE

any wisdom would be apreciated.


note: in class we are required to use an exterior editor and the older version of code warrior is verry bad it is used for compiling for our micro controler but is unusable for writting code.


things I have done

  • I have attempted using compile_commands.json by copying my VSCode config for path location
  • I have tried using a .clangd file with -I ...
  • I have tried other method but had no sucess so far

over all I was hopping to find a solution and have poured over the getting started page and stack overflow for several hours trying different method to no avail.

the .clangd file I used:

CompileFlags: # Tweak the parse settings
Add: -I=[${workspaceFolder}/**]
     -I=[${workspaceFolder}/lib/Inc]
     -I=[~/Documents/github/libraries/lib/**]
     -I=[~/Documents/github/libraries/lib\hc12c\lib/**]
4
  • I think the simplest approach in your case is the .clangd file. If it's not working, please provide some details such as: (1) the contents of your .clangd file, (2) an example error you get, and (3) clangd logs. Commented Feb 3, 2023 at 19:32
  • CompileFlags: # Tweak the parse settings Add: ` - "-I=[${workspaceFolder}/**]" ` ` - "-I=[${workspaceFolder}/lib/Inc]"` - "-I=[~/Documents/github/libraries/lib/**]" - "-I=[~/Documents/github/libraries/lib\hc12c\lib/**]" currently I have a header file located in /home/bjc1269/Documents/github/libraries/lib/hc12c/include but it is telling me that "file not found" Commented Feb 3, 2023 at 20:18
  • Can you edit your answer please to show the file contents in a multi-line code block? Anyways, several things there look wrong (for example, variable expansions like ${workspaceFolder} are not supported). Commented Feb 4, 2023 at 0:07
  • The configs must have exact paths. No ${...}, and probably no *. Commented Feb 5, 2023 at 4:00

2 Answers 2

10

The easiest approach is probably to use a .clangd file. Based on the path in your comment, the .clangd file should look like this:

CompileFlags:
  Add: -I/home/bjc1269/Documents/github/libraries/lib/hc12c/include

A few things that I'm seeing in the .clangd file in your comment that don't work are:

  • Variable substitutions like ${workspaceFolder}. This is a VSCode feature that works in some VSCode settings like "clangd.arguments", but is not supported in a .clangd file, which is editor-agnostic (for example, it works with editors that don't have a concept of a "workspace").
  • Referring to your home directory as ~. Expanding ~ to /home/<username> is a feature of your shell. Command-line arguments specified in .clangd are passed directly to the compiler without being processed by the shell, so ~ will not work.
  • Globs like **. To be honest, I'm not even sure what the intended semantics for this could be in the context of specifying include directories.
  • Square brackets inside the argument to -I. Square brackets may appear in a .clangd file as YAML syntax for specifying multiple values in a list, for example you might have:
    CompileFlags:
      Add: [-I/path/to/directory1, -I/path/to/directory2]
    
    But if you write -I=[/path/to/directory], the brackets just get passed on verbatim to the compiler, which does not understand this syntax.
Sign up to request clarification or add additional context in comments.

Comments

2

I'd recommend to use bear for this. You just simply invoke it with your build-command and the clangd LSP will read the includes automatically.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.