Skip to content

Fix XmlForClause and JsonForClause FirstTokenIndex in subqueries #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented May 20, 2025

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 Copilot AI changed the title [WIP] XmlForClause object has wrong FirstTokenIndex value in some cases Fix XmlForClause and JsonForClause FirstTokenIndex in subqueries May 20, 2025
@Copilot Copilot AI requested a review from llali May 20, 2025 21:11
Copilot finished work on behalf of llali May 20, 2025 21:11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove dotnet-install.sh from this PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the dotnet-install.sh file from the PR as requested in commit 27d9176.

Copilot finished work on behalf of llali May 21, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XmlForClause object has wrong FirstTokenIndex value in some cases
2 participants