Clangd lsp with pio HELP?

im try to get pio to use clangd as the lsp for neovim and i dont know what i doing wrong
what ive done so far is run pio run -t compiledb and i get compiled_commands.json i havent added anythong to the platformio.ini is there anyone who can help me who has more knowledge of clangd and pio than me?

machine/endian.h sounds very much like a toolchain internal file.

Did you enable toolchain includes per Compilation database compile_commands.json — PlatformIO latest documentation?

no and ive read the page over and over and i just can understand that part if you could please explain it better that would be a huge help [|=)]

You have your project folder. There is a platformio.ini. Like the documentation says, you add to the end of it a

extra_scripts = pre:extra_script.py

and in the project folder you then create a file called extra_script.py with content

import os
Import("env")

# include toolchain paths
env.Replace(COMPILATIONDB_INCLUDE_TOOLCHAIN=True)

# override compilation DB path
env.Replace(COMPILATIONDB_PATH=os.path.join("$BUILD_DIR", "compile_commands.json"))

and then you run the command to generate the compilation database again, pio run -t compiledb.

@maxgerhardt thank you i did what you posted and i also deleated the compiled_commands.json in the root as well as the .pio folder since its temp files and will be rebuild when running pio run
after all of that i ran pio run -t compiledb and it now seems to be put in the .pio/builld/whateverboard
there in that folder clangd doesnt even find it and it dispalys errors all over the place

If the output path of the compile_commands.json is a problem, change the path here from

to just

env.Replace(COMPILATIONDB_PATH="compile_commands.json")
1 Like

@maxgerhardt thank you thank you again you saved me lots of hours and its mostly working but i get two errors at the top of my file these dont need to be fix i just want to ask if you now anything about them
thank you again youre a huge help :grin: