Recover a CREATE VIEW/TABLE swallowed by a preceding broken routine - #2724
Recover a CREATE VIEW/TABLE swallowed by a preceding broken routine#2724ayushcodes10 wants to merge 4 commits into
Conversation
tree-sitter-sql has no grammar token for T-SQL [bracket] quoting: each bracket lands as its own ERROR node, one byte short of the real pair, so [dbo].[Alpha] reads back as the label `dbo].[Alpha` instead of dbo.Alpha. Rewrite bracket-quoted identifiers to backtick-quoted ones before parsing (a form the grammar already handles cleanly), then strip the synthetic backticks back out for display. Guards against misfiring on Postgres/MySQL array-type syntax (text[], numeric(10)[3]). Fixes Graphify-Labs#2712.
A bracket-quoted FOREIGN KEY ... REFERENCES clause could confuse the parser badly enough that the whole child table (with its FK constraint) landed as bogus nested content inside the parent table's own subtree, dropping the child table from the graph and fabricating a self-referencing EXTRACTED edge on the parent. Already fixed as a side effect of the Graphify-Labs#2712 debracketing change on this branch; this adds coverage for the specific Graphify-Labs#2713 repro. Fixes Graphify-Labs#2713.
This grammar has no rule at all for T-SQL's AS BEGIN...END routine body, bracketed name or not, so every CREATE PROCEDURE/FUNCTION only ever gets extracted through the ERROR-node regex fallback. That fallback matched a bare or double-quoted name but not a bracket-quoted one, so a bracketed routine name produced no node at all rather than a mangled one (0 of 845 procedures on a real SSMS-scripted dump). Extends the fallback's name pattern to also match a backtick-quoted name, which recovers a bracketed T-SQL name once Graphify-Labs#2712's debracketing has rewritten it. Fixes Graphify-Labs#2718.
This grammar has no rule for T-SQL's AS BEGIN...END routine body, so a CREATE FUNCTION/PROCEDURE with such a body lands in an ERROR node — and that ERROR span can absorb the NEXT statement too (e.g. a CREATE VIEW right after it), with no recovery path for anything but a routine. Extend the ERROR-node regex recovery to also catch a swallowed CREATE VIEW/TABLE name, registering it in table_nids so a later reference in the same file resolves onto it. Reproduces with bare identifiers, independent of the T-SQL bracket-quoting defects. Fixes Graphify-Labs#2719.
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Formal verification. No changes could be formally verified in this run.
Graphify review — findings
This PR adds T-SQL bracket-quoted identifier support to the SQL extractor and broadens name-part handling across its regex fallback paths. Specifically, it introduces a _debracket_tsql pre-parse pass that rewrites [bracket]-quoted identifiers to backtick-quoted ones (with guards for strings/comments and array-type syntax), plus helpers (_strip_backtick_parts, _clean_name, _ident) to strip that synthetic quoting from display labels. It also factors identifier-part matching into a shared _SQL_NAME_PART regex used by the ERROR-node fallbacks for CREATE FUNCTION/PROCEDURE and swallowed CREATE VIEW/TABLE statements. The change touches the SQL extractor module and a large set of multilang extractor tests (Go, Rust, TypeScript, SQL) that appear to have been updated or added alongside it.
No blocking issues surfaced. 3 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 279 functions depend on the 125 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract_sql()— 17 callers, 10 callees - worse:
walk()— 1 callers, 10 callees
Verification — 279 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 136 function(s) in the blast radius were not formally verified this run
Formal verification
Could not verify: Could not verify extract\_sql.
The verifier did not have enough to check extract\_sql, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set
· 1 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).
This grammar has no rule for T-SQL's AS BEGIN...END routine body, so a
CREATE FUNCTION/PROCEDURE with such a body lands in an ERROR node —
and that ERROR span can absorb the NEXT statement too (e.g. a CREATE
VIEW right after it), with no recovery path for anything but a
routine. Extend the ERROR-node regex recovery to also catch a
swallowed CREATE VIEW/TABLE name, registering it in table_nids so a
later reference in the same file resolves onto it. Reproduces with
bare identifiers, independent of the T-SQL bracket-quoting defects.
Fixes #2719.