TheLeoP / powershell.nvim

First class powershell editor integration into Neovim
MIT License
28 stars 1 forks source link

bug: neovim hangs #2

Closed mjvh80 closed 3 weeks ago

mjvh80 commented 3 weeks ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.5 Build type: RelWithDebInfo LuaJIT 2.1.1703942320

Operating system/version

Windows 10

Describe the bug

Thanks for creating this plugin, I have been trying to get it to work in Neovim but I'm not managing so I thought to double check it should in fact be possible to debug a PowerShell script with it (I'm using Neovim on Windows via Windows Terminal with pwsh).

When I start debugging and select the current powershell file Neovim will block. I can see that the Start-EditorServices.ps1 script has been started and created a json file in the temp folder. Neovim hangs and ctrl+c will give the error "couldn't connect to pipe xyz" (where xyz does match the pipe in the json file).

I have installed the powershell_es LSP plugin via Mason (which seems to start its own ES process).

Steps To Reproduce

  1. load a powershell script
  2. start debugging (require'dap'.continue())
  3. select 1 for the current script

Expected Behavior

Debugging powershell scripts like in VS Code.

TheLeoP commented 3 weeks ago

I can't reproduce the bug, so I'm gonna need more info. What is the exact error message? I would also like to have a minimal repro, but this may be a race condition (maybe because your hardware takes longer to open the named pipe?).

This is an example of me using the default setings to debug a siple a.ps1 powershell script

demo

mjvh80 commented 3 weeks ago

Maybe not entirely minimal, but the following init.lua file causes trouble for me.

Note on the first line I had to put vim.system = vim.fn.system I don't know if this is correct, but otherwise I get an error that the field system does not exist.

Running the following: nvim -u init.lua test.ps1 I get an error on startup (test.ps1 just contains write-host 'foobar')

Error executing vim.schedule lua callback: ...gram Files/Neovim/share/nvim/runtime/lua/vim/lsp/rpc.lua:615: bad argument #1 to 'connect' (string expected, got nil)
stack traceback:
        [C]: in function 'connect'
        ...gram Files/Neovim/share/nvim/runtime/lua/vim/lsp/rpc.lua:615: in function 'cmd'
        C:/Program Files/Neovim/share/nvim/runtime/lua/vim/lsp.lua:1205: in function 'start_client'
        C:/Program Files/Neovim/share/nvim/runtime/lua/vim/lsp.lua:885: in function 'start'
        ...al/nvim-data/lazy/powershell.nvim/lua/powershell/lsp.lua:288: in function 'callback'
        ...l/nvim-data/lazy/powershell.nvim/lua/powershell/util.lua:123: in function 'inner_try_func'
        ...l/nvim-data/lazy/powershell.nvim/lua/powershell/util.lua:107: in function 'fn'
        vim/_editor.lua:477: in function 'cb'
        vim/_editor.lua:263: in function <vim/_editor.lua:262>

ignoring this and running :lua require'dap'.continue() and choosing 1 then causes nvim to block.

vim.system = vim.fn.system

local my_bundle_path = 'C:\\Users\\mahu\\AppData\\Local\\nvim-data\\mason\\packages\\powershell-editor-services'
local my_root_dir = 'C:\\Users\\mahu\\AppData\\Local\\nvim-dbg'

-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
  if vim.v.shell_error ~= 0 then
    vim.api.nvim_echo({
      { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
      { out, "WarningMsg" },
      { "\nPress any key to exit..." },
    }, true, {})
    vim.fn.getchar()
    os.exit(1)
  end
end
vim.opt.rtp:prepend(lazypath)

vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

require("lazy").setup({
  spec = {
    "williamboman/mason.nvim",
    "williamboman/mason-lspconfig.nvim",
    "neovim/nvim-lspconfig",

    "onsails/lspkind.nvim",

    {
        "mfussenegger/nvim-dap",
        config = function() end
    },

    { "rcarriga/nvim-dap-ui", dependencies = {"mfussenegger/nvim-dap", "nvim-neotest/nvim-nio"} },

    {
       "TheLeoP/powershell.nvim",

       config = function()
         require'powershell'.setup({
             bundle_path = my_bundle_path,
         })
       end
    },

  },
  install = { colorscheme = { "habamax" } },
  checker = { enabled = true },
})

local dapui = require("dapui")
local dap = require("dap")
dapui.setup()
dap.listeners.after.event_initialized["dapui_config"] = function()
    dapui.open({})
    require('dap-powershell').correct_repl_colors()
end

require'mason'.setup()
require('mason-lspconfig').setup({
    ensure_installed = { 'powershell_es' },
})
local lspconfig = require('lspconfig')
lspconfig.powershell_es.setup({
})

require('powershell').setup({
   capabilities = vim.lsp.protocol.make_client_capabilities(),
   bundle_path = my_bundle_path,
   init_options = vim.empty_dict(),
   settings = vim.empty_dict(),
   shell = "pwsh",
   handlers = base_handlers, -- see lua/powershell/handlers.lua
   root_dir = function(buf)
      local fs = vim.fs
      return my_root_dir
      --return fs.dirname(fs.find({ ".git" }, { upward = true, path = fs.dirname(vim.api.nvim_buf_get_name(buf)) })[1])
 end,
})

The session json file contains:

get-content C:/Users/mahu/AppData/Local/Temp/nvim/powershell_es.temp_session.json
{"status":"started","debugServiceTransport":"NamedPipe","debugServicePipeName":"\\\\.\\pipe\\PSES_0l1f450e.vzi","powerShellVersion":"7.4.3"}
TheLeoP commented 3 weeks ago

Note on the first line I had to put vim.system = vim.fn.system

Oh, right, you are using Neovim 0.9.5. The API needed to connect to the debug adapter via named pipes was added on Neovim 0.10, so it's needed for this plugin to work

mjvh80 commented 3 weeks ago

Sorry about that, can confirm it works with Neovim 0.10.