From 0c1d459bc94767797dda4c56ac82c2fb8449be13 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 12 Jun 2017 11:52:24 -0700 Subject: [PATCH] Handle null case in ReferencesCodeLensProvider's CodeLens resolver This change fixes an issue where a null case isn't being handled gracefully in the ReferencesCodeLensProvider when resolving a CodeLens while the user is typing out a new function defintion or doing anything else that causes the code to change like formatting the script. Resolves PowerShell/vscode-powershell#857 Resolves PowerShell/vscode-powershell#855 --- .../CodeLens/CodeLensFeature.cs | 3 ++- .../CodeLens/ReferencesCodeLensProvider.cs | 22 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/PowerShellEditorServices.Host/CodeLens/CodeLensFeature.cs b/src/PowerShellEditorServices.Host/CodeLens/CodeLensFeature.cs index 17bcc65b21..6907f4a170 100644 --- a/src/PowerShellEditorServices.Host/CodeLens/CodeLensFeature.cs +++ b/src/PowerShellEditorServices.Host/CodeLens/CodeLensFeature.cs @@ -147,7 +147,8 @@ await requestContext.SendResult( } else { - // TODO: Write error! + await requestContext.SendError( + $"Could not find provider for the original CodeLens: {codeLensData.ProviderId}"); } } } diff --git a/src/PowerShellEditorServices.Host/CodeLens/ReferencesCodeLensProvider.cs b/src/PowerShellEditorServices.Host/CodeLens/ReferencesCodeLensProvider.cs index 3d1efc79d5..1fedc6cc5b 100644 --- a/src/PowerShellEditorServices.Host/CodeLens/ReferencesCodeLensProvider.cs +++ b/src/PowerShellEditorServices.Host/CodeLens/ReferencesCodeLensProvider.cs @@ -64,16 +64,18 @@ await editorSession.LanguageService.FindReferencesOfSymbol( references, editorSession.Workspace); - var referenceLocations = - referencesResult - .FoundReferences - .Select( - r => new Location - { - Uri = GetFileUri(r.FilePath), - Range = r.ScriptRegion.ToRange() - }) - .ToArray(); + Location[] referenceLocations = + referencesResult == null + ? new Location[0] + : referencesResult + .FoundReferences + .Select( + r => new Location + { + Uri = GetFileUri(r.FilePath), + Range = r.ScriptRegion.ToRange() + }) + .ToArray(); return new CodeLens(