fix(elixir): Phoenix channel extraction is unreachable in both branches - #1730
fix(elixir): Phoenix channel extraction is unreachable in both branches#1730henry-hz wants to merge 1 commit into
Conversation
Neither half of extract_channels_elixir could ever fire, so an Elixir project produced zero Channel nodes regardless of how much Phoenix.PubSub or Phoenix.Channel it used. The emit side read ts_node_child_by_field_name(call, "arguments"). tree-sitter-elixir defines no such field — its whole field set is key, left, operand, operator, quoted_start, quoted_end, right, target and value — so args was always null and elixir_emit_second_arg() returned early every time. extract_defs.c has always used a positional second-child fallback for this; the same fallback is now used here. The listener side dispatched on strcmp(kind, "def"). There is no `def` node type in the grammar: an Elixir definition is a `call` whose target is the macro name. elixir_process_function_def() was therefore dead code, and it also read `name` and `parameters` fields that do not exist. It now takes the def call, unwraps a `when` guard, and reads the head's name and parameters positionally, so guarded clauses like `def handle_in(e, p, s) when is_map(s)` are recognized too. Verified against a Phoenix application; the new test covers Phoenix.PubSub.broadcast/subscribe, a bare push/broadcast emit, and two handle_in clauses, one of them guarded. Signed-off-by: Henry Hazan <henry@teramine.io>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
|
Confirmed dead, and the evidence is even cleaner than your report. You wrote that tree-sitter-elixir never produces a That is a good find, and it is the kind that hides indefinitely because the dead branch looks like working code in review. The test is binding on all five assertions. The emit side fails on Scope is clean: everything is inside One thing I want you to confirm rather than assume. This is not purely "make the dead branch live" — you restructured the dispatch so a I worked through it and I believe it is safe: the loop still pushes every child onto the stack, so broadcasts inside a Your CI here is not a real failure. The run shows One heads-up spanning your three PRs. The production files are genuinely disjoint, so nothing here can break #1721 or #1731. But all three insert into Also note this adds a third near-identical positional-args helper ( |
Refs #1729 (defect 2 of 4).
The bug
Neither half of
extract_channels_elixir()can fire, so an Elixir project produces zeroChannelnodes regardless of how muchPhoenix.PubSuborPhoenix.Channelit uses.docs/elixir-lsp/PLAN.md§1.2 currently records this path as "Phoenix channels/PubSub (works today)", which is what prompted me to write it up rather than just patch it.Emit side
elixir_process_call()reads:tree-sitter-elixirdefines noargumentsfield — its whole field set iskey, left, operand, operator, quoted_start, quoted_end, right, target, value.argsis always null, soelixir_emit_second_arg()returns early every time.Listener side
There is no
defnode type in the grammar — an Elixir definition is acallwhose target is the macro name. That branch is unreachable, andelixir_process_function_def()compounds it by readingnameandparametersfields that also do not exist.The fix
elixir_call_args()whichextract_defs.chas always used for the same reasoncall+ a def-macro target instead of the phantomdefnode typeelixir_process_function_def()now takes the def call, unwraps awhenguard, and reads the head's name and parameters positionally — so guarded clauses likedef handle_in(e, p, s) when is_map(s)are caught tootargetorchild(0), matching whatextract_defs.cdoesTest
elixir_channels_pubsub_and_handle_incoversPhoenix.PubSub.broadcast,Phoenix.PubSub.subscribe, a barepushemit, and twohandle_inlistener clauses, one guarded.Verification
make -f Makefile.cbm test-focused TEST_SUITES="extraction registry lang_contract grammar_regression grammar_labels repro_language_registry repro_call_node_manifest"→ 388 passed, 0 failedclang-format --dry-run --Werrorclean onextract_channels.c.tests/left unformatted, per its exclusion fromLINT_SRCSIndependent of #1721 — these can land in either order.
Submitted as a bug fix under the CONTRIBUTING exception for focused bug fixes.
🤖 Generated with Claude Code
https://claude.ai/code/session_01DpDDX9sFC16mQ9U9wQ3WNd