-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclangd
executable file
·40 lines (30 loc) · 897 Bytes
/
clangd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
export TMPDIR=/tmp/clangd
mkdir -p $TMPDIR
if [ -n "$CLANGD" ]; then
exec $CLANGD "$@"
fi
file1="compile_commands.json"
file2="build/compile_commands.json"
if [ -f "$file1" ]; then
compile_commands_file="$file1"
elif [ -f "$file2" ]; then
compile_commands_file="$file2"
fi
if [ -f "$compile_commands_file" ]; then
command=$(jq --raw-output '.[0].command' "$compile_commands_file")
executable=$(echo "$command" | sed -E 's|([^ ]*/)[^ ]+.*|\1clangd|')
if [ -x "$executable" ]; then
exec "$executable" "$@"
fi
fi
exclude_dir=$(dirname "$0")
original_path="$PATH"
filtered_path=$(echo "$original_path" | tr ':' '\n' | grep -v "^$exclude_dir\$" | tr '\n' ':' | sed 's/:$//')
export PATH="$filtered_path"
clangd_path=$(command -v clangd)
if [ -z "$clangd_path" ]; then
echo "clangd not found in PATH."
exit 1
fi
exec clangd "$@"