Skip to content

fix(markdown): recognise backslash namespaces and Type::member code-span mentions (#4610) - #4695

Closed
viwe-monai wants to merge 1 commit into
Graphify-Labs:v8from
viwe-monai:fix/markdown-ns-member-mentions-4610
Closed

viwe-monai wants to merge 1 commit into
Graphify-Labs:v8from
viwe-monai:fix/markdown-ns-member-mentions-4610

Conversation

@viwe-monai

Copy link
Copy Markdown
Contributor

Fixes #4610

What

_code_span_mention accepted only the dotted and path-qualified forms, so the separators other languages' docs write were dropped before the resolver saw them — App\\Services\\Mailer (PHP namespaces) and Mailer::send() (PHP, Rust, C++ type-qualified members). Both are now qualifier separators the way . already is:

  • App\\Services\\Mailer → ["App", "Services", "Mailer"], Mailer::send() → ["Mailer", "send"] (a trailing () is dropped from the last name, like the dotted form),
  • Foo::CONST and Foo::class are left out — neither has a node to land on,
  • a span that is only a namespace root (App\\) is dropped as the non-mention it is.

On the resolution side, a PSR-4 namespace root maps to the scan directory and has no path segment, so when no candidate accounts for the whole chain the resolver drops the leading qualifiers a candidate cannot account for and falls back to the unique bare-name match. The fallback fires only when strict matching found nothing, so a qualifier that does match keeps discriminating: Mailer::send() still picks the right send over a same-named method on another class. Dotted mentions are untouched — they keep the strict evidence check (time.sleep, pyproject.toml still resolve to nothing).

Verification

The issue's exact repro (PHP corpus) now prints the expected:

[('Mail', 'Mailer'), ('Mail', '.send()')]     # was [] before

tests/test_markdown_code_spans.py extended with classification cases (App\\Services\\Mailer, Mailer::send(), Foo::CONST, Foo::class, App\\, C:\\Users\\me) and an end-to-end case mirroring the repro (namespace-root drop + Mailer::send() disambiguation against a second send). Full file: 16 passed; with tests/test_symbol_resolution.py: 58 passed.

The issue offered to open a PR with a regression test — happy to hand this over or adjust the shape if you'd rather drive it from your 12-README corpus numbers.

…pan mentions (Graphify-Labs#4610)

_code_span_mention accepted only the dotted and path-qualified forms, so the
separators other languages' docs write were dropped before the resolver saw
them: App\Services\Mailer (PHP namespaces) and Mailer::send() (PHP, Rust, C++
type-qualified members).

Both are now qualifier separators the way '.' already is, with Foo::CONST and
Foo::class left out (no node to land on) and a bare namespace root (App\)
dropped as the non-mention it is. A PSR-4 namespace root maps to the scan
directory and has no path segment, so when no candidate accounts for the whole
chain the resolver drops the leading qualifiers a candidate cannot account for,
falling back to the unique bare-name match; a qualifier that does match keeps
discriminating, so Mailer::send() still picks the right send().
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @viwe-monai. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; formal verification proved 0 of 3 changed function(s) (3 sampled, not proven).

Formal verification. PR-changed functions: 3/3 verified (0 proven, 3 may-equivalent, 0 distinguished) · 0 not verified.


Graphify review — findings

Adds recognition of PHP-style App\Services\Mailer and type-qualified Mailer::send() code spans as symbol mentions, splitting them on \ and :: like the dotted form. Spans ending in ::class or an all-caps constant, and bare namespace roots like App\, are dropped as non-symbols. That all-caps cutoff is a blunt heuristic that also catches legitimately all-caps symbol names. Tags these chains with ns_qualified so resolve_markdown_mentions falls back to dropping leading qualifiers no candidate can account for, since a PSR-4 root maps to the scan directory and has no path segment. The fallback runs only when the strict match finds nothing, so a matching qualifier like Mailer in Mailer::send() still picks the right send, but stripping unmatched qualifiers can leave too little to discriminate on.

Worth a look

  • Namespace fallback can drop every qualifier, so an unrelated owner still resolves — graphify/markdown_resolution.py:225 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 525 functions depend on the 75 functions this change touches.

Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • _rebuild_code() — 187 callers, 60 callees (high)
  • dispatch_command() — 5 callers, 134 callees (high)
  • main() — 110 callers, 3 callees (high)
  • extract_markdown() — 16 callers, 10 callees (high)
  • _run_cli() — 11 callers, 8 callees (high)
  • watch() — 6 callers, 10 callees (high)
  • resolve_markdown_mentions() — 3 callers, 7 callees (medium)
  • _resolve_markdown_link() — 3 callers, 6 callees (medium)
  • …and 2 more

Verification — 525 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 270 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

3 of 443 test file(s) selected (1%) via static blast radius.

  • tests/test_languages.py — impact
  • tests/test_markdown_code_spans.py — impact, changed-test
  • tests/test_watch.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

No difference found (not proven): No behavior difference found in \_code\_span\_mention (not a proof).

The verifier ran both versions of \_code\_span\_mention on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in extract\_markdown (not a proof).

The verifier ran both versions of extract\_markdown on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in resolve\_markdown\_mentions (not a proof).

The verifier ran both versions of resolve\_markdown\_mentions on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

safishamsi added a commit that referenced this pull request Nov 5, 2026
@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.103 (published to PyPI), cherry-picked with your authorship preserved. Follow-up: added the AST cache-schema bump (38->39) the PR was missing, since it changes per-file markdown extractor output. Fixes #4610. Thanks @viwe-monai.

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.

[Bug]: markdown mentions: Ns\Class and Class::method() are not recognised as symbol mentions (PHP, Rust, C++ docs)

2 participants