Skip to content

fix(5320): keep VB methods after a multi-line string literal - #5345

Open
Deepjyoti-Sarmah wants to merge 5 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5320-vb-error-recovery
Open

Deepjyoti-Sarmah wants to merge 5 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5320-vb-error-recovery

Conversation

@Deepjyoti-Sarmah

@Deepjyoti-Sarmah Deepjyoti-Sarmah commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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:

Dim s = "                                  no closing " on this line: not a string, read as code
var el = document.getElementById('abc');  ' starts a comment and swallows the )
return el;"                                the ( stays open: lines 6-14 become one ERROR node

The unclosed ( is what drops the methods, not the ' or the string on their own:

case methods kept
' on a continuation line that doesn't eat a ) 3/3
multi-line string with no ' 3/3
foo(1 with no string and no comment 2/3
a comment that eats a ) 2/3

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:

 extract_vbnet(path)
   source = read(path)
+  if a line opens a " it never closes, with no ' before it     (C regex)
+    source = flatten_multiline_strings(source)                 (VB-aware scan)
   root = parse(source)
Dim s = "            ->   Dim s = "" _
  f('a');                 _
  return el;" & id        & id

The scan follows VB's lexical rules: ' and REM comments (a " inside a comment opens nothing), "" escapes, and $"..." with {...} holes. An unterminated string is left for the parser.

Five commits

db23cf01  test(5320): pin VB methods surviving a multi-line string with a quote
d478306d  refactor(5320): add a line-preserving rewrite for VB multi-line strings
d87af597  fix(5320): reparse VB files with multi-line strings flattened
a6a5d0f2  perf(5320): flatten VB multi-line strings before the first parse
f869a02f  chore(5320): bump the AST cache schema to 49 for VB multi-line strings

The tests go in first and fail. d87af597 reparses only when the first parse has errors. a6a5d0f2 replaces that with flattening before the first parse, so reverting it falls back to the slower but still correct reparse.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

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.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

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.

  • Only .vb files with a line that opens a string it doesn't close are rewritten. Every other file is parsed byte-for-byte as on v8.
  • The VB extractor never reads string contents, so blanking them loses nothing. Node ids and line numbers don't change.
  • Any other open PR that bumps the schema to 49 will need to renumber, including fix(vbnet): count ByVal Optional parameters as optional (#5320) #5327.

Limitations

  • Curly quotes (“ ”), which VB also accepts as string delimiters, aren't recognised.
  • A string inside an interpolation hole ($"{f("x")}") is tracked only by brace depth. A " inside the hole isn't read as its own string.
  • Columns after a flattened string shift on its last line. Graphify records only lines.

How was this tested?

The reporter's file, before and after:

before  ['repro.vb', 'Demo', 'Antes()', 'Medio()']
after   ['repro.vb', 'Demo', 'Antes()', 'Medio()', 'Despues()']

Five new cases in tests/test_vbnet_extractor.py, run end to end through extract():

survives   reporter's file: all three methods, Medio -> Antes and Despues -> Antes
           Despues() keeps L12
           statement continuing after the closing " (& id, "" escapes)
           multi-line $"..." with ' and {id}
guard      ' say "hi  in a comment does not open a string (passes on v8 too)

VB tests at each commit:

commit result
db23cf01 tests 4 failed, 13 passed
d478306d helper 4 failed, 13 passed
d87af597 reparse on error 17 passed
a6a5d0f2 flatten first 17 passed
f869a02f schema 17 passed

I 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:

design tests with string clean evidence
v8 13 / 17 14.5 s parse 121 ms still loses the methods
S3: recover Sub/Function names from ERROR text 14 / 17 14.5 s — names come back but bodies aren't parsed: 0 call edges
S1: reparse flattened when the first parse has errors 17 / 17 ~14.7 s +0 pays the slow error-recovery parse first
S2: always scan and flatten 17 / 17 fast +99 ms the Python scan runs on every file
S4: C regex check, then flatten (this PR) 17 / 17 374 ms end to end +16 ms

tree-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 .vb files: 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 340268a7 in 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.

ruff check graphify/extractors/vbnet.py tests/test_vbnet_extractor.py  -> All checks passed

Not tested: Windows, and a real-world VB codebase beyond the reporter's sample.

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.
@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 19, 2026
@Deepjyoti-Sarmah Deepjyoti-Sarmah changed the title fix(vbnet): keep methods after a multi-line string literal (#5320) fix(5320): keep VB methods after a multi-line string literal Nov 19, 2026
@Deepjyoti-Sarmah
Deepjyoti-Sarmah marked this pull request as ready for review November 19, 2026 18:13

@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 code review View in Graphify

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 — raise minCoveringTests to run the full suite instead when coverage is this thin.

  • tests/test_binary_media_words.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_long_paths.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_cache_windows_case_4925.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_code_only_scope_4923.py — impact
  • tests/test_cpp_template_members.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_grammar_cache_key.py — impact
  • tests/test_hook_content_freshness.py — impact
  • tests/test_ignore_file_encoding.py — impact
  • tests/test_incremental_mtime_collision.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_java_nested_type_identity.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_language_overrides.py — impact
  • tests/test_linked_worktree_reconcile.py — impact
  • tests/test_llm_ambiguous_fragments.py — impact
  • tests/test_llm_backends.py — impact
  • tests/test_manifest_ingest.py — impact
  • tests/test_msbuild_dir_evidence.py — impact
  • tests/test_objc_field_table_remap.py — impact
  • tests/test_out_dir_evidence.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_pipeline.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_injected_factory_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_python_pytest_fixture_receivers.py — impact
  • tests/test_rust_self_member_calls.py — impact
  • tests/test_rust_use_trees.py — impact
  • tests/test_semantic_cache_basename_recovery.py — impact
  • tests/test_semantic_cache_out_root.py — impact
  • tests/test_skill_persisted_scan_options.py — impact
  • tests/test_skill_semantic_all_cached.py — impact
  • tests/test_skillgen.py — impact
  • tests/test_slice_checkpoint_completeness.py — impact
  • tests/test_stale_prune.py — impact
  • tests/test_stat_index_husk.py — impact
  • tests/test_stat_index_multi_root.py — impact
  • tests/test_stat_index_portability.py — impact
  • tests/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() in graphify/extract.py:11742 · 1287 callers, 78 callees: fans out to 78 callees (efferent coupling); 1287 callers depend on it (afferent coupling)
  • extract_vbnet() in graphify/extractors/vbnet.py:151 · 2 callers, 8 callees: fans out to 8 callees (efferent coupling)

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

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant