Skip to content

Instantly share code, notes, and snippets.

@sbmueller
Created July 14, 2022 07:54
Show Gist options
  • Save sbmueller/62032706f08db397c2679c5184776ead to your computer and use it in GitHub Desktop.
Save sbmueller/62032706f08db397c2679c5184776ead to your computer and use it in GitHub Desktop.
Wrapper around clangd that executes the server on host or in a docker container - from https://github.com/neovim/nvim-lspconfig/wiki/Running-language-servers-in-containers
#! /bin/sh
# The name of the container to run `clangd` in must be passed as the first and only argument
[ "$#" -ne 1 ] && echo "Container name required as first and only argument" >&2 && exit 1
CLANGD_ARGS="--clang-tidy --background-index --all-scopes-completion --header-insertion=iwyu --suggest-missing-includes --completion-style=detailed"
PATH_MAPPINGS="host=docker,host=docker" # change me
# Verify that a contianer by this name actually exists, and is running
if [ -z "$(docker ps -q -f name=$1 -f status=running)" ]; then
clangd $CLANGD_ARGS
else
# Important part here is both the '-i' and the redirection of STDERR
docker exec -i "$(docker ps -q -f name=$1 -f status=running)" /home/dev/.local/bin/clangd $CLANGD_ARGS --path-mappings="$PATH_MAPPINGS" 2>/dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment