Skip to content

Commit

Permalink
Added null check to GetCompletionsAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
dkattan authored and andyleejordan committed Feb 12, 2024
1 parent 3e12858 commit 9efac1c
Showing 1 changed file with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,10 @@ public static async Task<CommandCompletion> GetCompletionsAsync(
CancellationToken cancellationToken)
{
IScriptPosition cursorPosition = s_clonePositionWithNewOffset(scriptAst.Extent.StartScriptPosition, fileOffset);

logger.LogTrace($"Getting completions at offset {fileOffset} (line: {cursorPosition.LineNumber}, column: {cursorPosition.ColumnNumber})");

Stopwatch stopwatch = new();
logger.LogTrace($"Getting completions at offset {fileOffset} (line: {cursorPosition.LineNumber}, column: {cursorPosition.ColumnNumber})");

CommandCompletion commandCompletion = null;
await executionService.ExecuteDelegateAsync(
CommandCompletion commandCompletion = await executionService.ExecuteDelegateAsync(
representation: "CompleteInput",
new ExecutionOptions { Priority = ExecutionPriority.Next },
(pwsh, _) =>
Expand All @@ -108,35 +105,41 @@ await executionService.ExecuteDelegateAsync(

if (completionResults is { Count: > 0 })
{
commandCompletion = completionResults[0];
return completionResults[0];
}

return;
return null;
}

// If the current runspace is out of process, we can't call TabExpansion2
// because the output will be serialized.
commandCompletion = CommandCompletion.CompleteInput(
return CommandCompletion.CompleteInput(
scriptAst,
currentTokens,
cursorPosition,
options: null,
powershell: pwsh);
},
cancellationToken)
.ConfigureAwait(false);
cancellationToken).ConfigureAwait(false);

stopwatch.Stop();
logger.LogTrace(
"IntelliSense completed in {elapsed}ms - WordToComplete: \"{word}\" MatchCount: {count}",
stopwatch.ElapsedMilliseconds,
commandCompletion.ReplacementLength > 0
? scriptAst.Extent.StartScriptPosition.GetFullScript()?.Substring(
commandCompletion.ReplacementIndex,
commandCompletion.ReplacementLength)
: null,
commandCompletion.CompletionMatches.Count);

if (commandCompletion is null)
{
logger.LogError("Error Occurred in TabExpansion2");
}
else
{
logger.LogTrace(
"IntelliSense completed in {elapsed}ms - WordToComplete: \"{word}\" MatchCount: {count}",
stopwatch.ElapsedMilliseconds,
commandCompletion.ReplacementLength > 0
? scriptAst.Extent.StartScriptPosition.GetFullScript()?.Substring(
commandCompletion.ReplacementIndex,
commandCompletion.ReplacementLength)
: null,
commandCompletion.CompletionMatches.Count);
}
return commandCompletion;
}

Expand Down

0 comments on commit 9efac1c

Please sign in to comment.