Vscode-powershell: Support unloaded enums and classes in Intellisense

Created on 18 Nov 2019  路  5Comments  路  Source: PowerShell/vscode-powershell

VSCode Version: 1.40.1
OS Version: Windows 10, 1903
Powershell Extension: 2019.11.0

Steps to Reproduce:

Create an Enum
Create a function which references that Enum as a parameter.
Call that function, there will be no autosense when populating the parameters and values for said function.

Simple Example

Enum AzureSqlEdition
{
Standard
Premium
Basic
}

function functAutoSenseBroke
{
param
(
[Parameter(Mandatory=$True)][AzureSqlEdition]$DbType,
[Parameter(Mandatory=$True)][string]$OtherParameter
)
Write-Host $DbType
Write-Host $OtherParameter
}

function functAutoSenseWorks
{
param ( [Parameter(Mandatory=$True)][string]$DbType )
Write-Host $DbType
}
#works but no autosense
functAutoSenseBroke -DbType ([AzureSqlEdition]::Standard) -OtherParameter "other"

#Simple Function, no Enum, autosense works, for comparison purposes
functAutoSenseWorks -DbType "test"
Area-IntelliSense Issue-Enhancement PowerShell-Bug

Most helpful comment

Yeah completion acts differently when the source is also in the text it's trying to complete for. If you:

  1. Copy the whole script
  2. Paste it into a PSReadLine prompt without hitting enter or running any of the lines
  3. Put your cursor on the same spot and press tab

Then it'll probably act same. A very similar issue is PowerShell/PowerShell#10567. This is something that needs to be corrected in PowerShell itself (the engine provides the API that does all of vscode-powershell's completions)

All 5 comments

@cdelcambre thanks for opening this issue, and providing repro steps! I want to ensure that I understand what intellisense you are looking for/expecting, because I am having some trouble reproducing the issue
image
image
image

It would be great if you could attach a gif/screenshot or a description of what intellisense you are looking for--thanks!

Thank you for looking into this @SydneyhSmith! Your screen shots are exactly what I am hoping for but I don't get what you get on the function functAutoSenseBroke. For both I get a long list of nonsense parameter name suggestions I could definitely live without. Typing the text of the parameter I am looking for narrows down the noise. Perhaps that's a symptom of my problem because I don't see that long list of noise suggestions in your screen shots. Maybe I have a config issue? This is a clean install done today of both VS code and PowerShell extension. All default settings.

image

image

Noise!
image

Extension Details
image

VS Code Details:
Version: 1.40.1 (user setup)
Commit: 8795a9889db74563ddd43eb0a897a2384129a619
Date: 2019-11-13T16:49:35.976Z
Electron: 6.1.2
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18362

I reported a similar issue in #2117 . For arguments sake I tried your example and have the same issue, there simply is no argument or parameter completion on the function Get-Stuff.

Enum AzureSqlEdition {
    Standard
    Premium
    Basic
}

Function Get-Stuff {
    [CmdLetBinding()]
    Param (
        [Parameter(Mandatory)]
        [AzureSqlEdition]$DbType,
        [Parameter(Mandatory)]
        [string]$OtherParameter
    )

    $PSBoundParameters
}

The completion is simply not done in the editor pane when typing partially -db to get the full parameter name -DbType. Even thought the suggestion on top says it is known:

image

But in the vscode-insiders console, after several tries, the completion is done correctly:
image

In the PowerShell ISE there is no problem when typing in the console pane:
image

But the same problem is happening when typing in the PowerShell ISE editor pane, no completion whatsoever:

image

This is happening on vscode-insiders with PowerShell Preview extension 2019.11.0:

Version: 1.41.0-insider (user setup)
Commit: 29b99f85e54aa5af6cd4edf918a67d4f70a10aea
Date: 2019-11-19T10:22:48.048Z
Electron: 6.1.4
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 6.2.9200

Yeah completion acts differently when the source is also in the text it's trying to complete for. If you:

  1. Copy the whole script
  2. Paste it into a PSReadLine prompt without hitting enter or running any of the lines
  3. Put your cursor on the same spot and press tab

Then it'll probably act same. A very similar issue is PowerShell/PowerShell#10567. This is something that needs to be corrected in PowerShell itself (the engine provides the API that does all of vscode-powershell's completions)

Closing as an external fix in PowerShell
https://github.com/PowerShell/PowerShell/issues/12079

Was this page helpful?
0 / 5 - 0 ratings