1

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 atempted using compile_commands.json by coppying my vscode config for path location
  • I have tryed 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 diffrent method to no avail.

  • 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](https://clangd.llvm.org/troubleshooting#gathering-logs). – HighCommander4 Feb 03 '23 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" – Brandon Carpenter Feb 03 '23 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). – HighCommander4 Feb 04 '23 at 00:07
  • The configs must have exact paths. No `${...}`, and probably no `*`. – HolyBlackCat Feb 05 '23 at 04:00

2 Answers2

3

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.
HighCommander4
  • 50,428
  • 24
  • 122
  • 194
  • 1
    thanks this completely solved my issue, after putting it into a proper syntax it now recognizes any included information, thank you Ive been trying to figure this our for at least a month now. – Brandon Carpenter Feb 06 '23 at 15:39
0

First of all: Welcome to stackoverflow! :D

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.

TornaxO7
  • 1,150
  • 9
  • 24