Skip to content

Commit b5f2942

Browse files
committed
Added null check to GetCompletionsAsync
1 parent 8559105 commit b5f2942

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/PowerShellEditorServices/Services/Symbols/Visitors/AstOperations.cs

+12-8
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public static async Task<CommandCompletion> GetCompletionsAsync(
8181

8282
Stopwatch stopwatch = new();
8383

84-
CommandCompletion commandCompletion = null;
85-
await executionService.ExecuteDelegateAsync(
84+
CommandCompletion? commandCompletion = await executionService.ExecuteDelegateAsync(
8685
representation: "CompleteInput",
8786
new ExecutionOptions { Priority = ExecutionPriority.Next },
8887
(pwsh, _) =>
@@ -108,15 +107,14 @@ await executionService.ExecuteDelegateAsync(
108107

109108
if (completionResults is { Count: > 0 })
110109
{
111-
commandCompletion = completionResults[0];
110+
return completionResults[0];
112111
}
113-
114-
return;
112+
return null;
115113
}
116114

117115
// If the current runspace is out of process, we can't call TabExpansion2
118116
// because the output will be serialized.
119-
commandCompletion = CommandCompletion.CompleteInput(
117+
return CommandCompletion.CompleteInput(
120118
scriptAst,
121119
currentTokens,
122120
cursorPosition,
@@ -126,7 +124,13 @@ await executionService.ExecuteDelegateAsync(
126124
cancellationToken)
127125
.ConfigureAwait(false);
128126

129-
stopwatch.Stop();
127+
stopwatch.Stop();
128+
if(commandCompletion is null)
129+
{
130+
logger.LogError("Error Occurred in tabexpansion2");
131+
}
132+
else
133+
{
130134
logger.LogTrace(
131135
"IntelliSense completed in {elapsed}ms - WordToComplete: \"{word}\" MatchCount: {count}",
132136
stopwatch.ElapsedMilliseconds,
@@ -136,7 +140,7 @@ await executionService.ExecuteDelegateAsync(
136140
commandCompletion.ReplacementLength)
137141
: null,
138142
commandCompletion.CompletionMatches.Count);
139-
143+
}
140144
return commandCompletion;
141145
}
142146

0 commit comments

Comments
 (0)