Skip to content

fix(parser): resolve custom-language names via configurable name_field (#691)#702

Open
anusbutt wants to merge 1 commit into
tirth8205:mainfrom
anusbutt:fix/generic-walker-name-fields
Open

fix(parser): resolve custom-language names via configurable name_field (#691)#702
anusbutt wants to merge 1 commit into
tirth8205:mainfrom
anusbutt:fix/generic-walker-name-fields

Conversation

@anusbutt

Copy link
Copy Markdown

Linked issue

Closes #691

What & why

The generic walker's name heuristic only checked an identifier-like child or a
field literally named name, so common BibTeX/LaTeX/Markdown node shapes were
extracted unnamed and silently dropped (losing the node and all its edges).

Adds an optional name_field key to .code-review-graph/languages.toml
(string or ordered list). For custom languages only, each candidate is resolved
field-first across all candidates, then by descendant node type, then descended
to a cleaned text leaf. Two-pass ordering makes precise fields win over a
broader type match (e.g. LaTeX \newcommand resolves via declaration, not the
text node in its body). Anchoring on configured candidates avoids returning
unrelated inner identifiers (e.g. BibTeX field labels title/author).
Built-in language extraction is byte-for-byte unchanged.

How it was tested

uv run pytest tests/test_custom_languages.py -q   # 31 passed
uv run pytest tests/test_parser.py tests/test_multilang.py -q  # 516 passed, no regressions
uv run ruff check code_review_graph/              # clean
uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional  # clean
Full suite: 1972 passed / 5 skipped / 2 xpassed. One unrelated failure
(test_mcp_stdio_shutdown) is pre-existing — it fails identically on a clean
tree (a 20s MCP-server-startup timeout), not touched by this change.

Checklist

- [x] Tests added for new functionality
- [x] All tests pass (except one pre-existing, unrelated MCP-stdio-shutdown timeout)
- [x] Linting passes
- [x] Type checking passes
- [x] Lines are at most 100 characters
- [x] Docs updated (docs/CUSTOM_LANGUAGES.md)

🤖 Generated with Claude Code (https://claude.com/claude-code)

tirth8205#691)

The generic walker only found a definition's name from an identifier-like
child or a field literally named "name", so BibTeX/LaTeX/Markdown nodes whose
name lives in a differently named or nested field were extracted unnamed and
silently dropped.

Add an optional `name_field` (string or ordered list) to languages.toml.
For custom languages only, resolve each candidate field-first across all
candidates, then by descendant node type, then descend to a clean text leaf.
Built-in language extraction is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generic walker's name-field heuristic misses common LaTeX/BibTeX/Markdown node shapes

1 participant