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

未關閉
#217 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
powershell
領域
tooling

研究方向

Reproduce the syntax highlighting with the reported ArgumentCompleter attribute on a parameter, using the PowerShell example in the issue. Start by locating the syntax rule that classifies attribute references and parameter types; done means ArgumentCompleter is distinguished from the parameter type without regressing ordinary type highlighting.

由索引模型根據 Issue 內容生成。

描述

Issue-Bug Needs: Triage :mag:
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

主要語言
PowerShell
星號
151
分支
55
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

PowerShell/EditorSyntax 的其他 Issue

查看 PowerShell/EditorSyntax 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。