Recover bracket-quoted CREATE PROCEDURE/FUNCTION names - #2721
Recover bracket-quoted CREATE PROCEDURE/FUNCTION names#2721ayushcodes10 wants to merge 3 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.
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 handling to the SQL extractor in graphify/extractors/sql.py. It introduces a _debracket_tsql preprocessing pass that rewrites [bracket]-quoted identifiers to backtick-quoted ones before parsing (guarded to skip files that already contain backticks), plus _strip_backtick_parts and helper functions (_clean_name, _ident) to strip the synthetic backticks back out when producing display names. It also factors out a shared _SQL_NAME_PART regex fragment used by the ERROR-node fallback paths and routes existing name-reading call sites through the new identifier helpers. The accompanying test file (tests/test_multilang.py) is updated with new and modified cases covering the bracket-debracketing behavior, array-type handling, and various existing multi-language extraction scenarios across SQL, Go, TypeScript, and Rust.
No blocking issues surfaced. 4 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 275 functions depend on the 121 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract_sql()— 15 callers, 10 callees - worse:
walk()— 1 callers, 10 callees
Verification — 275 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: 132 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).
|
@safishamsi this PR's CI run is waiting on approval (first-time contributor gate) — could you approve the workflow run when you get a chance? Happy to address any review feedback in the meantime. |
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 #2712's
debracketing has rewritten it.
Fixes #2718.