Repository navigation
fix(5320): keep VB methods after a multi-line string literal - #5345
Deepjyoti-Sarmah wants to merge 5 commits into
Conversation
|
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 · 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
.vbdispatch 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 — 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· 1308 callers, 78 callees: fans out to 78 callees (efferent coupling); 1308 callers depend on it (afferent coupling)save_cached()ingraphify/cache.py:1230· 62 callers, 10 callees: fans out to 10 callees (efferent coupling); 62 callers depend on it (afferent coupling)extract_vbnet()ingraphify/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.
f869a02 to
ee930e2
Compare
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.
9b9c6e08reparses only when the first parse has errors.50022836replaces 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 49 → 50 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:
819416aftestsff11b2c0helper9b9c6e08reparse on error50022836flatten firstee930e26schemaI 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.