Commit d1a84a9

Eric Bower  ·  2026-10-12 22:23:13 -0400 EDT
parent 3ad8b1a
fix: ctags-deps should also gen stdlib
4 files changed,  +79, -22
+69, -12
......@@ -8,6 +8,8 @@ fi
88
99 target="tags_deps"
1010 generated=0
11+# Start from a clean slate so repeated runs don't accumulate duplicate tags.
12+rm -f "${target}"
1113
1214 # 1. Go modules
1315 if [[ -f "go.mod" ]] && command -v go >/dev/null 2>&1; then
......@@ -23,24 +25,33 @@ if [[ -f "go.mod" ]] && command -v go >/dev/null 2>&1; then
2325 fi
2426 fi
2527
26-# 2. Zig dependencies (build.zig.zon / zig-pkg)
27-if [[ -f "build.zig.zon" ]] || [[ -d "zig-pkg" ]]; then
28+# 2. Zig dependencies (build.zig.zon / zig-pkg) + build-generated sources
29+if [[ -f "build.zig.zon" ]] || [[ -d "zig-pkg" ]] || [[ -f ".generated-sources" ]]; then
2830 echo "Resolving Zig dependencies..."
29- zig_dirs=()
31+ zig_inputs=()
3032
31- # Check local vendor / cache directories first
33+ # Third-party dependency sources
3234 if [[ -d "zig-pkg" ]]; then
3335 for d in zig-pkg/*; do
34- [[ -d "$d" ]] && zig_dirs+=("$d")
36+ [[ -d "$d" ]] && zig_inputs+=("$d")
3537 done
3638 fi
3739
38- if [[ ${#zig_dirs[@]} -gt 0 ]]; then
39- readarray -t zig_dirs < <(printf "%s\n" "${zig_dirs[@]}" | sort -u)
40- echo "Indexing ${#zig_dirs[@]} Zig dependencies into ${target}..."
40+ # Project build-generated sources (e.g. wayland-scanner output) listed by
41+ # build.zig in .generated-sources, one absolute path per line. These live in
42+ # .zig-cache and are not reachable from zig-pkg, so we index them directly.
43+ if [[ -f ".generated-sources" ]]; then
44+ while IFS= read -r gf; do
45+ [[ -n "$gf" && -f "$gf" ]] && zig_inputs+=("$gf")
46+ done < .generated-sources
47+ fi
48+
49+ if [[ ${#zig_inputs[@]} -gt 0 ]]; then
50+ readarray -t zig_inputs < <(printf "%s\n" "${zig_inputs[@]}" | sort -u)
51+ echo "Indexing ${#zig_inputs[@]} Zig sources into ${target}..."
4152 # NOTE: --languages=Zig (not +Zig) so we don't also index CSS/HTML/JSON/etc.
4253 tmp_tags="$(mktemp)"
43- printf "%s\n" "${zig_dirs[@]}" | ctags \
54+ printf "%s\n" "${zig_inputs[@]}" | ctags \
4455 -f "${tmp_tags}" --languages=Zig \
4556 --exclude=test --exclude=tests \
4657 --exclude=example --exclude=examples \
......@@ -104,9 +115,55 @@ if [[ -f "package.json" && -d "node_modules" ]]; then
104115 fi
105116 fi
106117
118+# 5. Standard library tags for detected languages.
119+# Cached in $XDG_CACHE_HOME/tags and shared across projects, so we only
120+# generate them when missing (regenerating a whole stdlib is slow). To force a
121+# refresh, delete the cached file or run the individual ctags-*-std script.
122+cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/tags"
123+script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
124+std_generated=0
125+
126+ensure_std() {
127+ local lang="$1" script="$2"
128+ local std_target="${cache_dir}/${lang}_std.tags"
129+ if [[ -f "${std_target}" ]]; then
130+ echo "std tags for ${lang} cached ($(du -h "${std_target}" | cut -f1))"
131+ std_generated=1
132+ return 0
133+ fi
134+ if [[ -x "${script_dir}/${script}" ]]; then
135+ echo "Generating ${lang} std tags..."
136+ if "${script_dir}/${script}"; then
137+ std_generated=1
138+ else
139+ echo "warning: failed to generate ${lang} std tags" >&2
140+ fi
141+ else
142+ echo "warning: ${script} not found, skipping ${lang} std tags" >&2
143+ fi
144+}
145+
146+if [[ -f "go.mod" ]]; then
147+ ensure_std "go" "ctags-go-std"
148+fi
149+if [[ -f "build.zig" ]]; then
150+ ensure_std "zig" "ctags-zig-std"
151+fi
152+if [[ -n "${VIRTUAL_ENV:-}" && -d "${VIRTUAL_ENV}" ]] || [[ -d ".venv" ]] || [[ -d "venv" ]] \
153+ || [[ -f "pyproject.toml" || -f "setup.py" || -f "requirements.txt" ]]; then
154+ ensure_std "python" "ctags-python-std"
155+fi
156+if [[ -f "package.json" ]]; then
157+ ensure_std "ts" "ctags-ts-std"
158+fi
159+
107160 if [[ $generated -eq 1 ]]; then
108161 echo "Saved dependency tags to ${target} ($(du -h "${target}" | cut -f1))"
109-else
110- echo "No third-party dependencies detected in current directory."
111- exit 1
112162 fi
163+
164+if [[ $generated -eq 1 || $std_generated -eq 1 ]]; then
165+ exit 0
166+fi
167+
168+echo "No third-party dependencies or std libs detected in current directory."
169+exit 1
+2, -2
......@@ -7,11 +7,11 @@ tag_files=()
77 if [[ $# -gt 0 ]]; then
88 tag_files=("$@")
99 else
10- for f in tags .tags_deps; do
10+ for f in tags tags_deps; do
1111 [[ -f "$f" ]] && tag_files+=("$f")
1212 done
1313 if [[ ${#tag_files[@]} -eq 0 && -n "$git_root" ]]; then
14- for f in "$git_root/tags" "$git_root/.tags_deps"; do
14+ for f in "$git_root/tags" "$git_root/tags_deps"; do
1515 [[ -f "$f" ]] && tag_files+=("$f")
1616 done
1717 fi
+7, -7
......@@ -126,12 +126,12 @@ map global user d '<a-i>w: ctags-search<ret>' -docstring 'ctags jump to de
126126 map global user D ': ctags-generate<ret>' -docstring 'generate tags file'
127127 map global user s ': ctags-file-symbols<ret>' -docstring 'search symbols in current file'
128128
129-define-command ctags-deps -docstring "Generate .tags_deps for third-party dependencies" %{
129+define-command ctags-deps -docstring "Generate tags_deps for third-party dependencies" %{
130130 echo -markup "{Information}generating dependency tags in background..."
131131 nop %sh{ (
132132 trap - INT QUIT
133- while ! mkdir .tags_deps.kaklock 2>/dev/null; do sleep 1; done
134- trap 'rmdir .tags_deps.kaklock' EXIT
133+ while ! mkdir tags_deps.kaklock 2>/dev/null; do sleep 1; done
134+ trap 'rmdir tags_deps.kaklock' EXIT
135135
136136 if ctags-deps; then
137137 msg="dependency tags generated"
......@@ -162,28 +162,28 @@ hook global BufWritePost .* %{
162162 hook global WinSetOption filetype=zig %{
163163 evaluate-commands %sh{
164164 cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
165- printf 'set-option window ctagsfiles "tags" ".tags_deps" "%s/tags/zig_std.tags"\n' "$cache_dir"
165+ printf 'set-option window ctagsfiles "tags" "tags_deps" "%s/tags/zig_std.tags"\n' "$cache_dir"
166166 }
167167 }
168168
169169 hook global WinSetOption filetype=go %{
170170 evaluate-commands %sh{
171171 cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
172- printf 'set-option window ctagsfiles "tags" ".tags_deps" "%s/tags/go_std.tags"\n' "$cache_dir"
172+ printf 'set-option window ctagsfiles "tags" "tags_deps" "%s/tags/go_std.tags"\n' "$cache_dir"
173173 }
174174 }
175175
176176 hook global WinSetOption filetype=python %{
177177 evaluate-commands %sh{
178178 cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
179- printf 'set-option window ctagsfiles "tags" ".tags_deps" "%s/tags/python_std.tags"\n' "$cache_dir"
179+ printf 'set-option window ctagsfiles "tags" "tags_deps" "%s/tags/python_std.tags"\n' "$cache_dir"
180180 }
181181 }
182182
183183 hook global WinSetOption filetype=(javascript|typescript) %{
184184 evaluate-commands %sh{
185185 cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
186- printf 'set-option window ctagsfiles "tags" ".tags_deps" "%s/tags/ts_std.tags"\n' "$cache_dir"
186+ printf 'set-option window ctagsfiles "tags" "tags_deps" "%s/tags/ts_std.tags"\n' "$cache_dir"
187187 }
188188 }
189189
+1, -1
......@@ -1,5 +1,5 @@
11 {
2- "lastChangelogVersion": "1.0.4",
2+ "lastChangelogVersion": "1.2.0",
33 "packages": [
44 "npm:@deevus/pi-zmx",
55 "file:~/.pi/agent/extensions/qwen-remote.ts"