From 087f5836d91cdddc14efa2e30e8b332a722ae238 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 19 Dec 2016 07:39:41 -0800 Subject: [PATCH 1/2] Fix #323: DSC IntelliSense can cause language service to crash This change fixes an issue which appears sometimes when getting IntelliSense results within a DSC resource. The completion results return a replacement range of -1 which causes an exception in our BufferRange class. This fix catches and logs this exception so that the session may continue. Also fixes PowerShell/vscode-powershell#391. --- .../Language/LanguageService.cs | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/PowerShellEditorServices/Language/LanguageService.cs b/src/PowerShellEditorServices/Language/LanguageService.cs index 2f36145cf..e7e0a3769 100644 --- a/src/PowerShellEditorServices/Language/LanguageService.cs +++ b/src/PowerShellEditorServices/Language/LanguageService.cs @@ -102,23 +102,33 @@ await this.powerShellContext.GetRunspaceHandle( if (commandCompletion != null) { - CompletionResults completionResults = - CompletionResults.Create( - scriptFile, - commandCompletion); - - // save state of most recent completion - mostRecentCompletions = completionResults; - mostRecentRequestFile = scriptFile.Id; - mostRecentRequestLine = lineNumber; - mostRecentRequestOffest = columnNumber; - - return completionResults; - } - else - { - return new CompletionResults(); + try + { + CompletionResults completionResults = + CompletionResults.Create( + scriptFile, + commandCompletion); + + // save state of most recent completion + mostRecentCompletions = completionResults; + mostRecentRequestFile = scriptFile.Id; + mostRecentRequestLine = lineNumber; + mostRecentRequestOffest = columnNumber; + + return completionResults; + } + catch(ArgumentException e) + { + // Bad completion results could return an invalid + // replacement range, catch that here + Logger.Write( + LogLevel.Error, + $"Caught exception while trying to create CompletionResults:\n\n{e.ToString()}"); + } } + + // If all else fails, return empty results + return new CompletionResults(); } /// From b190b716d983167c5501e0c01fac28972b52b658 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 19 Dec 2016 07:41:01 -0800 Subject: [PATCH 2/2] Update FetchLatestBuild.ps1 script to look for Host dll instead of exe --- scripts/FetchLatestBuild.ps1 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/scripts/FetchLatestBuild.ps1 b/scripts/FetchLatestBuild.ps1 index 38b8bdbc1..00abb1c42 100644 --- a/scripts/FetchLatestBuild.ps1 +++ b/scripts/FetchLatestBuild.ps1 @@ -38,18 +38,13 @@ function Install-BuildPackage($packageName, $extension) { mkdir $binariesToSignPath -Force | Out-Null cp "$packageContentPath\lib\net45\$packageName.$extension" -Force -Destination $binariesToSignPath - # Don't forget the x86 exe - if ($extension -eq "exe") { - cp "$packageContentPath\lib\net45\$packageName.x86.$extension" -Force -Destination $binariesToSignPath - } - Write-Output "Extracted package $packageName ($buildVersion)" } # Pull the build packages from AppVeyor Install-BuildPackage "Microsoft.PowerShell.EditorServices" "dll" Install-BuildPackage "Microsoft.PowerShell.EditorServices.Protocol" "dll" -Install-BuildPackage "Microsoft.PowerShell.EditorServices.Host" "exe" +Install-BuildPackage "Microsoft.PowerShell.EditorServices.Host" "dll" # Open the BinariesToSign folder & start $binariesToSignPath