From 563b1cba831b5e7b6db733a71031a65b8a494609 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 18 Dec 2019 14:05:56 -0800 Subject: [PATCH] Add trailing line number to filename for ConciseView (#11391) --- .../DefaultFormatters/PowerShellCore_format_ps1xml.cs | 8 +++++++- test/powershell/engine/Formatting/ErrorView.Tests.ps1 | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 170893402..101bb1430 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -1058,7 +1058,13 @@ namespace System.Management.Automation.Runspaces $useTargetObject = $true } elseif ($myinv.ScriptName) { - $posmsg = ""${resetcolor}$($myinv.ScriptName)${newline}"" + if ($env:TERM_PROGRAM -eq 'vscode') { + # If we are running in vscode, we know the file:line:col links are clickable so we use this format + $posmsg = ""${resetcolor}$($myinv.ScriptName):$($myinv.ScriptLineNumber):$($myinv.OffsetInLine)${newline}"" + } + else { + $posmsg = ""${resetcolor}$($myinv.ScriptName):$($myinv.ScriptLineNumber)${newline}"" + } } else { $posmsg = ""${newline}"" diff --git a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 index 592fd7ff1..a786660b8 100644 --- a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 +++ b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 @@ -32,7 +32,7 @@ Describe 'Tests for $ErrorView' -Tag CI { $testScriptPath = Join-Path -Path $TestDrive -ChildPath 'test.ps1' Set-Content -Path $testScriptPath -Value $testScript $e = { & $testScriptPath } | Should -Throw -ErrorId 'UnexpectedToken' -PassThru - $e | Out-String | Should -BeLike "*$testScriptPath*" + $e | Out-String | Should -BeLike "*${testScriptPath}:4*" # validate line number is shown $e | Out-String | Should -BeLike '* 4 *' }