Skip to content
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

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

Open
6 tasks done
WillPittenger opened this issue May 22, 2023 · 0 comments
Open
6 tasks done

Comments

@WillPittenger
Copy link

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> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

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

Extension Version

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

Steps to Reproduce

I wrote the argument completer class shown below.

class TimeZoneCompleter : 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.)

function x
{
  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

@ghost ghost added the Needs: Triage 🔍 label May 22, 2023
@SydneyhSmith SydneyhSmith transferred this issue from PowerShell/vscode-powershell May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant