Kmpl: language-agnostic type resolution with lsp_hover + source fallback

This commit is contained in:
Levi Neely 2026-05-11 16:54:23 +02:00
parent 176e1cc0f9
commit 5348f73570
1 changed files with 7 additions and 2 deletions

View File

@ -60,11 +60,16 @@ if [ -s "$tmpdir/hover_cur" ]; then
sort -u -o "$tmpdir/seen_types" "$tmpdir/seen_types"
> "$tmpdir/hover_cur"
while IFS= read -r etype; do
defn=$(grep -rn "type ${etype} struct" "$modroot/" --include='*.go' 2>/dev/null | head -1 || true)
defn=$(grep -rn "\b${etype}\b" "$modroot/" --include='*.go' --include='*.php' --include='*.c' --include='*.h' --include='*.cc' --include='*.cpp' 2>/dev/null | grep -m1 "$etype" || true)
[ -z "$defn" ] && continue
dfile=${defn%%:*}
dline=${defn#*:}; dline=${dline%%:*}
# Read struct definition from file (until closing brace)
# Get column of type name for accurate hover
dcol=$(sed -n "${dline}p" "$dfile" 2>/dev/null | grep -bo "\b${etype}\b" | head -1 | cut -d: -f1 || echo 0)
dcol=$((dcol + 1))
result=$(python3 $OLLIE/t/lsp_hover "$dfile" "$dline" "$dcol" 2>/dev/null || true)
[ -n "$result" ] && [ "$result" != "(no hover info)" ] && { printf '%s\n' "$result" | tee -a "$tmpdir/hover_embedded" >> "$tmpdir/hover_cur"; continue; }
# Fallback: read raw source block
sed -n "${dline},/^}/p" "$dfile" 2>/dev/null | tee -a "$tmpdir/hover_embedded" >> "$tmpdir/hover_cur" || true
done < "$tmpdir/todo_types"
done