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

819416af  test(5320): pin VB methods surviving a multi-line string with a quote
ff11b2c0  refactor(5320): add a line-preserving rewrite for VB multi-line strings
9b9c6e08  fix(5320): reparse VB files with multi-line strings flattened
50022836  perf(5320): flatten VB multi-line strings before the first parse
ee930e26  chore(5320): bump the AST cache schema to 50 for VB multi-line strings

The tests go in first and fail. 9b9c6e08 reparses only when the first parse has errors. 50022836 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 49 → 50 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 50 will need to renumber.

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
819416af tests 4 failed, 13 passed
ff11b2c0 helper 4 failed, 13 passed
9b9c6e08 reparse on error 17 passed
50022836 flatten first 17 passed
ee930e26 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.

@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 · ee930e26473e

Warning

Merge confidence: 3/5 · Review before merging · 🟠 High impact
1 P2 bugs, 1 unranked · 2 possible issues not confirmed
1 not re-checked

The VB.NET extractor now rewrites multi-line string literals before parsing so later methods and calls remain extractable.

Full summary

The VB.NET extractor now rewrites multi-line string literals before parsing so later methods and calls remain extractable. The cache schema is bumped so cached VB.NET results are recalculated.

Bugs (2)

P2 · Track quoted expression strings in _flatten_multiline_strings: braces inside them can end interpolation early, causing the outer string to close at the wrong quote and later VB methods or calls to be missed. Inspect source

Detailed review · checked against the code

A brace inside an interpolation string can end the string scan early

When a multiline interpolated string contains a quoted expression string with a brace, the extractor can mistake that brace for the end of the interpolation and then mistake the expression’s closing quote for the end of the outer string. Text after that point is parsed as code, which can lose later VB.NET methods and calls.

Expected: The scanner should recognize the quoted expression string and continue scanning until the outer interpolated string’s actual closing quote.
Actually: The brace changes interpolation depth even though it is inside the quoted expression string. The next quote can be mistaken for the outer string’s end, leaving the rest of the literal to be parsed as code.

For a multiline interpolated string, the scanner counts every { and } while inside an interpolation, including braces inside quoted expression strings. A } in such a string can reduce depth to zero; the following quote is then treated as the outer string’s closing quote. The scanner rewrites only through that point and passes the remainder to the VB parser as source, so string contents can be parsed as code and interfere with later declarations or calls. The extractor invokes this rewrite before parsing VB files. This behavior was introduced here: base parsed the source directly, while head adds the scanner and calls it before parsing.

  • Independent source review: Read the interpolated-string test: it covers a simple {id} expression and confirms later methods survive, but has no quoted expression string containing a brace. It does not exercise or mitigate the premature-close path.

Distinguish XML attribute quotes from VB string delimiters in _flatten_multiline_strings: multiline XML attribute text can be replaced, so the XML literal is not preserved in the parser input. Inspect source

Detailed review · checked against the code

Multiline XML attribute quotes are rewritten as string literals

A valid multiline XML literal with an attribute value spanning lines can be mistaken for a VB string, so parsing may lose that XML and declarations or calls that follow it.

The added pre-scan treats a quote on an unmatched line as the start of a VB string without distinguishing a quote in a VB XML literal. The flattening routine then replaces the quote-delimited, multiline attribute text with an empty string and continuation lines. The resulting altered bytes are passed to the VB parser, so the valid XML literal is not preserved. The extractor is registered for .vb files. This establishes the rewrite and parser-input corruption; whether later declarations or calls are lost depends on parser recovery and was not established by the inspected source.

  • Independent source review: Checked the extractor’s normal .vb dispatch and existing multiline-string tests. Those tests cover VB strings, not XML attributes, and do not mitigate the XML-literal path. The inspected source does not establish what tree-sitter recovers after the rewritten XML.

  • The effect on later declarations depends on tree-sitter-vb-dotnet's error recovery for the rewritten XML.

Not confirmed (2 possible issues)

Leads worth a look; we didn't double-check these. They don't change the score.

Not confirmed · New VB test fixtures use multi-line string literals that VB rejects, so these tests do not show that real VB files keep their methods Inspect source

Detailed review · not confirmed

The fixtures open a string with a quote at the end of a line and close it on a later line. VB does not allow this, so the tests check recovery behavior on input the VB compiler would reject.

Lines 446-448 of _JS_BODY put Dim s = " on one line and the closing quote on a later line. The same construct appears in the tests at lines 494-496 and 523-525. The earlier test at line 394 says its input was checked with .NET 8, but these fixtures have no such check, and the PR description is empty, so the intended input is not stated.

  • The PR description is empty, so it is not stated whether the extractor is meant to accept non-VB multi-line strings

  • Only the test file is in this diff; the extractor implementation is not visible

  • Found by the per-file sweep; not double-checked.

Not confirmed · The statement-continuation regression test may still pass if the original comment-opening bug returns Inspect source

Detailed review · not confirmed

The test checks that Helper() calls are found after a multi-line string, but its assertions would likely still hold even if the quote on the continuation line opened a comment.

Under the old behavior, the apostrophe in f('" & id & "'); on line 495 would blank only the rest of that line. The Helper() calls on lines 497 and 500 are on separate lines and would still be parsed, so the Medio to Helper and Despues to Helper edges would still appear. The test never checks that the line with the apostrophe is treated as string content.

  • The tokenizer behavior on the old code is not visible, so this is inferred from the code shown

  • Not verified by running the test

  • Found by the per-file sweep; not double-checked.

Code graph and static checks · 3761 functions depend on this change

Impact & health

Impact — 3761 functions depend on the 136 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1308 callers, 78 callees
  • worse: save_cached() — 62 callers, 10 callees
  • worse: extract_vbnet() — 2 callers, 8 callees

Formal checks — 3761 functions this change can affect weren't formally checked in this review. Formal checks are informational only.

Health delta baseline: last indexed commit f51d46c (diverged from this PR's base — delta is approximate).

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: 2199 function(s) in the blast radius were not formally verified this run

Test selection

58 of 601 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 · 1308 callers, 78 callees: fans out to 78 callees (efferent coupling); 1308 callers depend on it (afferent coupling)
  • save_cached() in graphify/cache.py:1230 · 62 callers, 10 callees: fans out to 10 callees (efferent coupling); 62 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)

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.
@Deepjyoti-Sarmah
Deepjyoti-Sarmah force-pushed the fix/5320-vb-error-recovery branch from f869a02 to ee930e2 Compare November 20, 2026 02:29

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