Skip to content

refactor(infer): consolidate args.rs text-scan helpers onto CST path #147

Description

@Hessesian

Status (re-audited 2026-06-17)

The original premise is partly outdated. A CST fast path (cst_call_arg_type) was already added to find_as_call_arg_type in #24 (2026-04-29, a month before this issue was filed), so the text-scan helpers are already fallbacks that only run when no live tree is available — not the primary path.

There are now four independent enclosing-call detectors that don't share a base:

  • cst_call_info (cst_cursor.rs) — authoritative; used by signature help & traits_impl
  • cst_call_arg_type (args.rs:391) — a separate inline CST walk; used only by find_as_call_arg_type
  • find_enclosing_call_name (scope.rs:695) — text scan; 3 callers (args, receiver, scope)
  • find_call_context (args.rs:122) — text scan; 1 caller (find_positional_call_arg_type)

So the real duplication is broader than originally described, and it now includes a third CST variant — not just the two text helpers.

Rescoped goal — one CST-first detector + one text fallback

  • Fold cst_call_arg_type into cst_call_info (or have args.rs call cst_call_info directly) so there is a single CST call/arg detector.
  • Delete find_call_context; fold its depth-aware comma counting into find_enclosing_call_name as the single text fallback.
  • Converge find_named_call_arg_type / find_positional_call_arg_type onto that CST-first-with-text-fallback path.

Priority: low

The text helpers are fallback-only (no-live-tree case, rare for the file being edited) and are not directly unit-tested — only the entry point find_as_call_arg_type is (with a dedicated CST-fast-path test section). Pure cleanup: modest benefit, non-trivial regression risk.


Original problem (retained for context)

src/indexer/infer/args.rs has two independent text-scan implementations for detecting the enclosing call and argument position:

  • find_named_call_arg_type() (lines 69–107): calls find_enclosing_call_name() from scope.rs
  • find_positional_call_arg_type() (lines 109–119): uses its own find_call_context() helper (lines 122–196) with separate depth-aware comma counting

Both duplicate logic that cst_call_info() in src/indexer/infer/cst_cursor.rs already handles correctly with a CST-first + text fallback strategy.

Goal

  • Converge both functions to use cst_call_info when a live tree is available
  • Remove or merge find_call_context with find_enclosing_call_name in scope.rs
  • Single source of truth for enclosing-call detection

Discovered by

Audit of codebase after Issue #142 (CompletionContext centralisation).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions