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

Abierto
#217 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
powershell
Área
tooling

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
PowerShell
Estrellas
151
Forks
55
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de PowerShell/EditorSyntax

Todos los issues de PowerShell/EditorSyntax

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.