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 021d381
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
Task SetupHelpForTests {
# TODO: Check if it must be updated in a compatible way!
Write-Host "Updating help for tests."
Update-Help -Module Microsoft.PowerShell.Management,Microsoft.PowerShell.Utility -Force -Scope CurrentUser
Update-Help -Module Microsoft.PowerShell.Management,Microsoft.PowerShell.Utility -Force -Scope CurrentUser -UICulture en-US
}

Task Build FindDotNet, CreateBuildInfo, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,10 @@ static AstOperations()
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 @@ static AstOperations()
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 021d381

Please sign in to comment.