first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -142,9 +142,27 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
(Get-Variable | Select-Object -ExpandProperty Name) -join ' '
|
||||
$aliasesRaw = Get-Command -CommandType Alias | Select-Object -ExpandProperty DisplayName
|
||||
$aliases = $aliasesRaw -join [Environment]::NewLine
|
||||
$functionNamesRaw = Get-Command -CommandType Function | Where-Object { -not $_.Name.StartsWith('Warp') } | Select-Object -ExpandProperty Name
|
||||
# Only query modules that ship with PowerShell itself. This keeps bootstrap fast by
|
||||
# avoiding Windows system modules and third-party modules from the Gallery. The rest are
|
||||
# loaded asynchronously later.
|
||||
$corePsModules = @(
|
||||
'Microsoft.PowerShell.*', # All built-in PS modules (cross-platform)
|
||||
'Microsoft.WSMan.*', # WS-Management (Windows PS)
|
||||
'CimCmdlets', # CIM/WMI (Windows)
|
||||
'PackageManagement', # Package management
|
||||
'PowerShellGet', # Package get
|
||||
'PSReadLine', # Line editor bundled with PS
|
||||
'ThreadJob', # Thread jobs (PS 7)
|
||||
'PSDiagnostics', # PS diagnostics
|
||||
'PSDesiredStateConfiguration', # DSC (Windows PS)
|
||||
'PSWorkflow', # Legacy workflow (Windows PS 5)
|
||||
'PSWorkflowUtility' # Legacy workflow utility (Windows PS 5)
|
||||
)
|
||||
$functionNamesRaw = Get-Command -CommandType Function -Module $corePsModules |
|
||||
Where-Object { -not $_.Name.StartsWith('Warp') } |
|
||||
Select-Object -ExpandProperty Name
|
||||
$functionNames = $functionNamesRaw -join [Environment]::NewLine
|
||||
$builtinsRaw = Get-Command -CommandType Cmdlet | Select-Object -ExpandProperty Name
|
||||
$builtinsRaw = Get-Command -CommandType Cmdlet -Module $corePsModules | Select-Object -ExpandProperty Name
|
||||
$builtins = $builtinsRaw -join [Environment]::NewLine
|
||||
$shellVersion = $PSVersionTable.PSVersion.ToString()
|
||||
# PowerShell wasn't cross-platform until version 6. Anything before that is definitely on Windows.
|
||||
@@ -200,6 +218,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$bootstrappedMsg = @{
|
||||
hook = 'Bootstrapped'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
histfile = $(Get-PSReadLineOption).HistorySavePath
|
||||
shell = 'pwsh'
|
||||
home_dir = "$HOME"
|
||||
@@ -230,6 +249,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$preexecMsg = @{
|
||||
hook = 'Preexec'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
command = $command
|
||||
}
|
||||
}
|
||||
@@ -243,7 +263,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
}
|
||||
|
||||
# Clean up any completed warp jobs so they do not show up on the user's 'get-job'
|
||||
# comands
|
||||
# commands
|
||||
Warp-Clean-CompletedThread
|
||||
|
||||
# Remove any instance of the 'Warp-Run-GeneratorCommand' call from the user's history
|
||||
@@ -254,6 +274,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$updateMsg = @{
|
||||
hook = 'FinishUpdate'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
update_id = $updateId
|
||||
}
|
||||
}
|
||||
@@ -288,7 +309,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
# 2. We need to make sure that we are calling the Application git, and not
|
||||
# an alias or cmdlet named Git
|
||||
#
|
||||
# NOTE: Inlining this call in the function has a weird side effect of outputing
|
||||
# NOTE: Inlining this call in the function has a weird side effect of outputting
|
||||
# an escape sequence '^[i'. Since it made it more convenient to have a wrapper
|
||||
# function anyway, I have not investigated this, but in case someone is working
|
||||
# on this in the future, beware attempting to inline this function.
|
||||
@@ -344,6 +365,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$inputBufferMsg = @{
|
||||
hook = 'InputBuffer'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
buffer = $inputBuffer
|
||||
}
|
||||
}
|
||||
@@ -386,7 +408,7 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
Warp-Disable-PSPrediction
|
||||
}
|
||||
|
||||
# Force use of the Inline PredictionViewStyle. The ListView style can occassionally cause some
|
||||
# Force use of the Inline PredictionViewStyle. The ListView style can occasionally cause some
|
||||
# flickering when using Warp and it doesn't matter what the value of this setting is because
|
||||
# Warp has its own input editor.
|
||||
function Warp-Disable-PSPrediction {
|
||||
@@ -434,11 +456,13 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$HOST.UI.RawUI.WindowTitle = $newTitle
|
||||
|
||||
$blockId = $script:nextBlockId++
|
||||
$nextBlockId = "precmd-${global:_warpSessionId}-$blockId"
|
||||
$commandFinishedMsg = @{
|
||||
hook = 'CommandFinished'
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
exit_code = $exitCode
|
||||
next_block_id = "precmd-${global:_warpSessionId}-$blockId"
|
||||
next_block_id = $nextBlockId
|
||||
}
|
||||
}
|
||||
Warp-Send-JsonMessage $commandFinishedMsg
|
||||
@@ -457,6 +481,8 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$precmdMsg = @{
|
||||
hook = 'Precmd'
|
||||
value = @{
|
||||
exit_code = $exitCode
|
||||
next_block_id = $nextBlockId
|
||||
pwd = ''
|
||||
ps1 = ''
|
||||
git_head = ''
|
||||
@@ -493,39 +519,52 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$kubeConfig = $env:KUBECONFIG
|
||||
}
|
||||
|
||||
# Compute Node.js version if node is available and we're in a Node project within a Git repo.
|
||||
$hasNodeCommand = Get-Command -CommandType Application node 2>$null
|
||||
# Compute the Node.js version only when the Node.js Version chip is enabled
|
||||
# (WARP_PROMPT_NODE_VERSION_ENABLED is '0' when the chip is not shown; default
|
||||
# enabled when unset) and node is available. Cache the result keyed on the
|
||||
# current location + PATH so we only spawn node when the directory or PATH
|
||||
# changes (PATH changes on version-manager switches like `nvm use`).
|
||||
$nodeChipEnabled = "$env:WARP_PROMPT_NODE_VERSION_ENABLED" -ne '0'
|
||||
$hasNodeCommand = if ($nodeChipEnabled) { Get-Command -CommandType Application node 2>$null } else { $null }
|
||||
if ($hasNodeCommand) {
|
||||
try {
|
||||
# Walk up from the current directory to find a package.json
|
||||
$dir = Get-Item -LiteralPath (Get-Location).Path
|
||||
$foundPackageJson = $false
|
||||
$packageJsonDir = $null
|
||||
while ($null -ne $dir) {
|
||||
$candidate = Join-Path $dir.FullName 'package.json'
|
||||
if (Test-Path -LiteralPath $candidate) {
|
||||
$foundPackageJson = $true
|
||||
$packageJsonDir = $dir.FullName
|
||||
break
|
||||
}
|
||||
$dir = $dir.Parent
|
||||
}
|
||||
|
||||
if ($foundPackageJson) {
|
||||
# Verify package.json resides within a Git repository by walking up to find a .git directory
|
||||
$probe = Get-Item -LiteralPath $packageJsonDir
|
||||
$inGitRepo = $false
|
||||
while ($null -ne $probe) {
|
||||
if (Test-Path -LiteralPath (Join-Path $probe.FullName '.git')) {
|
||||
$inGitRepo = $true
|
||||
$nodeCacheKey = "$((Get-Location).Path)|$env:PATH"
|
||||
if ($nodeCacheKey -eq $script:warpNodeVersionCacheKey) {
|
||||
$nodeVersion = $script:warpNodeVersionCacheValue
|
||||
} else {
|
||||
# Walk up from the current directory to find a package.json
|
||||
$dir = Get-Item -LiteralPath (Get-Location).Path
|
||||
$foundPackageJson = $false
|
||||
$packageJsonDir = $null
|
||||
while ($null -ne $dir) {
|
||||
$candidate = Join-Path $dir.FullName 'package.json'
|
||||
if (Test-Path -LiteralPath $candidate) {
|
||||
$foundPackageJson = $true
|
||||
$packageJsonDir = $dir.FullName
|
||||
break
|
||||
}
|
||||
$probe = $probe.Parent
|
||||
$dir = $dir.Parent
|
||||
}
|
||||
|
||||
if ($inGitRepo) {
|
||||
$nodeVersion = Warp-TryGet-NodeVersion
|
||||
if ($foundPackageJson) {
|
||||
# Verify package.json resides within a Git repository by walking up to find a .git directory
|
||||
$probe = Get-Item -LiteralPath $packageJsonDir
|
||||
$inGitRepo = $false
|
||||
while ($null -ne $probe) {
|
||||
if (Test-Path -LiteralPath (Join-Path $probe.FullName '.git')) {
|
||||
$inGitRepo = $true
|
||||
break
|
||||
}
|
||||
$probe = $probe.Parent
|
||||
}
|
||||
|
||||
if ($inGitRepo) {
|
||||
$nodeVersion = Warp-TryGet-NodeVersion
|
||||
}
|
||||
}
|
||||
|
||||
$script:warpNodeVersionCacheKey = $nodeCacheKey
|
||||
$script:warpNodeVersionCacheValue = $nodeVersion
|
||||
}
|
||||
} catch {
|
||||
# Log at verbose level so the catch block is not empty and diagnostics are available when needed.
|
||||
@@ -558,6 +597,8 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
$precmdMsg = @{
|
||||
hook = 'Precmd'
|
||||
value = @{
|
||||
exit_code = $exitCode
|
||||
next_block_id = $nextBlockId
|
||||
pwd = (Get-Location).Path
|
||||
# TODO(PLAT-687) - honor the PS1
|
||||
ps1 = ''
|
||||
@@ -896,7 +937,9 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
function Clear-Host() {
|
||||
$inputBufferMsg = @{
|
||||
hook = 'Clear'
|
||||
value = @{}
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
}
|
||||
}
|
||||
Warp-Send-JsonMessage $inputBufferMsg
|
||||
}
|
||||
@@ -904,7 +947,9 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
|
||||
function clear() {
|
||||
$inputBufferMsg = @{
|
||||
hook = 'Clear'
|
||||
value = @{}
|
||||
value = @{
|
||||
session_id = $global:_warpSessionId
|
||||
}
|
||||
}
|
||||
Warp-Send-JsonMessage $inputBufferMsg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user