diff --git a/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1 b/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1 index 0bc740e6a..f5d53be4c 100644 --- a/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1 +++ b/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1 @@ -4,10 +4,10 @@ # if (!$PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq "Desktop") { - Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.VSCode.dll" + Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.VSCode.dll" } else { - Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.VSCode.dll" + Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.VSCode.dll" } if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject]) { @@ -17,6 +17,6 @@ else { Write-Verbose '$psEditor object not found in the session, components will not be registered.' } -Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse | ForEach-Object { +Microsoft.PowerShell.Management\Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse | ForEach-Object { . $PSItem.FullName } diff --git a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psm1 b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psm1 index ae745b604..d79c5f520 100644 --- a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psm1 +++ b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psm1 @@ -3,10 +3,10 @@ # Licensed under the MIT license. See LICENSE file in the project root for full license information. # -Import-LocalizedData -BindingVariable Strings -FileName Strings -ErrorAction Ignore +Microsoft.PowerShell.Utility\Import-LocalizedData -BindingVariable Strings -FileName Strings -ErrorAction Ignore -Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 | ForEach-Object { +Microsoft.PowerShell.Management\Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 | ForEach-Object { . $PSItem.FullName } -Export-ModuleMember -Function *-* \ No newline at end of file +Microsoft.PowerShell.Core\Export-ModuleMember -Function *-* diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 index 46b20884d..48cc4b145 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 @@ -4,13 +4,13 @@ # if (!$PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq "Desktop") { - Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.dll" - Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.Host.dll" + Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.dll" + Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.Host.dll" } else { - Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.dll" - Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Protocol.dll" - Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Host.dll" + Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.dll" + Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Protocol.dll" + Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Host.dll" } function Start-EditorServicesHost { @@ -75,10 +75,14 @@ function Start-EditorServicesHost { ) $editorServicesHost = $null - $hostDetails = New-Object Microsoft.PowerShell.EditorServices.Session.HostDetails @($HostName, $HostProfileId, (New-Object System.Version @($HostVersion))) + $hostDetails = + Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Session.HostDetails @( + $HostName, + $HostProfileId, + (Microsoft.PowerShell.Utility\New-Object System.Version @($HostVersion))) $editorServicesHost = - New-Object Microsoft.PowerShell.EditorServices.Host.EditorServicesHost @( + Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Host.EditorServicesHost @( $hostDetails, $BundledModulesPath, $EnableConsoleRepl.IsPresent, @@ -87,15 +91,19 @@ function Start-EditorServicesHost { $FeatureFlags) # Build the profile paths using the root paths of the current $profile variable - $profilePaths = New-Object Microsoft.PowerShell.EditorServices.Session.ProfilePaths @( - $hostDetails.ProfileId, - [System.IO.Path]::GetDirectoryName($profile.AllUsersAllHosts), - [System.IO.Path]::GetDirectoryName($profile.CurrentUserAllHosts)); + $profilePaths = + Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Session.ProfilePaths @( + $hostDetails.ProfileId, + [System.IO.Path]::GetDirectoryName($profile.AllUsersAllHosts), + [System.IO.Path]::GetDirectoryName($profile.CurrentUserAllHosts)) $editorServicesHost.StartLogging($LogPath, $LogLevel); - $languageServiceConfig = New-Object Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportConfig - $debugServiceConfig = New-Object Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportConfig + $languageServiceConfig = + Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportConfig + + $debugServiceConfig = + Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportConfig if ($Stdio.IsPresent) { $languageServiceConfig.TransportType = [Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportType]::Stdio @@ -143,15 +151,16 @@ function Compress-LogDir { begin { function LegacyZipFolder($Path, $ZipPath) { - if (!(Test-Path($ZipPath))) { - Set-Content -LiteralPath $ZipPath -Value ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) - (Get-Item $ZipPath).IsReadOnly = $false + if (!(Microsoft.PowerShell.Management\Test-Path($ZipPath))) { + $zipMagicHeader = "PK" + [char]5 + [char]6 + ("$([char]0)" * 18) + Microsoft.PowerShell.Management\Set-Content -LiteralPath $ZipPath -Value $zipMagicHeader + (Microsoft.PowerShell.Management\Get-Item $ZipPath).IsReadOnly = $false } - $shellApplication = New-Object -ComObject Shell.Application + $shellApplication = Microsoft.PowerShell.Utility\New-Object -ComObject Shell.Application $zipPackage = $shellApplication.NameSpace($ZipPath) - foreach ($file in (Get-ChildItem -LiteralPath $Path)) { + foreach ($file in (Microsoft.PowerShell.Management\Get-ChildItem -LiteralPath $Path)) { $zipPackage.CopyHere($file.FullName) Start-Sleep -MilliSeconds 500 } @@ -159,7 +168,7 @@ function Compress-LogDir { } end { - $zipPath = ((Convert-Path $Path) -replace '(\\|/)$','') + ".zip" + $zipPath = ((Microsoft.PowerShell.Management\Convert-Path $Path) -replace '(\\|/)$','') + ".zip" if (Get-Command Microsoft.PowerShell.Archive\Compress-Archive) { if ($PSCmdlet.ShouldProcess($zipPath, "Create ZIP")) { @@ -196,7 +205,7 @@ function Get-PowerShellEditorServicesVersion { $versionInfo += "macOS $(lsb_release -d -s)$nl" } else { - $osInfo = Get-CimInstance Win32_OperatingSystem + $osInfo = CimCmdlets\Get-CimInstance Win32_OperatingSystem $versionInfo += "Windows $($osInfo.OSArchitecture) $($osInfo.Version)$nl" } diff --git a/module/PowerShellEditorServices/Start-EditorServices.ps1 b/module/PowerShellEditorServices/Start-EditorServices.ps1 index 4a7b505d7..3c1e3eec1 100644 --- a/module/PowerShellEditorServices/Start-EditorServices.ps1 +++ b/module/PowerShellEditorServices/Start-EditorServices.ps1 @@ -102,17 +102,17 @@ function ExitWithError($errorString) { } function WriteSessionFile($sessionInfo) { - $sessionInfoJson = ConvertTo-Json -InputObject $sessionInfo -Compress + $sessionInfoJson = Microsoft.PowerShell.Utility\ConvertTo-Json -InputObject $sessionInfo -Compress Log "Writing session file with contents:" Log $sessionInfoJson - $sessionInfoJson | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop + $sessionInfoJson | Microsoft.PowerShell.Management\Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop } # Are we running in PowerShell 2 or earlier? if ($PSVersionTable.PSVersion.Major -le 2) { # No ConvertTo-Json on PSv2 and below, so write out the JSON manually "{`"status`": `"failed`", `"reason`": `"unsupported`", `"powerShellVersion`": `"$($PSVersionTable.PSVersion.ToString())`"}" | - Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop + Microsoft.PowerShell.Management\Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop ExitWithError "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled." } @@ -133,9 +133,9 @@ $isPS5orLater = $PSVersionTable.PSVersion.Major -ge 5 # If PSReadline is present in the session, remove it so that runspace # management is easier -if ((Get-Module PSReadline).Count -gt 0) { +if ((Microsoft.PowerShell.Core\Get-Module PSReadline).Count -gt 0) { LogSection "Removing PSReadLine module" - Remove-Module PSReadline -ErrorAction SilentlyContinue + Microsoft.PowerShell.Core\Remove-Module PSReadline -ErrorAction SilentlyContinue } # This variable will be assigned later to contain information about @@ -146,7 +146,7 @@ $resultDetails = $null; function Test-ModuleAvailable($ModuleName, $ModuleVersion) { Log "Testing module availability $ModuleName $ModuleVersion" - $modules = Get-Module -ListAvailable $moduleName + $modules = Microsoft.PowerShell.Core\Get-Module -ListAvailable $moduleName if ($modules -ne $null) { if ($ModuleVersion -ne $null) { foreach ($module in $modules) { @@ -182,7 +182,7 @@ function Test-PortAvailability { $ipAddress = [System.Net.IPAddress]::Loopback Log "Testing availability of port ${PortNumber} at address ${ipAddress} / $($ipAddress.AddressFamily)" - $tcpListener = New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber) + $tcpListener = Microsoft.PowerShell.Utility\New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber) $tcpListener.Start() $tcpListener.Stop() } @@ -202,7 +202,7 @@ function Test-PortAvailability { } $portsInUse = @{} -$rand = New-Object System.Random +$rand = Microsoft.PowerShell.Utility\New-Object System.Random function Get-AvailablePort() { $triesRemaining = 10; @@ -247,7 +247,7 @@ try { LogSection "Start up PowerShellEditorServices" Log "Importing PowerShellEditorServices" - Import-Module PowerShellEditorServices -ErrorAction Stop + Microsoft.PowerShell.Core\Import-Module PowerShellEditorServices -ErrorAction Stop # Locate available port numbers for services # There could be only one service on Stdio channel diff --git a/src/PowerShellEditorServices/Session/RemoteFileManager.cs b/src/PowerShellEditorServices/Session/RemoteFileManager.cs index 04bee2df7..e2d47dd88 100644 --- a/src/PowerShellEditorServices/Session/RemoteFileManager.cs +++ b/src/PowerShellEditorServices/Session/RemoteFileManager.cs @@ -75,7 +75,7 @@ function Open-EditorFile { foreach ($fileName in $Paths) { - dir $fileName | where { ! $_.PSIsContainer } | foreach { + Microsoft.PowerShell.Management\Get-ChildItem $fileName | Where-Object { ! $_.PSIsContainer } | Foreach-Object { $filePathName = $_.FullName # Get file contents @@ -89,10 +89,10 @@ function Open-EditorFile { $params['Encoding']='Byte' } - $contentBytes = Get-Content @params + $contentBytes = Microsoft.PowerShell.Management\Get-Content @params # Notify client for file open. - New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($filePathName, $contentBytes, $preview) > $null + Microsoft.PowerShell.Utility\New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($filePathName, $contentBytes, $preview) > $null } } } @@ -148,7 +148,7 @@ function New-EditorFile { if ($Path) { foreach ($fileName in $Path) { - if (-not (Test-Path $fileName) -or $Force) { + if (-not (Microsoft.PowerShell.Management\Test-Path $fileName) -or $Force) { $valueList > $fileName # Get file contents @@ -162,7 +162,7 @@ function New-EditorFile { $params['Encoding']='Byte' } - $contentBytes = Get-Content @params + $contentBytes = Microsoft.PowerShell.Management\Get-Content @params if ($Path.Count -gt 1) { $preview = $false @@ -171,10 +171,10 @@ function New-EditorFile { } # Notify client for file open. - New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($fileName, $contentBytes, $preview) > $null + Microsoft.PowerShell.Utility\New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($fileName, $contentBytes, $preview) > $null } else { $PSCmdlet.WriteError( ( - New-Object -TypeName System.Management.Automation.ErrorRecord -ArgumentList @( + Microsoft.PowerShell.Utility\New-Object -TypeName System.Management.Automation.ErrorRecord -ArgumentList @( [System.Exception]'File already exists.' $Null [System.Management.Automation.ErrorCategory]::ResourceExists @@ -182,14 +182,14 @@ function New-EditorFile { } } } else { - $bytes = [System.Text.Encoding]::UTF8.GetBytes(($valueList | Out-String)) - New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($null, $bytes) > $null + $bytes = [System.Text.Encoding]::UTF8.GetBytes(($valueList | Microsoft.PowerShell.Utility\Out-String)) + Microsoft.PowerShell.Utility\New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($null, $bytes) > $null } } } - Set-Alias psedit Open-EditorFile -Scope Global - Export-ModuleMember -Function Open-EditorFile, New-EditorFile + Microsoft.PowerShell.Utility\Set-Alias psedit Open-EditorFile -Scope Global + Microsoft.PowerShell.Core\Export-ModuleMember -Function Open-EditorFile, New-EditorFile "; // This script is templated so that the '-Forward' parameter can be added @@ -199,14 +199,15 @@ function New-EditorFile { [string] $PSEditModule ) - Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile -Forward -SupportEvent - New-Module -ScriptBlock ([Scriptblock]::Create($PSEditModule)) -Name PSEdit | Import-Module -Global + Microsoft.PowerShell.Utility\Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile -Forward -SupportEvent + Microsoft.PowerShell.Core\New-Module -ScriptBlock ([Scriptblock]::Create($PSEditModule)) -Name PSEdit | + Microsoft.PowerShell.Core\Import-Module -Global "; private const string RemovePSEditFunctionScript = @" - Get-Module PSEdit | Remove-Module + Microsoft.PowerShell.Core\Get-Module PSEdit | Microsoft.PowerShell.Core\Remove-Module - Unregister-Event -SourceIdentifier PSESRemoteSessionOpenFile -Force -ErrorAction Ignore + Microsoft.PowerShell.Utility\Unregister-Event -SourceIdentifier PSESRemoteSessionOpenFile -Force -ErrorAction Ignore "; private const string SetRemoteContentsScript = @" @@ -226,7 +227,7 @@ function New-EditorFile { $params['Encoding']='Byte' } - Set-Content @params 2>&1 + Microsoft.PowerShell.Management\Set-Content @params 2>&1 "; #endregion