vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Support for "using Module" statement.

Open crazygao opened this issue 4 years ago • 2 comments

Prerequisites

  • [X] I have written a descriptive issue title.
  • [X] I have searched all issues to ensure it has not already been reported.

Summary

when using class from another file. example: using Module .\FileToManageInfo.psm1 [FileToManageInfo]::new()

The class FileToManageInfo cannot navigate.

example FileToManageInfo.psm1: class FileToManageInfo { [string] $SourceName [string] $FileContent [string] $TargetName

FileToManageInfo([string] $SourceName, [string] $TargetName, [bool] $Lazy = $false) {
    $this.SourceName = $SourceName
    if (!$Lazy) {
        $this.LoadFile()
    }
    $this.TargetName = $TargetName
}
LoadFile() {
    if ([IO.File]::Exists($this.SourceName)) {
        $this.FileContent = Get-Content -Path $this.SourceName -Raw
    } else {
        Trace-OneBoxError "Failed to get file $this.SourceName" @{ "CommandLine" = $MyInvocation.Line.TrimStart('.', '\').Trim() }
    }
}
WriteOutput() {
    Write-Output "SourceName = $this.SourceName"
    Write-Output "TargetName = $this.TargetName"
    Write-Output $this.FileContent
    Write-Output "============================="
}
Materialize() {
    #Finalize files.
    Test-CreateDirectory -Folder ([IO.Path]::GetDirectoryName($this.TargetName))
    Save-TextToFileUtf8NoBOM $this.TargetName $this.FileContent
}

}

Or is there any replacement for this?

Proposed Design

Support this language feature.

crazygao avatar Sep 02 '22 06:09 crazygao

Are you talking about IntelliSense or using the class in general? The class itself should work find if you actually run the using module statement but the tab completion depends on PowerShell itself and unfortunately PowerShell doesn't handle tab completion for PowerShell classes unless they are included in the document you are getting completions for.
I have a pending PR that fixes this issue (and a lot more) here: https://github.com/PowerShell/PowerShell/pull/16875 you will need to wait for that to get merged to fix this issue.
In the mean time you can do what I do, and compile your own version of PowerShell with the changes I've made in that PR and then point this extension to your custom PowerShell build.

MartinGC94 avatar Sep 05 '22 17:09 MartinGC94

This issue has been marked as answered and has not had any activity in a day. It has been automatically closed for housekeeping purposes.

ghost avatar Sep 09 '22 18:09 ghost