Skip to content

Null reference exceptions when trying to complete variable names #1926

Closed

Description

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

I have PowerShell Editor Services configured in KDE Kate using a script that does essentially:

& 'C:/Tools/PowerShellEditorServices/PowerShellEditorServices/Start-EditorServices.ps1' -BundledModulesPath C:/Tools/PowerShellEditorServices -LogPath $logPath -SessionDetailsPath $sessionPath -FeatureFlags @() -AdditionalModules @() -Stdio -LogLevel Normal -HostName $host -HostProfileId $profile -HostVersion $hostVersion

Sometimes, when I am typing a variable reference, PowerShell Editor Services throws a null reference exception. When it happens, it happens repeatedly, but I don't yet know the exact conditions. I will try to find specific trigger conditions tomorrow.

Expected behavior

Either a completion is offered successfully or fails silently.

Actual behavior

An exception is thrown, which is displayed in the editor window distractingly. (In Kate this is especially bad because the Output window pops up, grabbing keyboard focus.)

Error details

OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Failed to handle request textDocument/completion 1727 - System.NullReferenceException: Object reference not set to an instance of an object.
      at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Vistors\AstOperations.cs:line 141
      at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 248
      at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 82
      at OmniSharp.Extensions.LanguageServer.Server.Pipelines.SemanticTokensDeltaPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
      at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
      at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
      at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
      at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
      at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
      at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
      at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
      at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.<RouteRequest>g__InnerRoute|7_0(IServiceScopeFactory serviceScopeFactory, Request request, TDescriptor descriptor, Object params, CancellationToken token, ILogger logger)
      at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.RouteRequest(IRequestDescriptor`1 descriptors, Request request, CancellationToken token)
      at OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker.<>c__DisplayClass10_0.<<RouteRequest>b__5>d.MoveNext() | Method='textDocument/completion' RequestId='1727'

Environment data

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

3.5.1

Visuals

No response

Activity

  1. ghost added
    Needs: TriageMaintainer attention needed!
    on Sep 29, 2022
  2. andyleejordan commented on Oct 18, 2022

    @andyleejordan
    Member

    Hey, I was able to repro this! Interestingly the VS Code client doesn't crash after that fails, but the null reference exception is certainly happening, so we can hopefully get this fixed ASAP. Thank you so much for the detailed repro info!!! 🥳🥳🥳

  3. andyleejordan commented on Oct 21, 2022

    @andyleejordan
    Member

    Fixed with a regression test!

  4. MartinGC94 commented on Oct 22, 2022

    @MartinGC94
    Contributor

    The completion code shouldn't throw errors so it's probably worth creating an issue in https://github.com/PowerShell/PowerShell to fix the underlying issue.

  5. andyleejordan commented on Oct 24, 2022

    @andyleejordan
    Member

    Thanks so much MartinGC94!

  6. andyleejordan commented on Oct 25, 2022

    @andyleejordan
    Member

    Hi @alexbuzzbee! We just got this fixed in v3.6.0, can you verify for us?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions