Skip to content

Commit 0c1d459

Browse files
committed
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
1 parent 6fa555a commit 0c1d459

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/PowerShellEditorServices.Host/CodeLens/CodeLensFeature.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ await requestContext.SendResult(
147147
}
148148
else
149149
{
150-
// TODO: Write error!
150+
await requestContext.SendError(
151+
$"Could not find provider for the original CodeLens: {codeLensData.ProviderId}");
151152
}
152153
}
153154
}

src/PowerShellEditorServices.Host/CodeLens/ReferencesCodeLensProvider.cs

+12-10
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,18 @@ await editorSession.LanguageService.FindReferencesOfSymbol(
6464
references,
6565
editorSession.Workspace);
6666

67-
var referenceLocations =
68-
referencesResult
69-
.FoundReferences
70-
.Select(
71-
r => new Location
72-
{
73-
Uri = GetFileUri(r.FilePath),
74-
Range = r.ScriptRegion.ToRange()
75-
})
76-
.ToArray();
67+
Location[] referenceLocations =
68+
referencesResult == null
69+
? new Location[0]
70+
: referencesResult
71+
.FoundReferences
72+
.Select(
73+
r => new Location
74+
{
75+
Uri = GetFileUri(r.FilePath),
76+
Range = r.ScriptRegion.ToRange()
77+
})
78+
.ToArray();
7779

7880
return
7981
new CodeLens(

0 commit comments

Comments
 (0)