SqlScriptDOM icon indicating copy to clipboard operation
SqlScriptDOM copied to clipboard

Fix XmlForClause and JsonForClause FirstTokenIndex in subqueries

Open Copilot opened this issue 8 months ago • 0 comments

Issue

When using XML or JSON FOR clauses in subqueries, the FirstTokenIndex of XmlForClause and JsonForClause objects incorrectly pointed to the first option token (typically PATH) instead of the FOR keyword token.

As shown in the screenshot, the FirstTokenIndex value of the XmlForClause in a subquery points to index 55 (the PATH keyword) while it should point to the FOR keyword like it does in regular queries.

Changes

Modified the xmlForClause and jsonForClause grammar rules to properly track the FOR token index:

  1. Added code to capture the index of the FOR token using GetLastTokenIndex() at the beginning of the clause parsing
  2. Explicitly set the FirstTokenIndex to the FOR token index using UpdateTokenInfo() before any other token operations
  3. Applied this fix consistently across all SQL grammar versions (TSql80.g through TSql170.g)

Testing

Added a test file with examples of both regular queries and subqueries using FOR XML and FOR JSON clauses.

This ensures that FirstTokenIndex consistently points to the FOR keyword in all contexts, making token indexing more reliable for tooling that depends on these indices.

Fixes #119.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • crl3.digicert.com
    • Triggering command: dotnet build (dns block)
  • crl4.digicert.com
    • Triggering command: dotnet build (dns block)
  • dc.services.visualstudio.com
    • Triggering command: dotnet build (dns block)
  • dot.net
    • Triggering command: wget REDACTED (dns block)
  • ocsp.digicert.com
    • Triggering command: dotnet build (dns block)
  • s.symcb.com
    • Triggering command: dotnet build (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • s.symcd.com
    • Triggering command: dotnet build (dns block)
  • ts-crl.ws.symantec.com
    • Triggering command: dotnet build (dns block)
  • ts-ocsp.ws.symantec.com
    • Triggering command: dotnet build (dns block)
  • www.antlr2.org
    • Triggering command: /home/REDACTED/.dotnet/dotnet /home/REDACTED/.dotnet/sdk/8.0.406/MSBuild.dll /nologo /nodemode:1 /nodeReuse:true /low:false (dns block)
  • www.antlr3.org
    • Triggering command: wget REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar May 20 '25 20:05 Copilot