Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added null check to GetCompletionsAsync #2115

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
@@ -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, {
Original file line number Diff line number Diff line change
@@ -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, _) =>
@@ -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;
}


Unchanged files with check annotations Beta

{
new OmniSharpFileSystemWatcher()
{
GlobPattern = "**/*.{ps1,psm1}",

Check warning on line 50 in src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs

GitHub Actions / ert

Possible null reference assignment.

Check warning on line 50 in src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs

GitHub Actions / analyze (csharp)

Possible null reference assignment.

Check warning on line 50 in src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs

GitHub Actions / themis

Possible null reference assignment.

Check warning on line 50 in src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs

GitHub Actions / dotnet (windows-latest)

Possible null reference assignment.

Check warning on line 50 in src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs

GitHub Actions / dotnet (macos-latest)

Possible null reference assignment.

Check warning on line 50 in src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs

GitHub Actions / dotnet (ubuntu-latest)

Possible null reference assignment.
Kind = WatchKind.Create | WatchKind.Delete | WatchKind.Change,
},
},
namespace PowerShellEditorServices.Test.E2E
{
[Trait("Category", "LSP")]
public class LanguageServerProtocolMessageTests : IClassFixture<LSPTestsFixture>, IDisposable

Check warning on line 31 in test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs

GitHub Actions / dotnet (windows-latest)

'LanguageServerProtocolMessageTests' is coupled with '120' different types from '31' different namespaces. Rewrite or refactor the code to decrease its class coupling below '96'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1506)

Check warning on line 31 in test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs

GitHub Actions / dotnet (macos-latest)

'LanguageServerProtocolMessageTests' is coupled with '120' different types from '31' different namespaces. Rewrite or refactor the code to decrease its class coupling below '96'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1506)

Check warning on line 31 in test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs

GitHub Actions / dotnet (ubuntu-latest)

'LanguageServerProtocolMessageTests' is coupled with '120' different types from '31' different namespaces. Rewrite or refactor the code to decrease its class coupling below '96'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1506)
{
// Borrowed from `VersionUtils` which can't be used here due to an initialization problem.
private static bool IsLinux { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
protected PsesStdioProcess _psesProcess;
public int ProcessId => _psesProcess.Id;
public async Task InitializeAsync()

Check warning on line 44 in test/PowerShellEditorServices.Test.E2E/LSPTestsFixures.cs

GitHub Actions / dotnet (windows-latest)

'InitializeAsync' is coupled with '42' different types from '21' different namespaces. Rewrite or refactor the code to decrease its class coupling below '41'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1506)

Check warning on line 44 in test/PowerShellEditorServices.Test.E2E/LSPTestsFixures.cs

GitHub Actions / dotnet (macos-latest)

'InitializeAsync' is coupled with '42' different types from '21' different namespaces. Rewrite or refactor the code to decrease its class coupling below '41'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1506)

Check warning on line 44 in test/PowerShellEditorServices.Test.E2E/LSPTestsFixures.cs

GitHub Actions / dotnet (ubuntu-latest)

'InitializeAsync' is coupled with '42' different types from '21' different namespaces. Rewrite or refactor the code to decrease its class coupling below '41'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1506)
{
LoggerFactory factory = new();
_psesProcess = new PsesStdioProcess(factory, IsDebugAdapterTests);