Skip to content

Commit 377dc7f

Browse files
safishamsiclaude
andcommitted
fix(extract): warn when code files have no AST extractor instead of silently dropping them (#1689)
Extensions like .r/.R (also .ejs, .ets) are in CODE_EXTENSIONS, so those files are classified as code and counted in the scan, but there is no entry for them in the extractor dispatch — so they produce zero nodes and are silently absent from the graph while the CLI still reports success. The #1666 zero-node warning deliberately skips them (it only fires when an extractor exists), so nothing surfaced the gap. extract() now emits a warning listing the offending extensions and counts ("N file(s) are classified as code but graphify has no AST extractor ...: .r (2)") so a primarily-R (or .ejs/.ets) corpus no longer looks fully mapped when it is not. Grouped by extension, fires only for files actually present with no extractor (today: .ejs, .ets, .r). Adding real grammars for these remains the follow-up; this removes the silent-data-loss now. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent d1d1f41 commit 377dc7f

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎graphify/extract.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16403,6 +16403,29 @@ def extract(
1640316403
file=sys.stderr, flush=True,
1640416404
)
1640516405

16406+
# #1689: a file counted as code (extension in CODE_EXTENSIONS) but with no AST
16407+
# extractor wired up (e.g. .r/.R — there is no tree-sitter-r dispatch) silently
16408+
# contributes zero nodes. The #1666 warning above deliberately skips these (it
16409+
# only fires when an extractor exists), so surface them explicitly, grouped by
16410+
# extension, rather than reporting success as if the language were mapped.
16411+
from graphify.detect import CODE_EXTENSIONS as _CODE_EXTS
16412+
_no_extractor: dict[str, int] = {}
16413+
for _p in paths:
16414+
_ext = _p.suffix.lower()
16415+
if _ext in _CODE_EXTS and _get_extractor(_p) is None:
16416+
_no_extractor[_ext] = _no_extractor.get(_ext, 0) + 1
16417+
if _no_extractor:
16418+
_by_count = ", ".join(
16419+
f"{ext} ({n})" for ext, n in sorted(_no_extractor.items(), key=lambda kv: (-kv[1], kv[0]))
16420+
)
16421+
_tot = sum(_no_extractor.values())
16422+
print(
16423+
f" warning: {_tot} file(s) are classified as code but graphify has no AST "
16424+
f"extractor for their language, so they contributed nothing to the graph: "
16425+
f"{_by_count}. Please open an issue to request support for these (#1689).",
16426+
file=sys.stderr, flush=True,
16427+
)
16428+
1640616429
all_nodes: list[dict] = []
1640716430
all_edges: list[dict] = []
1640816431
all_raw_calls: list[dict] = []

‎tests/test_extract.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,3 +1769,29 @@ def test_case_insensitive_suffix_filtering(tmp_path):
17691769
assert "myJSFunction()" in labels
17701770
assert "MyTSClass" in labels
17711771

1772+
1773+
1774+
def test_extract_warns_on_code_files_with_no_ast_extractor(tmp_path, capsys):
1775+
# #1689: .r/.R is in CODE_EXTENSIONS (counted as code) but has no AST extractor,
1776+
# so R files silently contribute nothing. extract() must surface that instead of
1777+
# reporting success as if the language were mapped.
1778+
r1 = tmp_path / "analysis.R"; r1.write_text("f <- function(x) x + 1\n")
1779+
r2 = tmp_path / "helper.r"; r2.write_text("g <- function(y) y * 2\n")
1780+
py = tmp_path / "main.py"; py.write_text("def main():\n return 1\n")
1781+
1782+
result = extract([r1, r2, py], cache_root=tmp_path)
1783+
err = capsys.readouterr().err
1784+
1785+
assert "no AST extractor" in err
1786+
assert ".r (2)" in err # both R files grouped under the lowercased ext
1787+
assert "#1689" in err
1788+
# the Python file still extracts normally
1789+
labels = [n.get("label") for n in result["nodes"]]
1790+
assert any(str(l).startswith("main") for l in labels)
1791+
1792+
1793+
def test_extract_no_warning_when_all_code_has_extractors(tmp_path, capsys):
1794+
py = tmp_path / "a.py"; py.write_text("def a():\n return 1\n")
1795+
extract([py], cache_root=tmp_path)
1796+
err = capsys.readouterr().err
1797+
assert "no AST extractor" not in err

0 commit comments

Comments
 (0)