-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathprplsp
More file actions
executable file
·53 lines (48 loc) · 1.74 KB
/
Copy pathprplsp
File metadata and controls
executable file
·53 lines (48 loc) · 1.74 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
# prplsp -- launch the Pyrope/LiveHD LSP server (lhd pyrope lsp)
#
# Picks which lhd to run based on the CURRENT WORKING DIRECTORY (the dir the
# editor launched in), so neovim can use a single command everywhere:
#
# 1. If $PWD is inside a livehd checkout, use that repo's freshly-built
# bazel-bin/lhd/lhd -- no copying/installing while hacking on the LSP.
# 2. Otherwise fall back to the `lhd` found in $PATH (the default install).
#
# A livehd checkout is identified by an ancestor MODULE.bazel declaring
# name = "livehd". Extra arguments are forwarded to lhd after `pyrope lsp`.
set -euo pipefail
# Walk up from $PWD looking for the livehd repo root (MODULE.bazel naming the
# "livehd" module). Prints the root on success; empty if not inside a checkout.
find_livehd_root() {
local dir
dir=$(pwd -P)
while [[ -n "${dir}" ]]; do
if [[ -f "${dir}/MODULE.bazel" ]] &&
grep -Eq 'name[[:space:]]*=[[:space:]]*"livehd"' "${dir}/MODULE.bazel"; then
printf '%s\n' "${dir}"
return 0
fi
[[ "${dir}" == "/" ]] && break
dir=$(dirname "${dir}")
done
return 1
}
if repo_root=$(find_livehd_root); then
repo_lhd="${repo_root}/bazel-bin/lhd/lhd"
if [[ -x "${repo_lhd}" ]]; then
lhd="${repo_lhd}"
else
echo "prplsp: inside livehd (${repo_root}) but no built lhd at" >&2
echo " ${repo_lhd}" >&2
echo " build it with: bazel build //lhd:lhd" >&2
echo " falling back to 'lhd' in \$PATH" >&2
fi
fi
# Fall back to PATH if not inside a checkout, or inside but not yet built.
if [[ -z "${lhd:-}" ]]; then
if ! lhd=$(command -v lhd 2>/dev/null); then
echo "prplsp: could not find lhd (not in a livehd checkout, and none in \$PATH)" >&2
exit 1
fi
fi
exec "${lhd}" pyrope lsp "$@"