-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
Windows: add support for named pipes #1230
Comments
Since debugging works in VSCode on Windows, could there be any clues there that might help us? |
The approach mentioned in this issue involves I remember trying a simmilar approach on powershell.nvim (currently, the only debug config is broken on Windows, so the repo does not contain said attempt), but I don't remember why I didn't continued using it. I think I may have posponed it while waiting for a response on PowerShell/PowerShellEditorServices#2164 |
I installed ---@param adapter dap.PipeAdapter
---@param opts? table
---@param on_connect fun(err?: string)
---@return dap.Session
function Session.pipe(adapter, opts, on_connect)
local pipe = assert(uv.new_pipe(), "Must be able to create pipe")
local session = new_session(adapter, opts or {}, pipe)
if adapter.executable then
if adapter.pipe == "${pipe}" then
-- don't mutate original adapter definition
adapter = vim.deepcopy(adapter)
session.adapter = adapter
local filepath = os.tmpname()
local is_windows = vim.fn.has("win32")
if is_windows then
filepath = vim.fs.basename(filepath)
adapter.pipe = string.format([[\\.\pipe\%s]], filepath)
else
os.remove(filepath)
adapter.pipe = filepath
end
session.on_close["dap.server_executable_pipe"] = function()
pcall(os.remove, filepath)
end
-- adapter.pipe = filepath
if adapter.executable.args then
local args = assert(adapter.executable.args)
for idx, arg in pairs(args) do
args[idx] = arg:gsub('${pipe}', filepath)
end
end
end
spawn_server_executable(adapter.executable, session)
log.debug(
"Debug adapter server executable started with pipe " .. adapter.pipe)
-- The adapter should create the pipe
local adapter_opts = adapter.options or {}
local timeout = adapter_opts.timeout or 5000
vim.print("waiting for pipe: " .. adapter.pipe)
vim.wait(timeout, function()
local ready = uv.fs_stat(adapter.pipe) ~= nil
if ready then
vim.print("pipe created")
end
return ready
end)
end Error:
It seems like the pipe gets created but never accepts connections. |
I'm experimenting with manually running |
That's because vim.wait(timeout, function()
return uv.fs_stat(adapter.pipe) ~= nil
end) to vim.wait(timeout, function()
return false
end) (to always wait 5 seconds before connecting to the pipe), it'll work (because now |
I did that as well. Can confirm it still doesn't connect. It's not in the example, but I did add a wait call in the connect method. |
For the sake of completion, @freddiehaddad I just pushed DAP support to powershel.nvim, but it still doesn't support using an integrated debug terminal |
Problem Statement
Currently, the plugin supports Unix domain sockets, but not Windows named pipes.
I was trying to come up with a minimal solution before opening an issue, but I've encountered a few problems.
Here, a temp file is created on the file to use it as a Unix domain socket, but this isn't valid in Windows.
nvim-dap/lua/dap/session.lua
Line 1238 in 922ebc7
So, I tried to do something like
But it turns out that Powershell Editor Services (what I'm trying to integrate nvim-dap with) doesn't like to receive the full path of the pipe, it only wants to receive the name. So, for testing purposes, I changed my code to:
Now, the executable gets the pipe name and nvim-dap connects to the pipe path.
Surprisingly, the following check does (almost) work also on Windows
uv.fs_stat
does return something once the named pipe is created, but the named pipe can be created without it being available for connections yet. So, another problem, nvim-dap can fail (with a timeout error) to connect to the named pipe ifpipe:connect(...)
is called too early.As fas as I can tell, there is no way to check if a named pipe is ready to receive connections and the only workaround is to retry the connection if it has failed with a timeout error (which seems messy).
Possible Solutions
No idea
Considered Alternatives
I'm trying not to rely on nvim-dap launching the Powershell Editor Services executable by creating a plugin powershell.nvim. This allows me to use some custom logic to wait for the pipe to be opened (the executable creates a json file when the pipe is ready to receive connections). But, I'm facing what I think it's a Neovim problem (?), I haven't fully debuged it yet.I launch the executable using:h termopen()
(since one of the Powershell Editor Services features is an integrated Powershell terminal) and the debugging session is launched correctly. However, the external executable does not process some actions until a new command (or even an empty line) is sent through the integrated terminal. My guess is that it has something to do with Neovim not providing separated handles fortty
andstdin
when opening a terminal (relevant issue), which causes the input to go throughtty
and hence the need for a new command (even an empty line) to be send via thetty
for the input to be received by the executable (but, as I said, I haven't debugged this on my Linux machine yet to confirm my suspicions).It turned out to be an Powershell Editor Services issue. I can't think of any alternatives :c
link to the issue
The text was updated successfully, but these errors were encountered: