> [!Caution] > I've moved this gist over to a template repository [here](https://github.com/ironlungx/nvim-pio/). > Everything here is unmaintained... # Extensions Following are the extensions required for neovim: * [mason](https://github.com/williamboman/mason.nvim) * [mason-lspconfig](https://github.com/williamboman/mason-lspconfig.nvim) * [lspconfig](https://github.com/neovim/nvim-lspconfig) I use `lazy.nvim` so, just add the following to your plugins table, or create a new file in `lua/plugins/lsp.lua` ```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({}) -- Minimal setup end, }, } ``` For the LSP server setup (as recommended by @omani) this is what I use, it improves auto complete functionality ```lua lspconfig.clangd.setup({ on_attach = on_attach, capabilities = capabilities, cmd = { "clangd", "--background-index", "-j=12", }, }) ``` # Setting up the project **I've made a script to do all this for you**: ```bash $ cd path/to/the/project $ curl -sSL https://gist.github.com/ironlungx/a2b620de74f875c49c1d06999a8c41f8/raw/script.sh | sh $ rm compile_commands.json $ pio run -t compiledb ``` **__BUT I DONT LIKE `curl|sh`__**: 1. Initialize a project with `pio init` 2. In the project root create the following files - `.clangd`: (thanks @omani for fixing and adding flags to the file) ```yaml # clangd controls options for the LSP *server* CompileFlags: Add: [ -DSSIZE_MAX, -DLWIP_NO_UNISTD_H=1, -Dssize_t=long, -D_SSIZE_T_DECLARED, -Wno-unknown-warning-option ] Remove: [ -mlong-calls, -fno-tree-switch-conversion, -mtext-section-literals, -mlongcalls, -fstrict-volatile-bitfields, -free, -fipa-pta, -march=*, -mabi=*, -mcpu=* ] Diagnostics: Suppress: "pp_including_mainfile_in_preamble" ``` - `.clang-tidy`: (thanks @omani for adding more flags!) ```yaml Checks: '-*, -misc-definitions-in-headers' # Fixes some issue with header reinclusion IndentWidth: 2 # Only if you like 2, replace with 3/4/.. if you'd like ``` - `gen_compile_commands.py`: ```python import os Import("env") # platformio specific stuff # include toolchain paths (i.e. to have stuff like the Arduino framework headers present in the compile commands) env.Replace(COMPILATIONDB_INCLUDE_TOOLCHAIN=True) # override compilation DB path env.Replace(COMPILATIONDB_PATH="compile_commands.json") ``` 3. Now add the following to your platformio.ini ```ini extra_scripts = pre:gen_compile_commands.py ``` 4. Now in your terminal run: `pio run -t compiledb` (Just delete the old `compile_commands.json` before executing this) Hopefully this helped, I spent a lot of time figuring it out