Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 3, 2025

Summary

This PR prevents the @description decorator from being used on metadata declarations and removes it from language server completion suggestions for metadata. The @description decorator has no effect on the generated ARM template when used on metadata, making it misleading and incorrect.

Issues Fixed

  1. Validation Error: @description on metadata now produces BCP269 error
  2. Language Server: No longer suggests @description when typing decorators for metadata

Before

@description('description')
metadata foo = 'foo'

✅ Compiles without error (but @description has no effect on generated template)
💡 Language server suggests @description for metadata

After

@description('description')
metadata foo = 'foo'

BCP269 Error: Function "description" cannot be used as a metadata decorator
💡 Language server does not suggest @description for metadata

Implementation

Core Changes

  1. Added AnyDecoratorExceptMetadata flag in FunctionFlags.cs

    • New flag that includes all decorator types except MetadataDecorator
    • Provides precise control over decorator usage
  2. Updated @description decorator in SystemNamespaceType.cs

    • Changed from FunctionFlags.AnyDecorator to FunctionFlags.AnyDecoratorExceptMetadata
    • Prevents usage on metadata while preserving functionality elsewhere

How It Works

  • Validation: When @description is used on metadata, the validation system checks for the MetadataDecorator flag. Since @description now uses AnyDecoratorExceptMetadata, it fails validation and produces BCP269 error.
  • Language Server: The completion provider filters decorators by required flags. For metadata symbols, it only shows decorators with MetadataDecorator flag, automatically excluding @description.

Testing

  • Updated test baselines in InvalidMetadata_CRLF to expect BCP269 error
  • Added comprehensive integration tests:
    • DescriptionDecorator_OnMetadata_ShouldProduceError(): Verifies error occurs
    • DescriptionDecorator_OnValidTargets_ShouldWork(): Ensures @description still works on parameters/outputs

Verification

The fix leverages existing validation infrastructure and is minimal/surgical:

  • @description on metadata → BCP269 error
  • @description on parameters/outputs → works correctly
  • ✅ Language server no longer suggests @description for metadata
  • ✅ All existing functionality preserved

Fixes #10714.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] @description should not be suggested or allowed on metadata Fix: Prevent @description decorator on metadata declarations Jul 3, 2025
@Copilot Copilot AI requested a review from anthony-c-martin July 3, 2025 19:30
Copilot finished work on behalf of anthony-c-martin July 3, 2025 19:30
Copy link
Contributor

github-actions bot commented Jul 3, 2025

Test this change out locally with the following install scripts (Action run 16058989084)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 16058989084
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 16058989084"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 16058989084
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 16058989084"

@Copilot Copilot AI requested a review from anthony-c-martin July 3, 2025 19:38
Copilot finished work on behalf of anthony-c-martin July 3, 2025 19:38
@Copilot Copilot AI requested a review from anthony-c-martin July 3, 2025 19:47
Copilot finished work on behalf of anthony-c-martin July 3, 2025 19:47
Copilot finished work on behalf of anthony-c-martin July 3, 2025 19:56
@anthony-c-martin anthony-c-martin marked this pull request as ready for review July 3, 2025 20:23
/// <summary>
/// The function can be used as a decorator anywhere except metadata.
/// </summary>
AnyDecoratorExceptMetadata = ParameterDecorator | VariableDecorator | FunctionDecorator | ResourceDecorator | ModuleDecorator | OutputDecorator | ExtensionDecorator | TypeDecorator,
Copy link
Member

Choose a reason for hiding this comment

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

Remove the MetadataDecorator flag entirely, and clean up references to it. It was only added pre-emptively, and isn't actually used anywhere.

Copy link
Member

@anthony-c-martin anthony-c-martin left a comment

Choose a reason for hiding this comment

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

See comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@description should not be suggested or allowed on metadata
2 participants