Following are the extensions required for neovim:
I use lazy.nvim
so, just add the following to your plugins table, or create a new file in lua/plugins/lsp.lua
return {
{
"williamboman/mason.nvim",
config = function()
require("mason").setup({})
end,
},
{
"williamboman/mason-lspconfig.nvim",
config = function()
require("mason-lspconfig").setup({
ensure_installed = { "lua_ls", "clangd" },
})
end,
},
{
"neovim/nvim-lspconfig",
config = function()
local lspconfig = require("lspconfig")
lspconfig.lua_ls.setup({})
lspconfig.clangd.setup({})
end,
},
}
I've made a script to do all this for you:
$ cd path/to/the/project
$ curl https://gist.githubusercontent.com/ironlungx/a2b620de74f875c49c1d06999a8c41f8/raw/3f0d5d46c0d6369fc7e51e32487772ac194c27b1/script.sh | sh
$ pio run -t compiledb
BUT I DONT LIKE curl|sh
:
-
Initialize a project with
pio init
-
In the project root create the following files
.clangd
:CompileFlags: Add: [ # -mlong-calls, -DSSIZE_MAX, -DLWIP_NO_UNISTD_H=1, -Dssize_t=long, -D_SSIZE_T_DECLARED, ] Remove: [ -fno-tree-switch-conversion, -mtext-section-literals, -mlongcalls, -fstrict-volatile-bitfields, -free, -fipa-pta, ]
.clang-tidy
:Checks: '-*, -misc-definitions-in-headers'
gen_compile_commands.py
:import os Import("env") # include toolchain paths env.Replace(COMPILATIONDB_INCLUDE_TOOLCHAIN=True) # override compilation DB path env.Replace(COMPILATIONDB_PATH="compile_commands.json")
-
Now add the following to your platformio.ini
extra_scripts = pre:gen_compile_commands.py
-
Now in your terminal run:
pio run -t compiledb
(Just delete the oldcompile_commands.json
before executing this)
Hopefully this helped, I spent a lot of time figuring it out
Hey, I just want to say thanks to you I manage to get my neovim C lsp to pick up the path to the file correctly. Given the fact that I also used clang on my Mac it make sense that I would probably need to configure a .clang file lol. That being said, I don't really understand what is happening here in all the setting script, so if you could add explanation line by line, that would be a really great addition for future users to learn more and contribute back to your solutions if there are errors that we might encounter. Once again, thanks for your efforts!