-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathals
executable file
·152 lines (139 loc) · 3.73 KB
/
als
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
set -e
#set -x
detect_kind() {
path=$1
kind=
if [ -d $path ]; then
[ -f $path/Cargo.toml ] && kind=r
[ -f $path/go.mod ] && kind=g
[ -f $path/pubspec.yaml ] && kind=d
[ -f $path/build.zig ] && kind=z
[ -f $path/mix.exs ] && kind=e
elif [ -f $path ]; then
ext=${path##*\.}
[ $ext = "go" ] && kind=g
[ $ext = "rs" ] && kind=r
[ $ext = "dart" ] && kind=d
[ $ext = "zig" ] && kind=z
[ $ext = "c" -o $ext = "cpp" -o $ext = "cc" -o $ext = "h" ] && kind=c
[ $ext = "ex" -o $ext = "exs" ] && kind=e
fi
echo $kind
}
detect_root() {
kind=$1
root=$2
case $kind in
c)
while [ ! -e "$root/compile_commands.json" ] && [ "$root" != "/" ]
do
root=`dirname $root`
done
;;
d)
while [ ! -e "$root/pubspec.yaml" ] && [ "$root" != "/" ]
do
root=`dirname $root`
done
;;
e)
while [ ! -e "$root/mix.exs" ] && [ "$root" != "/" ]
do
root=`dirname $root`
done
;;
g)
while [ ! -e "$root/go.mod" ] && [ "$root" != "/" ]
do
root=`dirname $root`
done
;;
r)
while [ ! -e "$root/Cargo.toml" ] && [ "$root" != "/" ]
do
root=`dirname $root`
done
;;
z)
while [ ! -e "$root/build.zig" ] && [ "$root" != "/" ]
do
root=`dirname $root`
done
;;
esac
[ $root = "/" ] && root=
echo $root
}
get_root_from_win_envs() {
for l in `9p read acme/$winid/envs`; do
env=(${l//=/ })
[ "${env[0]}" = "lsp_root" ] && echo "${env[1]}" && break
done
}
if [ $# -lt 1 ]; then
echo "usage: $0 [command]"
exit 2
fi
cmd=$1
shift 1
[ -z "$winid" ] && [ -z "$(pgrep acmefocused)" ] && { echo "acmefocused not started"; exit 3; }
[ -z "$winid" ] && winid=`dial unix!$(namespace)/acmefocused`
[ -z "$winid" ] && { echo "failed to get current window id"; exit 3; }
file_path=`9p read acme/$winid/tag | cut -d' ' -f1`
kind=`detect_kind "$file_path"`
[ -z "$kind" ] && { echo "failed to detect kind based on $file_path"; exit 4; }
root=`get_root_from_win_envs`
[ -z "$root" ] && root=`detect_root "$kind" "$file_path"`
[ -z "$root" ] && { echo "failed to detect root based on $kind $file_path"; exit 5; }
session=`echo -n "$root"/+LSP | 9 tr .@ _`
if tmux has -t "$session" 2>/dev/null; then
[[ `tmux lsp -t "$session:1" -F '#{pane_dead}'` = 1 ]] && tmux respawnp -t "$session:1"
else
case $kind in
c)
tmux new -d -s "$session" -c "$root" lsp clangd --log=error
;;
r)
tmux new -d -s "$session" -c "$root" -e _lsp_format_on_save=1 lsp rust-analyzer
;;
g)
tmux new -d -s "$session" -c "$root" -e _lsp_format_on_save=1 lsp gopls serve
;;
d)
tmux new -d -s "$session" -c "$root" -e _lsp_format_on_save=1 lsp "sh", "-c", "dart $(dirname $(which dart))/snapshots/analysis_server.dart.snapshot --lsp"
;;
z)
tmux new -d -s "$session" -c "$root" -e _lsp_format_on_save=1 lsp zls
;;
e)
tmux new -d -s "$session" -c "$root" -e _lsp_format_on_save=1 lsp /home/tw/code/lexical/_build/dev/package/lexical/bin/start_lexical.sh
;;
*)
echo "Not supported: $kind"
exit 1
;;
esac
tmux set -p -t "$session:1" remain-on-exit on
tmux set -p -t "$session:1" monitor-silence 3600 # 1h
tmux set -p -t "$session:1" silence-action any
tmux set -p -t "$session:1" status-right 'silent for #{e|-|:#(date +%s),#{window_activity}}s'
tmux set-hook -p -t "$session:1" alert-silence "kill-session"
fi
case $cmd in
def)
tmux pipep -t $session:1 -I "echo open ""$file_path"" $winid && echo def ""$file_path"" `acme-dot -l $winid`"
;;
refs)
tmux pipep -t $session:1 -I "echo open ""$file_path"" $winid && echo ref ""$file_path"" `acme-dot -l $winid`"
;;
restart)
tmux respawnp -k -t "$session:1"
;;
impls)
tmux pipep -t $session:1 -I "echo open ""$file_path"" $winid && echo imp ""$file_path"" `acme-dot -l $winid`"
;;
*)
echo "$cmd not supported"
;;
esac