From 328eaf868cd931278a460ab87f7fda5a439aa758 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 17 Dec 2019 20:41:45 -0800 Subject: [PATCH 1/3] Add trailing line number to filename for ConciseView --- .../DefaultFormatters/PowerShellCore_format_ps1xml.cs | 2 +- test/powershell/engine/Formatting/ErrorView.Tests.ps1 | 2 +- 2 files changed, 2 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 2237e05f5f7..190cb190287 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,7 @@ function Get-ConciseViewPositionMessage { $useTargetObject = $true } elseif ($myinv.ScriptName) { - $posmsg = ""${resetcolor}$($myinv.ScriptName)${newline}"" + $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 500ac52ee8e..5443f3fca1c 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 *' } From d93a506d05b6678d3b8e955f9698df0c42349252 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 17 Dec 2019 21:10:37 -0800 Subject: [PATCH 2/3] fix test --- test/powershell/engine/Formatting/ErrorView.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 index 5443f3fca1c..079ba94d290 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}:4" + $e | Out-String | Should -BeLike "*${testScriptPath}:4*" # validate line number is shown $e | Out-String | Should -BeLike '* 4 *' } From ba51dfb4e46e875b7a382efdf04576e677ddfd07 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 17 Dec 2019 22:34:41 -0800 Subject: [PATCH 3/3] Detect if using vscode and provide column information --- .../DefaultFormatters/PowerShellCore_format_ps1xml.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 190cb190287..1a26db5c6da 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 @@ function Get-ConciseViewPositionMessage { $useTargetObject = $true } elseif ($myinv.ScriptName) { - $posmsg = ""${resetcolor}$($myinv.ScriptName):$($myinv.ScriptLineNumber)${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}""