Skip to content

Code thinks ArgumentCompleter attribute on parameter is the parameter's type #217

Description

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

I put [ArgumentCompleter([MyType])] on a [string] parameter. Code is trying to treat the attribute as the type. Types don't have parantheses. But otherwise, the syntax for an attribute reference is similar to how you reference a type. Though, in this case, an attribute type reference would be [ArgumentCompleterAttribute]. I tried it with both a class passed to the attribute and a script block. Same results both times.

On a related note, when I try to run my script outside Code in Windows Terminal, PS 7.3.4 ignores the same [ArgumentCompleter()] attribute references. It acts as those attributes aren't there at all.

PowerShell Version

PS C:\Users\willp> $PSVersionTableName Value---- -----PSVersion 7.3.4PSEdition CoreGitCommitId 7.3.4OS Microsoft Windows 10.0.22621Platform Win32NTPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}PSRemotingProtocolVersion 2.3SerializationVersion 1.1.0.1WSManStackVersion 3.0

Visual Studio Code Version

Version: 1.78.2 (system setup)Commit: b3e4e68a0bc097f0ae7907b217c1119af9e03435Date: 2023-05-10T14:39:26.248ZElectron: 22.5.2Chromium: 108.0.5359.215Node.js: 16.17.1V8: 10.8.168.25-electron.0OS: Windows_NT x64 10.0.22621Sandboxed: No

Extension Version

Name: PowerShellId: ms-vscode.powershellDescription: Develop PowerShell modules, commands and scripts in Visual Studio Code!Version: 2023.5.0Publisher: MicrosoftVS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell

Steps to Reproduce

I wrote the argument completer class shown below.

classTimeZoneCompleter : Management.Automation.IArgumentCompleter
{
[Collections.Generic.IEnumerable[Management.Automation.CompletionResult]] CompleteArgument([string] $strCmdName, [string] $strParamName, [string] $strWordToComplete, [Management.Automation.Language.CommandAst] $cmdAst, [Collections.IDictionary]$mapFakeBoundParameters)
{
[Management.Automation.CompletionResult[]]$result= [Management.Automation.CompletionResult[]]@();
([TimeZoneInfo]::GetSystemTimeZones() +$global:mapCommonTimeZones.Values) |Where-Object { $_.Id-like"$strWordToComplete*"-or$_.DisplayName-like"$strWordToComplete*"-or$_.DaylightName-like"$strWordToComplete*"-or$_.StandardName-like"$strWordToComplete*" } |ForEach-Object { $result+= [Management.Automation.CompletionResult]::New("'$($_.Id)'",$_.Id, [Management.Automation.CompletionResultType]::ParameterValue,$_.DisplayName) };
return$result;
}
}

I then applied that attribute to my method's parameter. (Simplified version of the method shown below.)

functionx
{
param
(
[ArgumentCompleter([TimeZoneCompleter])
[TimeZoneInfo]
$timezone
)
}

Visuals

This screenshot shows how such code is rendered. Notice how the ArgumentCompleter attribute is in blue. It should be in a brown.
image

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions