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

Đang mở
#217 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
powershell
Lĩnh vực
tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
PowerShell
Star
151
Fork
55
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PowerShell/EditorSyntax

Tất cả issue của PowerShell/EditorSyntax

Issue tương tự

Thêm issue về DevTools

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.