0

I am using Neovim (LunarVim IDE layer), I want to work with 'openFrameworks' library. To not get linter warning on header file includes (look at example below), I am adding all possible header files to my $CPLUS_INCLUDE_PATH and $LIBRARY_PATH (code shown below).

Is there a better way I can achieve my LSP knowing the header file contents? Vs-Code somehow achieves all that.

I want to achieve this in Neovim. In this temporary fix, whenever a new header is not in path, I have to find it in the library folder and add to my ~/.bashrc, so I am struggling.

Please help.

The warnings: warnings-on-neovim-linter-header-files-includes

The annoying temporary fix, is there anything better that I can do?

# ~/.bashrc

# openFrameworks
openFrameworks="/opt/homebrew/Caskroom/openframeworks/0.12.0/of_v0.12.0_osx_release"
include_dirs=(
    "/libs/openFrameworks/"
    "/libs/openFrameworks/math"
    "/libs/openFrameworks/utils"
    
    ...

    "/libs/uriparser/include"
    "/libs/glm/include"
    "/libs/FreeImage/include"
)

include_path=""
for dir in "${include_dirs[@]}"; do
    include_path+=":${openFrameworks}/${dir}"
done

export LIBRARY_PATH="$include_path:$LIBRARY_PATH"
export CPLUS_INCLUDE_PATH="$include_path:$CPLUS_INCLUDE_PATH"

I had tried bear, but I am getting the following error:

RPC[Error] code_name = UnknownErrorCode, message = "Failed to parse includes"

RPC[Error] code_name = UnknownErrorCode, message = "Failed to parse includes"

Edit1: Also, although the linter errors on header includes have gone away, the LSP features like autocompletion etc, are not working. How do I let my editor (Neovim - LunarVim) know about those header files, or should I give up and switch to an IDE?

Edit2: related: (not fixed)[https://neovim.discourse.group/t/lsp-rpc-error-codes-printed-at-neovim-exit-starting-from-0-8-0/3736]

4
  • Would that answer help you? Sep 16 at 5:47
  • 1
    No, not really, @VivianDeSmedt because I am already using compile_commands.json Sep 17 at 6:22
  • Thanks for the feedback :-) Sep 17 at 7:37
  • If you are satisfied with your answer maybe could you accept it using the v button next to the arrow voting buttons. It allow the question to rest :-) Sep 20 at 4:50

1 Answer 1

0

Solved it by installing llvm from brew,

Paying attention to the caveats, added the following in bashrc (or similar):

export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"

and then adding this in lvim config:

local nvim_lsp = require("lspconfig")

nvim_lsp.clangd.setup {
    cmd = { "/opt/homebrew/opt/llvm/bin/clangd", "--background-index" },
    root_dir = nvim_lsp.util.root_pattern("compile_commands.json", ".clangd"),
}

Edit: So the problem was using an old version of clangd, and having two versions of clang (one installed through Mason and other was the builtin). I installed llvm clangd and followed the above steps.

Your Answer

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

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