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
| ... | ... | @@ -8,6 +8,8 @@ fi | |
| 8 | 8 | ||
| 9 | 9 | target="tags_deps" | |
| 10 | 10 | generated=0 | |
| 11 | + | # Start from a clean slate so repeated runs don't accumulate duplicate tags. | |
| 12 | + | rm -f "${target}" | |
| 11 | 13 | ||
| 12 | 14 | # 1. Go modules | |
| 13 | 15 | 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 | |
| 23 | 25 | fi | |
| 24 | 26 | fi | |
| 25 | 27 | ||
| 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 | |
| 28 | 30 | echo "Resolving Zig dependencies..." | |
| 29 | - | zig_dirs=() | |
| 31 | + | zig_inputs=() | |
| 30 | 32 | ||
| 31 | - | # Check local vendor / cache directories first | |
| 33 | + | # Third-party dependency sources | |
| 32 | 34 | if [[ -d "zig-pkg" ]]; then | |
| 33 | 35 | for d in zig-pkg/*; do | |
| 34 | - | [[ -d "$d" ]] && zig_dirs+=("$d") | |
| 36 | + | [[ -d "$d" ]] && zig_inputs+=("$d") | |
| 35 | 37 | done | |
| 36 | 38 | fi | |
| 37 | 39 | ||
| 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}..." | |
| 41 | 52 | # NOTE: --languages=Zig (not +Zig) so we don't also index CSS/HTML/JSON/etc. | |
| 42 | 53 | tmp_tags="$(mktemp)" | |
| 43 | - | printf "%s\n" "${zig_dirs[@]}" | ctags \ | |
| 54 | + | printf "%s\n" "${zig_inputs[@]}" | ctags \ | |
| 44 | 55 | -f "${tmp_tags}" --languages=Zig \ | |
| 45 | 56 | --exclude=test --exclude=tests \ | |
| 46 | 57 | --exclude=example --exclude=examples \ |
| ... | ... | @@ -104,9 +115,55 @@ if [[ -f "package.json" && -d "node_modules" ]]; then | |
| 104 | 115 | fi | |
| 105 | 116 | fi | |
| 106 | 117 | ||
| 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 | + | ||
| 107 | 160 | if [[ $generated -eq 1 ]]; then | |
| 108 | 161 | 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 | |
| 112 | 162 | 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=() | |
| 7 | 7 | if [[ $# -gt 0 ]]; then | |
| 8 | 8 | tag_files=("$@") | |
| 9 | 9 | else | |
| 10 | - | for f in tags .tags_deps; do | |
| 10 | + | for f in tags tags_deps; do | |
| 11 | 11 | [[ -f "$f" ]] && tag_files+=("$f") | |
| 12 | 12 | done | |
| 13 | 13 | 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 | |
| 15 | 15 | [[ -f "$f" ]] && tag_files+=("$f") | |
| 16 | 16 | done | |
| 17 | 17 | fi |
+7,
-7
| ... | ... | @@ -126,12 +126,12 @@ map global user d '<a-i>w: ctags-search<ret>' -docstring 'ctags jump to de | |
| 126 | 126 | map global user D ': ctags-generate<ret>' -docstring 'generate tags file' | |
| 127 | 127 | map global user s ': ctags-file-symbols<ret>' -docstring 'search symbols in current file' | |
| 128 | 128 | ||
| 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" %{ | |
| 130 | 130 | echo -markup "{Information}generating dependency tags in background..." | |
| 131 | 131 | nop %sh{ ( | |
| 132 | 132 | 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 | |
| 135 | 135 | ||
| 136 | 136 | if ctags-deps; then | |
| 137 | 137 | msg="dependency tags generated" |
| ... | ... | @@ -162,28 +162,28 @@ hook global BufWritePost .* %{ | |
| 162 | 162 | hook global WinSetOption filetype=zig %{ | |
| 163 | 163 | evaluate-commands %sh{ | |
| 164 | 164 | 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" | |
| 166 | 166 | } | |
| 167 | 167 | } | |
| 168 | 168 | ||
| 169 | 169 | hook global WinSetOption filetype=go %{ | |
| 170 | 170 | evaluate-commands %sh{ | |
| 171 | 171 | 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" | |
| 173 | 173 | } | |
| 174 | 174 | } | |
| 175 | 175 | ||
| 176 | 176 | hook global WinSetOption filetype=python %{ | |
| 177 | 177 | evaluate-commands %sh{ | |
| 178 | 178 | 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" | |
| 180 | 180 | } | |
| 181 | 181 | } | |
| 182 | 182 | ||
| 183 | 183 | hook global WinSetOption filetype=(javascript|typescript) %{ | |
| 184 | 184 | evaluate-commands %sh{ | |
| 185 | 185 | 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" | |
| 187 | 187 | } | |
| 188 | 188 | } | |
| 189 | 189 |
+1,
-1