Repository navigation
fix(5320): keep VB methods after a multi-line string literal - #5345
Deepjyoti-Sarmah wants to merge 5 commits into
Conversation
A ' on a continuation line of a multi-line string (plain or $"...") opens a comment that swallows a ')' and the rest of the file is lost. Four tests fail on v8; the comment guard passes.
tree-sitter-vb-dotnet 0.3.0 only accepts single-line strings. The helper turns a literal that crosses line breaks into "" plus one ' _' line continuation per break, so later lines keep their numbers. Not wired in yet.
When the first parse has errors and the file has a string that crosses a line break, parse again with those strings flattened, so methods after them keep their nodes and calls.
Error recovery on a multi-line string is slow as well as lossy: an 8,000-line file took 14.5 s to parse on v8 against 121 ms clean, and the reparse-on-error approach still paid that. Flatten up front instead, but only when a C-speed check finds a line that opens a string it does not close, so clean files skip the Python scan (16 ms against 99 ms).
Cached VB.NET extractions from before the fix are missing every method after a multi-line string, so they re-run.
|
Thanks for the pull request, @Deepjyoti-Sarmah. 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.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify code review 
Review completed · f869a02f388a
Warning
Merge confidence: 3/5 · Review before merging · 🟠 High impact
1 P2 bug checked against the code
VB.NET extraction now rewrites multiline string literals before parsing and increments the AST cache schema so cached VB.NET results are refreshed.
Bugs (1)
P2 · Preserve interpolation expressions when flattening multiline strings in _flatten_multiline_strings: replacing the whole literal removes calls such as FormatValue() before invocation traversal can record them. Inspect source
Detailed review · checked against the code
Calls inside multiline interpolated strings disappear from the graph
When a multiline interpolated string contains a call inside {...}, extraction drops that call along with the string contents.
Expected: The method's extracted call edges include the call to FormatValue().
Actually: Preprocessing replaces the full multiline literal, including its interpolation expression, with an empty string and continuations; the later invocation traversal cannot record the removed call.
For a multiline interpolated literal, _flatten_multiline_strings tracks braces so the closing quote is found after the interpolation expression, then replaces the entire literal with "" and line continuations. That removes any call such as FormatValue() inside {...} before parsing. The method-body visitor records calls by traversing parsed invocation nodes, so it cannot extract the erased call. This is a bounded call-graph accuracy bug for VB.NET calls inside multiline interpolated strings.
-
Independent source review: The added multiline-interpolation test checks that later methods and calls outside the literal survive, but does not check a call inside an interpolation expression. The extraction visitor confirms calls must remain in the parsed body as invocation nodes; no preservation path for the erased expression was found.
-
This depends on the VB.NET grammar representing calls inside single-line interpolation expressions as invocation nodes; the changed tests cover multiline survival but not calls inside interpolation expressions.
-
Also reported as: Calls inside multiline interpolated strings disappear
Code graph and static checks · 3717 functions depend on this change
Impact & health
Impact — 3717 functions depend on the 134 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1287 callers, 78 callees - worse:
extract_vbnet()— 2 callers, 8 callees
Formal checks — 3717 functions this change can affect weren't formally checked in this review. Formal checks are informational only.
Gate & verification
✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 2168 function(s) in the blast radius were not formally verified this run
Test selection
58 of 593 test file(s) selected (10%) via static blast radius.
ℹ️ 1 changed file rests on a single covering test (
graphify/extractors/vbnet.py). The selection is only as good as that one test — raiseminCoveringTeststo run the full suite instead when coverage is this thin.
tests/test_binary_media_words.py— impacttests/test_cache.py— impacttests/test_cache_long_paths.py— impacttests/test_cache_stale_import_target.py— impacttests/test_cache_windows_case_4925.py— impacttests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_code_only_scope_4923.py— impacttests/test_cpp_template_members.py— impacttests/test_csharp_partial_classes.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_extract_cli.py— impacttests/test_grammar_cache_key.py— impacttests/test_hook_content_freshness.py— impacttests/test_ignore_file_encoding.py— impacttests/test_incremental_mtime_collision.py— impacttests/test_java_member_calls.py— impacttests/test_java_nested_type_identity.py— impacttests/test_js_member_collisions.py— impacttests/test_language_override_lifecycle.py— impacttests/test_language_overrides.py— impacttests/test_linked_worktree_reconcile.py— impacttests/test_llm_ambiguous_fragments.py— impacttests/test_llm_backends.py— impacttests/test_manifest_ingest.py— impacttests/test_msbuild_dir_evidence.py— impacttests/test_objc_field_table_remap.py— impacttests/test_out_dir_evidence.py— impacttests/test_partial_cache.py— impacttests/test_pipeline.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_injected_factory_calls.py— impacttests/test_python_property_reads.py— impacttests/test_python_pytest_fixture_receivers.py— impacttests/test_rust_self_member_calls.py— impacttests/test_rust_use_trees.py— impacttests/test_semantic_cache_basename_recovery.py— impacttests/test_semantic_cache_out_root.py— impacttests/test_skill_persisted_scan_options.py— impacttests/test_skill_semantic_all_cached.py— impacttests/test_skillgen.py— impacttests/test_slice_checkpoint_completeness.py— impacttests/test_stale_prune.py— impacttests/test_stat_index_husk.py— impacttests/test_stat_index_multi_root.py— impacttests/test_stat_index_portability.py— impacttests/test_terraform_modules.py— impact- … and 8 more
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.
Every flagged function
extract()ingraphify/extract.py:11742· 1287 callers, 78 callees: fans out to 78 callees (efferent coupling); 1287 callers depend on it (afferent coupling)extract_vbnet()ingraphify/extractors/vbnet.py:151· 2 callers, 8 callees: fans out to 8 callees (efferent coupling)
What does this PR do?
Part of #5320 (point 2b). A VB.NET file with a multi-line string literal no longer loses every method after that string. In the reporter's file,
Despues()comes back along with its calls. The grammar bug behind it is filed upstream as CodeAnt-AI/tree-sitter-vb-dotnet#9. This PR works around it in graphify.tree-sitter-vb-dotnet 0.3.0 defines a string as
" ( [^"\r\n] | "" )* ", so a string can't cross a line break. VB 14 allows it, and this is what happens:The unclosed
(is what drops the methods, not the'or the string on their own:'on a continuation line that doesn't eat a)'foo(1with no string and no comment)In VB that compiles, an unclosed
(only appears this way, so the fix targets the string itself. Before parsing, each literal that spans lines is flattened. Line numbers are kept, and so is the code after the closing quote:The scan follows VB's lexical rules:
'andREMcomments (a"inside a comment opens nothing),""escapes, and$"..."with{...}holes. An unterminated string is left for the parser.Five commits
The tests go in first and fail.
d87af597reparses only when the first parse has errors.a6a5d0f2replaces that with flattening before the first parse, so reverting it falls back to the slower but still correct reparse.Type of change
Verification & Invariants
Invariant: a statement the grammar can't read stays inside that statement. A VB string that spans lines must not cost the methods and calls after it, or move their line numbers.
Merge Danger
Door: two-way. The rewrite only changes the bytes handed to the parser. Reverting restores v8 output, and the cache schema goes 48 → 49 so cached VB extractions re-run.
Blast Radius: small.
.vbfiles with a line that opens a string it doesn't close are rewritten. Every other file is parsed byte-for-byte as on v8.Limitations
“ ”), which VB also accepts as string delimiters, aren't recognised.$"{f("x")}") is tracked only by brace depth. A"inside the hole isn't read as its own string.How was this tested?
The reporter's file, before and after:
Five new cases in
tests/test_vbnet_extractor.py, run end to end throughextract():VB tests at each commit:
db23cf01testsd478306dhelperd87af597reparse on errora6a5d0f2flatten firstf869a02fschemaI measured four designs against the same tests and an 8,000-line file (2,000 methods), with and without one multi-line string near the top:
Sub/Functionnames from ERROR texttree-sitter's error recovery on this input is slow as well as lossy: one multi-line string made the parse 120× slower. Flattening before the first parse fixes both.
Regex check against the scan, on 315 local
.vbfiles: 0 misses and 0 false alarms (it fired on all 10 files with multi-line strings and none of the other 305). Most of these are short generated test files, not real projects.Full suite: 76 failed, 11520 passed. v8
340268a7in the same environment: 76 failed, 11515 passed, with the identical set of failing tests. They're subprocess tests that run the shared venv's editable install of the main checkout. The +5 are the new tests.Not tested: Windows, and a real-world VB codebase beyond the reporter's sample.