PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
623 stars 214 forks source link

CodeLens related commands cause exception to be thrown #2172

Open mhintzke opened 3 weeks ago

mhintzke commented 3 weeks ago

Prerequisites

Summary

In the repository below, I have forked @TylerLeonhardt's old Monaco + PSES example, upgraded to the (almost) latest version of all packages, and wrote up how to reproduce the issue in the README.md.

https://github.com/mhintzke/monaco-powershell

Basically, regardless of OS (Windows or Unix) when the editor detects that the contents contains a basic function, e.g.

function Verb-Noun {

}

Then Monaco Client sends some commands such as textDocument/codeLens and codeLens/resolve. Both of which cause an exception to be thrown here

https://github.com/PowerShell/PowerShellEditorServices/blob/41fce39f491d5d351b4ac5864e89857ec070e107/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs#L144

This is all using very basic configuration of the Monaco Editor and a model URI of inmemory://model.ps1. Basically when these commands are handled by PSES, they attempt to open the file at the uri above, but somehow along the way to the function above, gets translated into an "empty" string.

Because we are working with inmemory models here, I feel like we should just not even attempt to perform a File System read at all. I'm not 100% what the intended function of these commands are, but they might be not applicable in the scenario where we use inmemory models. Please correct me if I am wrong.

PowerShell Version

❯ $PSVersionTable
                                                                                                                        Name                           Value
----                           -----
PSVersion                      7.4.4
PSEdition                      Core
GitCommitId                    7.4.4
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Editor Version

Monaco v7.0.7

PowerShell Editor Services Version

v3.20.1

(Invoke-RestMethod https://api.github.com/repos/PowerShell/PowerShellEditorServices/releases/latest).tag_name // v3.20.1

Steps to Reproduce

See forked repository README.md

Visuals

No response

Logs

No response

andyleejordan commented 2 weeks ago

Can you provide a callstack?

mhintzke commented 2 weeks ago

@andyleejordan The callstack and more pertinent information is in the forked repository README.md I linked above. Here it is though just to make it easier:

Uncaught Error: Internal Error - System.ArgumentException: The value cannot be an empty string. (Parameter 'path')
   at System.ArgumentException.ThrowNullOrEmptyException(String argument, String paramName)
   at System.IO.Strategies.FileStreamHelpers.ValidateArguments(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at Microsoft.PowerShell.EditorServices.Services.WorkspaceService.OpenStreamReader(DocumentUri uri) in C:\__w\1\s\src\PowerShellEditorServices\Services\Workspace\WorkspaceService.cs:line 398
   at Microsoft.PowerShell.EditorServices.Services.WorkspaceService.GetFile(DocumentUri documentUri) in C:\__w\1\s\src\PowerShellEditorServices\Services\Workspace\WorkspaceService.cs:line 144
   at Microsoft.PowerShell.EditorServices.Services.WorkspaceService.TryGetFile(DocumentUri documentUri, ScriptFile& scriptFile) in C:\__w\1\s\src\PowerShellEditorServices\Services\Workspace\WorkspaceService.cs:line 211
   at Microsoft.PowerShell.EditorServices.Services.AnalysisService.GetMostRecentCodeActionsForFileAsync(DocumentUri uri) in C:\__w\1\s\src\PowerShellEditorServices\Services\Analysis\AnalysisService.cs:line 218
   at Microsoft.PowerShell.EditorServices.Handlers.PsesCodeActionHandler.Handle(CodeActionParams request, CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CodeActionHandler.cs:line 49
   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()

Error: Internal Error - System.ArgumentException: The value cannot be an empty string. (Parameter 'path')
   at System.ArgumentException.ThrowNullOrEmptyException(String argument, String paramName)
   at System.IO.Strategies.FileStreamHelpers.ValidateArguments(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at Microsoft.PowerShell.EditorServices.Services.WorkspaceService.OpenStreamReader(DocumentUri uri) in C:\__w\1\s\src\PowerShellEditorServices\Services\Workspace\WorkspaceService.cs:line 398
   at Microsoft.PowerShell.EditorServices.Services.WorkspaceService.GetFile(DocumentUri documentUri) in C:\__w\1\s\src\PowerShellEditorServices\Services\Workspace\WorkspaceService.cs:line 144
   at Microsoft.PowerShell.EditorServices.Services.WorkspaceService.TryGetFile(DocumentUri documentUri, ScriptFile& scriptFile) in C:\__w\1\s\src\PowerShellEditorServices\Services\Workspace\WorkspaceService.cs:line 211
   at Microsoft.PowerShell.EditorServices.Services.AnalysisService.GetMostRecentCodeActionsForFileAsync(DocumentUri uri) in C:\__w\1\s\src\PowerShellEditorServices\Services\Analysis\AnalysisService.cs:line 218
   at Microsoft.PowerShell.EditorServices.Handlers.PsesCodeActionHandler.Handle(CodeActionParams request, CancellationToken cancellationToken) in C:\__w\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CodeActionHandler.cs:line 49
   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()
    at handleResponse (http://localhost:5555/main.bundle.js:1331:48)
    at handleMessage (http://localhost:5555/main.bundle.js:1111:13)
    at processMessageQueue (http://localhost:5555/main.bundle.js:1128:17)
    at http://localhost:5555/main.bundle.js:1100:13
    at http://localhost:5555/main.bundle.js:108245:29