Vscode-powershell: Parameter and argument completion broken

Created on 8 Mar 2020  路  8Comments  路  Source: PowerShell/vscode-powershell

Issue Type: Bug

When a function parameter uses a PS-defined enum as datatype, parameter and argument completion are broken on the editor pane where the function was defined (even though the syntax displays correctly). The issue is not present on other opened editor panes or the console.

Try this code:

enum Cities
{
  Hannover
  Redmond
  NewYork
}

function Test-It
{
  param
  (
    [Cities]
    $City
  )

  $PSBoundParameters
}

Expected result:

When entering "Test-It -" and pressing CTRL+SPACE, there should be completion for parameter -City, then completion for arguments.

Actual result:

On the same editor pane where the function is defined, regardless of whether the code was run or not, there is no completion for parameter or arguments. The parameter completion list does not even contain the parameter and lists only standard entries.

When the code was run, the completion works for console and other editor panes, but never for the editor pane that defines the function.

Suspected Trigger:

The problem occurs once a parameter is using a PS-defined enum. When changing the data type from [Cities] to any non-PS-enum type like [ConsoleColor], there is no issue and all works fine.
(using PS7.0.0 and editorservices 2020.3.0)

Extension version: 2020.3.0
VS Code version: Code 1.42.1
OS version: Windows_NT x64 10.0.18363


System Info

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz (8 x 1498)|
|GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: enabled
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled|
|Load (avg)|undefined|
|Memory (System)|31.77GB (20.84GB free)|
|Process Argv||
|Screen Reader|no|
|VM|0%|


PowerShell-Bug Resolution-External

All 8 comments

There's a bug in PowerShell itself that is causing this experience. A simple repro:

$script1 = '
  enum Cities
  {
    Hannover
    Redmond
    NewYork
  }

  function Test-It
  {
    param
    (
      [Cities]
      $City
    )

    $PSBoundParameters
  }'
TabExpansion2 -inputScript $script1 -cursorColumn $script1.Length | select -ExpandProperty CompletionMatches

no results...

but then if we define the enum ahead of time, it works:

enum Cities
  {
    Hannover
    Redmond
    NewYork
  }

$script2 = '
  function Test-It
  {
    param
    (
      [Cities]
      $City
    )

    $PSBoundParameters
  }

Test-It -'

TabExpansion2 -inputScript $script2 -cursorColumn $script2.Length | select -ExpandProperty CompletionMatches

Gives us:

CompletionText ListItemText    ResultType ToolTip
-------------- ------------    ---------- -------
-City          City         ParameterName [Cities] City

Even with the enum defined in the session, running this still gives us an empty result:

TabExpansion2 -inputScript $script1 -cursorColumn $script1.Length | select -ExpandProperty CompletionMatches

Great find. I can confirm that this apparently seems to be a long-standing bug in PowerShell as it can be repro'ed in WPS as well.
So next step: what's the best way to carry this over to the PS team? Should I open a new case?

@SteveL-MSFT can you transfer this issue into the PowerShell/PowerShell repo please.

Unfortunately, I think the same behavior will happen with PowerShell classes as well...

BTW I noticed earlier that the attribute [ArgumentCompleter({...})] has the same issue:

THIS (fails):

$script = '
  function Test-It
  {
    param
    (
      [ArgumentCompleter({"Hannover","Redmond","NewYork"})]
      $City
    )

    $PSBoundParameters
  }

Test-It -City '

TabExpansion2 -inputScript $script -cursorColumn $script.Length | select -ExpandProperty CompletionMatches

VERSUS THIS (works):

function Test-It
  {
    param
    (
      [ArgumentCompleter({"Hannover","Redmond","NewYork"})]
      $City
    )

    $PSBoundParameters
  }

$script = 'Test-It -City '

TabExpansion2 -inputScript $script -cursorColumn $script.Length | select -ExpandProperty CompletionMatches

Seems to be the same underlying issue in PowerShell.

Does the ISE work fine? Maybe we need to consider borrowing the code from the ISE... though that could be fixing one bug, and exposing many more...

No in fact with the attribute example, this first surfaced in the ISE. Don't know why the trainees moved back to ISE in the latter case, it is definitely editor-agnostic.

It must be related to how PowerShell parses the code. There is a slight difference: with the enum example, this messes up parameter completion altogether. With the completer attribute, only the completion results are messed up.

Should I open a case in the PowerShell repo?

I moved the issue over to the powershell team: https://github.com/PowerShell/PowerShell/issues/12079

For VSCode this is definitely no issue. Thanks for looking into this Tyler! Your test approach using tabexpansion2 directly was very helpful.

Thanks for doing that, Tobias!

Was this page helpful?
0 / 5 - 0 ratings