Skip to content

Stdio mode broken since v3.0.0 #1695

Closed

Description

Hi!

Kate is an awesome open source text editor made by the KDE folks, and it supports language servers. By default, they provide configurations for some popular languages, documented here: https://docs.kde.org/trunk5/en/kate/kate/kate-application-plugin-lspclient.html

I am trying to add PowerShell support in it, by using this config:

{
    "servers": {
        "powershell": {
            "command": ["pwsh", "-NoLogo", "-NoProfile", "-Command", "%{ENV:USERPROFILE}/Desktop/PowerShellEditorServices/PowerShellEditorServices/Start-EditorServices.ps1", "-BundledModulesPath", "%{ENV:USERPROFILE}/Desktop/PowerShellEditorServices", "-LogPath", "%{ENV:TEMP}/kate/logs.log", "-SessionDetailsPath", "%{ENV:TEMP}/kate/session.json", "-HostName", "Kate", "-HostProfileId", "KDE.Kate", "-HostVersion", "2.0.0", "-Stdio", "-LogLevel", "Normal"],
            "highlightingModeRegex": "^PowerShell$"
        }
    }
}

The server starts successfully, and recognizes symbols, but that's it. Nothing else seems to work, definitions go-to, hover etc. This is the log:

2022-02-02 12:11:37.835 +05:30 [INF] highlight handler loaded
2022-02-02 12:11:38.942 +05:30 [INF] PSScriptAnalyzer settings file not found. Falling back to default rules
2022-02-02 12:11:43.975 +05:30 [FTL] Failed to handle request textDocument/hover 3
System.InvalidOperationException: Stack empty.
   at System.Collections.Generic.Stack`1.ThrowForEmptyStack()
   at System.Collections.Generic.Stack`1.Peek()
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.get_CurrentFrame() in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 153
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.get_CurrentRunspace() in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 137
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.Microsoft.PowerShell.EditorServices.Services.PowerShell.Runspace.IRunspaceContext.get_CurrentRunspace() in D:\a\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 151
   at Microsoft.PowerShell.EditorServices.Services.SymbolsService.FindSymbolDetailsAtLocationAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber) in D:\a\1\s\src\PowerShellEditorServices\Services\Symbols\SymbolsService.cs:line 327
   at Microsoft.PowerShell.EditorServices.Handlers.PsesHoverHandler.Handle(HoverParams request, CancellationToken cancellationToken) in D:\a\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\HoverHandler.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()

I'm using PowerShell 7.1.2 on Windows 10 21H2.

