Since getting LSP to work is very finicky this guide provides two methods to get LSP working. Try both of them and use the one with the least errors
- Method 1: Using
clangd - Method 2: Using
ccls
⭐ If you find this project useful, consider starring the repo to help it gain visibility!
- Clone the repo (if using Method 1):
git clone https://github.com/ironlungx/nvim-pio PROJECT_NAME
cd PROJECT_NAME- Set up your PlatformIO project:
- Edit
platformio.inito set yourboardandplatform - Run:
pio init --ide vimUse your system package manager or install via Mason
python3 conv.pyInstall the following Neovim plugins (using lazy.nvim or your preferred manager):
return {
{
"williamboman/mason.nvim",
config = function()
require("mason").setup({})
end,
},
{
"williamboman/mason-lspconfig.nvim",
config = function()
require("mason-lspconfig").setup({
ensure_installed = { "clangd", "lua_ls" },
})
end,
},
{
"neovim/nvim-lspconfig",
config = function()
local lspconfig = require("lspconfig")
lspconfig.lua_ls.setup({})
lspconfig.clangd.setup({
cmd = { "clangd", "--background-index" },
})
end,
},
}- Open Neovim inside your project folder.
- LSP should now work. If not, feel free to open an issue.
Follow the install guide on ccls GitHub
Run:
pio init --ide vim
pio run -t compiledbIn your Neovim config:
vim.lsp.config("ccls", {
init_options = {
diagnostics = {
onChange = 100,
},
},
})
vim.lsp.enable("ccls")
-- Optional: Fallback to clangd if .ccls doesn't exist
if vim.fn.filereadable(vim.uv.cwd() .. "/.ccls") == 0 then
vim.lsp.enable("clangd")
endEvery time you modify project libraries or config:
pio init --ide vim && pio run -t compiledb- Use clangd if you're looking for easier setup and performance.
- Use ccls if you prefer
.ccls-based workflows or have specific compatibility needs.
Found a better way or improvement? Open a PR or issue!