Skip to content

Conversation

SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Sep 7, 2025

PR Summary

Enable user functions in a configurations following the limitations defined by ARM.

User functions, just like built-in functions, are case sensitive.
Expression grammar needed slight modification to allow for function names to contain a single period.

PR Context

Fix #1018

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables user-defined functions in DSC configurations following ARM template limitations. The implementation adds support for custom functions defined in a functions section of the configuration with namespace-based scoping and restrictions on what built-in functions can be called from within user functions.

Key changes include:

  • Added user function definitions to configuration schema with parameters and output specifications
  • Implemented user function invocation with parameter validation and type checking
  • Added restrictions preventing user functions from calling certain built-in functions like reference(), variables(), and utcNow()

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tree-sitter-dscexpression/grammar.js Updated function name regex to support dot notation for namespaced user functions
tree-sitter-dscexpression/test/corpus/valid_expressions.txt Added test case for user function syntax
tree-sitter-dscexpression/test/corpus/invalid_expressions.txt Updated test expectations for error cases
dsc_lib/src/configure/config_doc.rs Added data structures for user function definitions
dsc_lib/src/configure/context.rs Added ProcessMode enum and user_functions field to Context
dsc_lib/src/configure/mod.rs Added user function initialization logic
dsc_lib/src/functions/user_function.rs Implemented core user function invocation and validation logic
dsc_lib/src/functions/mod.rs Added user function dispatch and enhanced error messages
dsc_lib/src/functions/variables.rs Added restriction preventing use in user functions
dsc_lib/src/functions/reference.rs Added restriction preventing use in user functions
dsc_lib/src/functions/utc_now.rs Updated to use ProcessMode instead of boolean flag
dsc_lib/src/parser/mod.rs Updated to use ProcessMode enum
dsc_lib/src/dscresources/dscresource.rs Updated to use ProcessMode enum
dsc_lib/locales/en-us.toml Added localized error messages for user functions
dsc/tests/dsc_user_functions.tests.ps1 Added comprehensive test suite for user function functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@SteveL-MSFT SteveL-MSFT marked this pull request as draft September 7, 2025 04:50
@SteveL-MSFT SteveL-MSFT added Doc-Impact Schema-Impact Change requires updating a canonical schema for configs or manifests labels Sep 7, 2025
@SteveL-MSFT SteveL-MSFT marked this pull request as ready for review September 7, 2025 16:41
@SteveL-MSFT SteveL-MSFT force-pushed the user-functions branch 2 times, most recently from 51cf6c0 to 6bfe059 Compare September 11, 2025 19:48
@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue Sep 12, 2025
Merged via the queue into PowerShell:main with commit 8929bb5 Sep 12, 2025
4 checks passed
@SteveL-MSFT SteveL-MSFT deleted the user-functions branch September 12, 2025 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Doc-Impact Schema-Impact Change requires updating a canonical schema for configs or manifests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User defined functions
2 participants