145 lines
3.7 KiB
Markdown
145 lines
3.7 KiB
Markdown
# LSP Setup for Warp Pipe
|
|
|
|
This project uses GCC 15 from Homebrew, which requires special configuration for clangd to find standard library headers.
|
|
|
|
## Files Created
|
|
|
|
1. **compile_commands.json** (symlink to build/compile_commands.json)
|
|
- Tells clangd how files are compiled
|
|
|
|
2. **.clangd** - Configuration file
|
|
- Points clangd to the compilation database
|
|
|
|
3. **clangd-wrapper.sh** - Wrapper script with --query-driver flag
|
|
- Helps clangd extract system includes from GCC
|
|
|
|
4. **.envrc** - Environment variables for LSP
|
|
- Sets CLANGD_FLAGS to configure clangd globally
|
|
|
|
## Using the LSP
|
|
|
|
### Option 1: Use CLANGD_FLAGS Environment Variable (Easiest)
|
|
|
|
Set the environment variable in your shell before starting your editor:
|
|
|
|
```bash
|
|
export CLANGD_FLAGS="--query-driver=/home/linuxbrew/.linuxbrew/bin/g++"
|
|
```
|
|
|
|
Add this to your `~/.bashrc` or `~/.zshrc` to make it permanent.
|
|
|
|
**Using direnv (Recommended for per-project setup):**
|
|
1. Install direnv: `brew install direnv`
|
|
2. Copy `.envrc.example` to `.envrc` (or use the existing `.envrc`)
|
|
3. Run `direnv allow` in the project directory
|
|
4. The environment will be set automatically when you cd into the project
|
|
|
|
**Neovim users**: If you start Neovim from the shell with the env var set, clangd will automatically pick it up.
|
|
|
|
**VS Code users**: Add to your workspace settings (.vscode/settings.json):
|
|
```json
|
|
{
|
|
"terminal.integrated.env.linux": {
|
|
"CLANGD_FLAGS": "--query-driver=/home/linuxbrew/.linuxbrew/bin/g++"
|
|
}
|
|
}
|
|
```
|
|
|
|
### Option 2: Use clangd-wrapper.sh
|
|
|
|
Configure your editor to use `/var/home/joey/Projects/warppipe/clangd-wrapper.sh` instead of `clangd`.
|
|
|
|
**Neovim (nvim-lspconfig)**:
|
|
```lua
|
|
require('lspconfig').clangd.setup{
|
|
cmd = { vim.fn.getcwd() .. '/clangd-wrapper.sh' }
|
|
}
|
|
```
|
|
|
|
**VS Code (settings.json)**:
|
|
```json
|
|
{
|
|
"clangd.path": "/var/home/joey/Projects/warppipe/clangd-wrapper.sh"
|
|
}
|
|
```
|
|
|
|
### Option 3: Pass --query-driver via Editor Config
|
|
|
|
Add to your editor's clangd configuration:
|
|
|
|
**Neovim**:
|
|
```lua
|
|
require('lspconfig').clangd.setup{
|
|
cmd = { 'clangd', '--query-driver=/home/linuxbrew/.linuxbrew/bin/g++' }
|
|
}
|
|
```
|
|
|
|
**VS Code (settings.json)**:
|
|
```json
|
|
{
|
|
"clangd.arguments": ["--query-driver=/home/linuxbrew/.linuxbrew/bin/g++"]
|
|
}
|
|
```
|
|
|
|
### Option 4: Install llvm/clang++ from Homebrew
|
|
|
|
```bash
|
|
brew install llvm
|
|
```
|
|
|
|
Then rebuild with clang++ (requires libstdc++ setup).
|
|
|
|
## Neovim with coc.nvim Setup
|
|
|
|
### 1. Install coc-clangd
|
|
|
|
In Neovim, run:
|
|
```vim
|
|
:CocInstall coc-clangd
|
|
```
|
|
|
|
### 2. Configure coc-clangd
|
|
|
|
**Option A: Project-specific (Recommended)**
|
|
|
|
A `.vim/coc-settings.json` file has been created in this project with the correct configuration. Just open Neovim in this directory and it will work automatically.
|
|
|
|
**Option B: Global configuration**
|
|
|
|
Edit `~/.config/nvim/coc-settings.json` (or create it):
|
|
```json
|
|
{
|
|
"clangd.arguments": [
|
|
"--background-index",
|
|
"--clang-tidy",
|
|
"--query-driver=/home/linuxbrew/.linuxbrew/bin/g++"
|
|
],
|
|
"clangd.path": "/home/linuxbrew/.linuxbrew/bin/clangd"
|
|
}
|
|
```
|
|
|
|
**Note**: The global config will apply the `--query-driver` to all projects, which might cause issues for non-Homebrew projects. The project-specific config (Option A) is safer.
|
|
|
|
### 3. Restart coc
|
|
|
|
After configuration:
|
|
```vim
|
|
:CocRestart
|
|
```
|
|
|
|
## Verifying LSP Works
|
|
|
|
After configuration, open any C++ file and check:
|
|
- Autocomplete works
|
|
- Go-to-definition works (F12/gd)
|
|
- No errors on standard library includes (<vector>, <string>, etc.)
|
|
|
|
## Troubleshooting
|
|
|
|
If you still see "file not found" errors for standard headers:
|
|
1. Ensure you're using the wrapper script
|
|
2. Restart your LSP server
|
|
3. Check that GCC 15 is still at the same path:
|
|
```bash
|
|
ls -la /var/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0/include/c++/15
|
|
```
|