Skip to content

Support constant identifiers in policy name parsing #251305

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 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 12, 2025

The policy generation script (build/lib/policies.ts) previously only supported string literals and localization function calls for policy names, causing failures when developers tried to use constants:

// This would fail policy generation
const CHAT_MCP_POLICY_NAME = 'ChatMCP';

policy: {
    name: CHAT_MCP_POLICY_NAME,  // ParseError: Missing required 'name' property
    minimumVersion: '1.99'
}

Changes Made

Enhanced the StringQ tree-sitter query to support identifier references:

  • Added (identifier) @identifier pattern to match constant references
  • Implemented resolveIdentifierToString() function to resolve identifiers to their string constant values
  • Updated the QType interface and related functions to pass rootNode for identifier resolution
  • Maintained full backward compatibility with existing string literals and localization calls

Example Usage

Developers can now define policy names as constants and reference them consistently:

// Policy constants
const CHAT_MCP_POLICY_NAME = 'ChatMCP';

// Use in policy configuration
policy: {
    name: CHAT_MCP_POLICY_NAME,  // ✅ Now works correctly
    minimumVersion: '1.99'
}

This improvement allows policy names to be defined once and reused across multiple locations, reducing the risk of typos and improving maintainability when policy names need to be referenced in multiple places within the codebase.

Fixes #251304.


💡 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 AI and others added 2 commits June 12, 2025 18:49
Co-authored-by: joshspicer <23246594+joshspicer@users.noreply.github.com>
Co-authored-by: joshspicer <23246594+joshspicer@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] policy.name as a constant variable causes policy file generation to fail Support constant identifiers in policy name parsing Jun 12, 2025
@Copilot Copilot AI requested a review from joshspicer June 12, 2025 18:59
Copilot finished work on behalf of joshspicer June 12, 2025 18:59
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

Error loading sessions

Retrying...

Successfully merging this pull request may close these issues.

policy.name as a constant variable causes policy file generation to fail
2 participants