Skip to content

fix(extract): end Dart method and function ranges at the body - #3189

Draft
x-labb wants to merge 1 commit into
DeusData:mainfrom
x-labb:fix-3010-dart-method-line-range
Draft

x-labb wants to merge 1 commit into
DeusData:mainfrom
x-labb:fix-3010-dart-method-line-range

Conversation

@x-labb

@x-labb x-labb commented Dec 4, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #3010.

The Dart grammar makes function_body a sibling of function_signature (or of the method_signature wrapping it), so a function's or method's line range ended with its signature, and get_code_snippet returned the declaration without the body.

The range now ends on the following function_body when there is one (comments in between are skipped). A bodiless signature keeps its own range, and other languages are unaffected: the new helper returns the definition node for anything but Dart.

Only end_line and lines change. Complexity metrics and fingerprints are still computed from the same node as before. I did not bump CBM_INDEX_FORMAT_VERSION.

How it was checked

Windows 11, MSYS2 CLANG64 (clang 23.1.6), ASan + UBSan.

  • New test dart_def_range_covers_body in tests/test_extraction.c: block body, multi-line signature, arrow body, static method, unnamed extension member, comment between signature and body, bodiless external function.
    • scripts/test.sh CC=clang CXX=clang++ --suites extraction without the fix: 590 passed, 1 failed (def->end_line == 6, expected 8).
    • With the fix: 591 passed.
  • The lib/repro.dart from the issue, indexed with a binary built from this branch: BlockBody.ping is 9-13, BlockBody.wide 15-22, and get_code_snippet on ping returns the whole body.
  • make -f Makefile.cbm test CC=clang CXX=clang++ (run before rebasing onto feat(pipeline): resolve Dart import URIs in the path rule #3176): 10653 passed, 3 failed, 114 skipped. The failures are test_git_facts_gitfile_redirection_cannot_certify_false_ancestry, test_git_ancestor_changes_history_and_external_driver_guards_apply and mem_map_attributes_a_known_allocation; the same three fail with extract_defs.c reverted. The incremental suite did not run because its fixture clone failed. After the rebase I re-ran the extraction suite (591 passed).
  • make -k -f Makefile.cbm lint-ci (clang-format 20.1.8, cppcheck 2.22.0): clang-format, NOLINT, memory-core and vendored-scanner checks pass. cppcheck reports findings in other files and none in extract_defs.c.

Checklist

  • Every commit is signed off (git commit -s) — required, CI rejects
    unsigned commits (DCO, see CONTRIBUTING.md)
  • Tests pass locally (make -f Makefile.cbm test)
  • Lint passes (make -f Makefile.cbm lint-ci)
  • New behavior is covered by a test (reproduce-first for bugs)

Written with AI assistance.

The Dart grammar makes `function_body` a sibling of `function_signature`
(or of the `method_signature` wrapping it), so a definition's range ended
with the signature. get_code_snippet then returned the declaration alone
for any member whose body starts or continues on a later line.

End the range on the following `function_body` when there is one. A
bodiless signature keeps its own range.

Fixes DeusData#3010

Signed-off-by: x-labb <154824493+x-labb@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

Dart: method node line range covers only the signature, so get_code_snippet returns no body

1 participant