Activity

  1. ydschneider commented on Feb 10, 2022

    @ydschneider

    I had the same issue when trying to use the builtin Neovim LSP client. I tried some older versions of the PowerShell Editor Services, release 2.5.3 works fine for me so far. Seems like this is broken since 3.0

  2. rashil2000 commented on Feb 10, 2022

    @rashil2000
    Author

    Wow! Thank you, you're a genius :)

    2.5.3 works perfect.

    Seems like this is broken since 3.0

    It looks like there was a major refactor, which broke it for stdio mode.

  3. changed the title [-]Help needed with Kate configuration[/-] [+]Stdio mode broken since v3.0.0[/+] on Feb 10, 2022
  4. rashil2000 commented on Feb 10, 2022

    @rashil2000
    Author

    Updated the title to be more specific

  5. andyleejordan commented on Feb 16, 2022

    @andyleejordan
    Member

    I think it's probably #1592

    Interestingly though, we have a suite of LSP and DAP tests which use PSES over stdio, and they work. So we'll have to dig into what exactly is still broken.

  6. andyleejordan commented on Feb 16, 2022

    @andyleejordan
    Member

    Looking at that stack trace makes me wonder if we actually get into a command loop, since non-Code LSP clients don't usually start up an integrated console. 🤔

  7. rashil2000 commented on Feb 16, 2022

    @rashil2000
    Author

    If it helps, Kate does have an integrated terminal, but only on Linux.

  8. andyleejordan commented on Feb 16, 2022

    @andyleejordan
    Member

    Hm, does it work on Linux just fine?

  9. rashil2000 commented on Feb 16, 2022

    @rashil2000
    Author

    I have not tested it (don't have linux system).

  10. ydschneider commented on Feb 18, 2022

    @ydschneider

    Just had a chance to test on Linux and got the exact same behavior. 3.1.2 and 3.1.3 lead to the error message from the original post, 2.5.3 works.

  11. fl3pp commented on Apr 3, 2022

    @fl3pp

    I'm having the same issue using the Neovim LSP client and version 3.1.6 on Windows. Version 2.5.3 works just fine.

    Because I didn't set up the project before, I spend hours troubleshooting this thing until I found this issue... Since LSP is just starting to take off in many editors, it is actually a bit frightening that stdio clients have been broken for so long, with many releases in between.

  12. andyleejordan commented on Apr 4, 2022

    @andyleejordan
    Member

    jflepp We are still working on getting v3 "released" into its main consumer, the VS Code extension. Once that work is done, we're slated to come back and get the stdio mode working again too 😊

  13. fl3pp commented on Apr 4, 2022

    @fl3pp

    Andy Jordan (@andschwa) Appreciate the work, thanks for the update 👍

    Sorry if I came off a bit judgy / demanding, I was just a bit frustrated. It's now working in the 2.5 release and I'm having a blast working with PowerShell completely in the console 😊

    But if I understand this correctly, does this mean that the versions 3.0.0+ are neither working in VSCode nor in stdio based editors? Maybe it would then make sense to mark them as pre-releases so that people don't get confused.

  14. andyleejordan commented on Apr 4, 2022

    @andyleejordan
    Member

    3.0.0 is only in the preview channel for VS Code, and our top priority is to get that stable enough to release to the stable channel. So it's working (it uses named pipes) but we're working on sorting through our remaining MVP issues.

  15. 4 remaining items

  16. andyleejordan commented on May 9, 2022

    @andyleejordan
    Member

    Getting to work on this now!

  17. moved this from P0 - Todo to In Progress in American Pharoah on May 9, 2022
  18. Repository owner moved this from In Progress to Done in American Pharoah on May 17, 2022
  19. andyleejordan commented on May 17, 2022

    @andyleejordan
    Member

    I think I got this solved! It was...a doozy. Had a few issues to fix. Tested successfully with eglot in Emacs. Will get a release out ASAP (today is the plan!) and hope you all can test in your various environments with different clients.

  20. andyleejordan commented on May 18, 2022

    @andyleejordan
    Member

    Heyo, sorry, that took a bit longer to get out than expected due to client-side tests failing. Rashil Gandhi (@rashil2000), fl3pp, Yannick Schneider (@ydschneider) Can you give v3.4.0 a try?

  21. fl3pp commented on May 19, 2022

    @fl3pp

    Hi Andy Jordan (@andschwa), thanks for taking a look at the issue.

    Unfortunately, the version you supplied doesn't work, although a behavior change was noticeable. In the log of NeoVim NVIM v0.7.0-dev+1385-g6786b6afa I can see following exceptions thrown by PowershellES:

    2022-05-19 20:56:07.394 +02:00 [FTL] Failed to handle request initialize 1
    System.Management.Automation.PSInvalidOperationException: No commands are specified.
       at System.Management.Automation.PowerShell.Prepare[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings, Boolean shouldCreateWorker)
       at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
       at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
       at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear(PowerShell pwsh, PSInvocationSettings invocationSettings) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 88
       at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeCommand(PowerShell pwsh, PSCommand psCommand, PSInvocationSettings invocationSettings) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 105
       at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.LoadProfiles(PowerShell pwsh, ProfilePathInfo profilePaths) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 214
       at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.<LoadHostProfilesAsync>b__102_0(PowerShell pwsh, CancellationToken _) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 437
       at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPSDelegateTask.Run(CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousDelegateTask.cs:line 95
       at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.ExecuteSynchronously(CancellationToken executorCancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousTask.cs:line 92
    --- End of stack trace from previous location ---
       at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.TryStartAsync(HostStartOptions startOptions, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Host\PsesInternalHost.cs:line 250
       at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.MediatR.IRequestHandler<OmniSharp.Extensions.LanguageServer.Protocol.Models.InternalInitializeParams,OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult>.Handle(InternalInitializeParams request, CancellationToken token)
       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()
    2022-05-19 20:56:07.439 +02:00 [WRN] Tried to send request or notification before initialization was completed and will be sent later {"Id":1,"Error":{"Code":-32603,"Data":null,"Message":"Internal Error - System.Management.Automation.PSInvalidOperationException: No commands are specified.\r\n   at System.Management.Automation.PowerShell.Prepare[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings, Boolean shouldCreateWorker)\r\n   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)\r\n   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)\r\n   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)\r\n   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)\r\n   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear(PowerShell pwsh, PSInvocationSettings invocationSettings) in D:\\a\\_work\\1\\s\\src\\PowerShellEditorServices\\Services\\PowerShell\\Utility\\PowerShellExtensions.cs:line 88\r\n   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeCommand(PowerShell pwsh, PSCommand psCommand, PSInvocationSettings invocationSettings) in D:\\a\\_work\\1\\s\\src\\PowerShellEditorServices\\Services\\PowerShell\\Utility\\PowerShellExtensions.cs:line 105\r\n   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.LoadProfiles(PowerShell pwsh, ProfilePathInfo profilePaths) in D:\\a\\_work\\1\\s\\src\\PowerShellEditorServices\\Services\\PowerShell\\Utility\\PowerShellExtensions.cs:line 214\r\n   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.<LoadHostProfilesAsync>b__102_0(PowerShell pwsh, CancellationToken _) in D:\\a\\_work\\1\\s\\src\\PowerShellEditorServices\\Services\\PowerShell\\Host\\PsesInternalHost.cs:line 437\r\n   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPSDelegateTask.Run(CancellationToken cancellationToken) in D:\\a\\_work\\1\\s\\src\\PowerShellEditorServices\\Services\\PowerShell\\Execution\\SynchronousDelegateTask.cs:line 95\r\n   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.ExecuteSynchronously(CancellationToken executorCancellationToken) in D:\\a\\_work\\1\\s\\src\\PowerShellEditorServices\\Services\\PowerShell\\Execution\\SynchronousTask.cs:line 92\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost.TryStartAsync(HostStartOptions startOptions, CancellationToken cancellationToken) in D:\\a\\_work\\1\\s\\src\\PowerShellEditorServices\\Services\\PowerShell\\Host\\PsesInternalHost.cs:line 250\r\n   at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.MediatR.IRequestHandler<OmniSharp.Extensions.LanguageServer.Protocol.Models.InternalInitializeParams,OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult>.Handle(InternalInitializeParams request, CancellationToken token)\r\n   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.SemanticTokensDeltaPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n   at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n   at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\r\n   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.<RouteRequest>g__InnerRoute|7_0(IServiceScopeFactory serviceScopeFactory, Request request, TDescriptor descriptor, Object params, CancellationToken token, ILogger logger)\r\n   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.RouteRequest(IRequestDescriptor`1 descriptors, Request request, CancellationToken token)\r\n   at OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker.<>c__DisplayClass10_0.<<RouteRequest>b__5>d.MoveNext()","$type":"ErrorMessage"},"Method":"initialize","$type":"InternalError"}
    

    The configuration I'm running works flawlessly with version 2.5.3:

    local temp_path = vim.fn.stdpath 'cache'
    local pes_path = vim.env.HOME .. '\\bin\\powershell-es'
    local pes_template =
       [[& '%s\PowerShellEditorServices\Start-EditorServices.ps1' -BundledModulesPath '%s' -LogPath '%s\powershell_es.log' -SessionDetailsPath '%s\powershell_es.session.json' -FeatureFlags @() -AdditionalModules @() -HostName nvim -HostProfileId 0 -HostVersion 1.0.0 -Stdio -LogLevel Normal]]
    
    require'lspconfig'.powershell_es.setup {
       on_attach = on_attach,
       capabilities = capabilities,
       shell = 'pwsh',
       cmd = {
          'pwsh',
          '-NoLogo',
          '-NoProfile',
          '-Command',
          pes_template:format(pes_path,pes_path,temp_path,temp_path)
    }}
    
  22. andyleejordan commented on May 19, 2022

    @andyleejordan
    Member

    Interesting...I have it working with Emacs and eglot with this configuration:

    (use-package eglot ; an LSP client in GNU ELPA
      :hook
      (powershell-mode . eglot-ensure)
      :custom
      (eglot-auto-display-help-buffer t)
      (eglot-autoshutdown t)
      (eglot-confirm-server-initiated-edits nil)
      (eglot-connect-timeout nil)
      :config
      (add-to-list 'eglot-server-programs '(powershell-mode . ("pwsh" "-NoLogo" "-NoProfile" "-Command" "~/src/PowerShellEditorServices/module/PowerShellEditorServices/Start-EditorServices.ps1" "-BundledModulesPath" "/Users/andschwa/src/PowerShellEditorServices/module" "-Stdio" "-LogPath" "/Users/andschwa/src/pses.log" "-SessionDetailsPath" "/Users/andschwa/src/session.json" "-HostName" "Emacs" "-HostProfileId" "Emacs" "-HostVersion" "1.0.0" "-LogLevel" "Diagnostic"))))
  23. andyleejordan commented on May 19, 2022

    @andyleejordan
    Member

    We figured it out! Fix incoming.

  24. andyleejordan commented on May 19, 2022

    @andyleejordan
    Member

    fl3pp thanks for that log, it was super helpful. #1807

  25. andyleejordan commented on May 20, 2022

    @andyleejordan
    Member

    Ok fl3pp Can you please test https://github.com/PowerShell/PowerShellEditorServices/releases/tag/v3.4.1? I fixed that issue, but wonder if you'll find another!

  26. fl3pp commented on May 20, 2022

    @fl3pp

    Andy Jordan (@andschwa) didn't find anything, it just works!

    Thanks for fixing and have a nice weekend 😄

  27. andyleejordan commented on May 20, 2022

    @andyleejordan
    Member

    Yay! Thank you for testing!!!

  28. andyleejordan commented on Jun 9, 2022

    @andyleejordan
    Member

    Hey all, I really didn't want this to happen again, so I've setup a full regression test against Eglot (an Emacs LSP client using PSES over stdio).

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

Metadata

Metadata

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions