fix(elixir): Phoenix channel extraction is unreachable in both branches - #1730
Open
henry-hz wants to merge 1 commit into
Open
fix(elixir): Phoenix channel extraction is unreachable in both branches#1730henry-hz wants to merge 1 commit into
henry-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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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