PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
633 stars 216 forks source link

Intellisense not behaving properly before class object is instantiated #1896

Closed fflaten closed 2 years ago

fflaten commented 2 years ago

Prerequisites

Steps to reproduce

class Person {
    [string]$Name
    [int]$Age = 999

    Person([string]$name) {
        $this.Name = $name
    }

    Person([string]$name, [int]$age) {
        $this.Name = $name
        $this.Age = $age
    }

    [string]GetIntroduction([string]$greeting) {
        return "$greeting $($this.Name)"
    }

    [string]GetIntroduction([bool]$withAge) {
        return "Hello $($this.Name) ($($this.Age))"
    }
}

# 1. Run until this point. Don't execute the next lines
# ctrl+space at end $p. to open intellisense.
# Look at GetIntroduction (missing second overload) and Person (shouldn't be there)
$p = [Person]::new("Frode")
$p.

# 2. Execute next line
$p = [Person]::new("Frode")

# 3. ctrl+space at end of next line and check again. both method overloads visible + no constructor as expected
$p.

Expected behavior

Intellisense/completion shows the same step 3 at step 2

Actual behavior

Difference. Intellisense for members of `$p` include constructor and only first overload of methods. See images below

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.5
PSEdition                      Core
GitCommitId                    7.2.5
OS                             Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

2022.8.2 preview

Visuals

Constructor is shown image

Only first overload image

MartinGC94 commented 2 years ago

PowerShell provides the tooltips, not editor services. This issue was fixed in PS version 7.3 preview 5, specifically this PR: https://github.com/PowerShell/PowerShell/pull/16963 so if you can run a preview version there's a fix available, otherwise you will need to wait for the final release.

fflaten commented 2 years ago

@MartinGC94 You Sir, are one step ahead of the rest.🥇 Thanks!