Open fourpastmidnight opened 2 years ago
Thanks for the detailed report! There's a bit to chew through here, so I'll need to dedicate a bit of time to set up the repro.
On the face of it though, the traceback suggests that the debug adapter is not outputting valid DAP protocol messages. The "too many values to unpack" suggests that the data written to its channel by the debug adapter was not valid DAP.
Looking quickly at your adapter definition, vimspector is expecting DAP on the standard output of the adapter. I see from your comments that you're expecting to be able to use a unix domain socket for adapter communication. unfortunately I don't think that vimspector supports that right now. It could but certainly putting a "hostName" in the configuration that vimspector doesn't itself read is unlikely to achieve that. Right now, vimspector tries to use a vim channel (rather than a job) in the case that the 'port' entry is found in the adapter block. we would have to enhance that to support something that tells it to use a UDS instead (my guess).
Oh, I thought vimspector added support for Unix domain sockets! Whoops, my mistake. I can appreciate it'll take you some time to dig through the above report. In the meantime, I did see that the Start-EditorServices.ps1
cmdlet that's used to start PSES had a parameter named -Stdio
, so maybe it's possible to just use that? I'll dig through the PSES code again. But, adding UDS support to Vimspector would be great, too. I was poking around a bit to see if I could understand what it would take to add that support on the (not-so-)off-chance (apparently) I was wrong. 😉
And I found this in the PSES code, though, I'm not exactly sure of the implications—but I'm thinking that means no Console would be available in the debugging environment? If so, then I would want to try to enable Vimspector to support UDS.
if (_hostConfig.ConsoleRepl != ConsoleReplKind.None
&& (lspUsesStdio || debugUsesStdio))
{
throw new ArgumentException("Cannot use the REPL with a Stdio protocol transport");
}
I was able to make it work, sort of, with the following gadget installer file:
{
"cust_PowerShellEditorServices": {
"language": [ "powershell" ],
"download": {
"url": "https://github.com/PowerShell/PowerShellEditorServices/releases/download/v${version}/${file_name}",
"format": "zip"
},
"all": {
"version": "3.3.3",
"file_name": "PowerShellEditorServices.zip",
"checksum": "",
"extension_path": "",
"adapters": {
"cust_PowerShellEditorServices": {
"name": "cust_PowerShellEditorServices",
"variables": {
"PSES_BUNDLE_PATH": "${gadgetDir}/cust_PowerShellEditorServices",
"SESSION_TEMP_PATH": "${workspaceRoot}"
},
"type": "PowerShell",
"host": "unix",
"port": "$TMPDIR/CoreFxPipe_vimspector${unusedLocalPort}",
"tty": true,
"command": [
"pwsh",
"-NoLogo",
"-NoProfile",
"-Command", "$PSES_BUNDLE_PATH/PowerShellEditorServices/Start-EditorServices.ps1",
"-BundledModulesPath", "$PSES_BUNDLE_PATH",
"-LogPath", "$SESSION_TEMP_PATH/logs.log",
"-SessionDetailsPath", "$SESSION_TEMP_PATH/session.json",
"-FeatureFlags", "@()",
"-AdditionalModules", "@()",
"-HostName", "Vimspector",
"-HostProfileId", "Vimspector",
"-HostVersion", "1.0.0",
"-DebugServiceOnly",
"-DebugServicePipeName", "vimspector${unusedLocalPort}",
"-LogLevel", "Normal"
]
}
}
}
}
}
and the following .vimspector.json:
{
"configurations": {
"launch": {
"adapter": "cust_PowerShellEditorServices",
"configuration": {
"request": "launch",
"Script": "${file}",
"NoDebug": false,
"StopOnEntry": true,
"Args": [],
"Cwd": "${workspaceRoot}",
"CreateTemporaryIntegratedConsole": true,
"Env": {}
}
}
}
}
There are still some problems. It seems the debug adapter doesn't properly handle the shutdown sequence and I'm not seeing program output, but maybe you can make more progress from here.
Note you need at least vim v8.2.4684 (https://github.com/vim/vim/commit/cc766a85f460ebb7f8c915508447548b5f5b99bc) and the following vimspector hack:
diff --git a/autoload/vimspector/internal/channel.vim b/autoload/vimspector/internal/channel.vim
index 0129f3d..e51c6d8 100644
--- a/autoload/vimspector/internal/channel.vim
+++ b/autoload/vimspector/internal/channel.vim
@@ -62,17 +62,35 @@ function! vimspector#internal#channel#StartDebugSession( config ) abort
\ )
endif
- let l:addr = get( a:config, 'host', '127.0.0.1' ) . ':' . a:config[ 'port' ]
-
- echo 'Connecting to ' . l:addr . '... (waiting fo up to 10 seconds)'
- let s:ch = ch_open( l:addr,
- \ {
- \ 'mode': 'raw',
- \ 'callback': funcref( 's:_OnServerData' ),
- \ 'close_cb': funcref( 's:_OnClose' ),
- \ 'waittime': 10000,
- \ }
- \ )
+ let l:host = get( a:config, 'host', '127.0.0.1' )
+
+ let l:addr = l:host . ':' . a:config[ 'port' ]
+
+ if l:host ==# 'unix'
+ echo 'Waiting for' a:config[ 'port' ] . '... (for up to 10 seconds)'
+ let tries=0
+ while tries<10 && !filereadable( a:config[ 'port' ] )
+ sleep 1000m
+ let tries+=1
+ endwhile
+ let s:ch = ch_open( l:addr,
+ \ {
+ \ 'mode': 'raw',
+ \ 'callback': funcref( 's:_OnServerData' ),
+ \ 'close_cb': funcref( 's:_OnClose' ),
+ \ }
+ \ )
+ else
+ echo 'Connecting to ' . l:addr . '... (waiting for up to 10 seconds)'
+ let s:ch = ch_open( l:addr,
+ \ {
+ \ 'mode': 'raw',
+ \ 'callback': funcref( 's:_OnServerData' ),
+ \ 'close_cb': funcref( 's:_OnClose' ),
+ \ 'waittime': 10000,
+ \ }
+ \ )
+ endif
if ch_status( s:ch ) !=# 'open'
unlet! s:ch
@puremourning Thanks for this! I looked at this a bit last night. I modified my local copy of Vimspector, but I still need to get an updated Vim, which probably means compiling it myself. So that will take me a bit of time to do. But I'm keen on getting this working! I'll let you know how I make out.
I was able to custom compile Vim and I got the PSES to start. However, the PowerShell code doesn't seem to run, breakpoints are never hit, etc. Also, a console windows shows up on the side with the output from PSES (maybe because I'm using -LogLevel Verbose
??), and then when I hit "Restart", the original PSES console remains and then a new one is opened with a new instance of PSES.
So I guess I'm wondering what the behavior here ought to be? A couple of thoughts:
I'd really like to start using Vim as my main PowerShell editing and debugging environment, and vimspector will be a key part of that. So if there's anyway I can help, I'd like to try. I'm very new to Vim plugin development and have basically no knowledge of the vim codebase. And the last time I used Python was over 10 years ago (it was still Python 2)—but, it's just another language, I'm sure I can pick it up fairly quickly; so this is the least of my concerns. 😉
If you have any advice, guidance, tips, etc. to help get me started and/or as I progress through trying to get this to work correctly, I'd be appreciative. Especially as it relates to debugging vimspector itself. I'll continue to pour over Vimspector's code to gain a deeper understanding of it in the meantime.
Thanks for all your efforts so far with this issue!
FWIW, unix domain sockets seem like a cleaner way of implementing DAP server I/O than TCP for most cases, and if vimspector gets this support, then I'll add domain socket support to the probe-rs
dap server.
A variant of this would be to create a socketpair()
and pass a file descriptor to the child process.
Description
I read #69, and figured by now, this "should just work", with a bit of elbow grease from me. Reading that issue, it was a bit hard to understand what was taking place to "make things work". But today, I finally managed to get the PowerShellEditorServices to start the DebuggingServicesOnly portion, i.e., the Debug Adapter Protocol Server.
For background, here's what I've got to make this work up to this point:
cust_PowerShellEditorServices.json
(I added some comments, but obviously. they don't exist in the actual gadgets file):.vimspector.json
in the root of my PowerShell module project directory:Now, when I have a PowerShell file opened in Vim which is part of my module workspace, I press F5 to start debugging (for good measure, I set a breakpoint beforehand). When I do this, Vimspector starts, but I get red error messages in Vim. For good measure, here's the output from the PowerShellEditorServices, as well as the error messages in Vim (obtained via
:messages
):session.log
(specified as a parameter to the PowerShellEditorServices), which shows the debug adapter server started just fine and is listening for messages (some paths were changed to use$HOME
for my home directory, instead of showing the absolute path):Vimspector error stack trace (from
:messages
):I'm not sure about that last line in the stack trace:
ValueError: not enough values to unpack (expected 2, got 1)
. I know why the error was printed, but not how it got here. I tried adding to the gadget file command-WaitForDebugger
, thinking maybe it was a timing thing. But after adding that, nothing changed.Unlike when @TylerLeonhardt and @puremourning were first attempting to get PSES working in #69, I seemed to have made further progress since Vim now supports opening channels over Unix Domain Sockets, no longer requiring the "funky" "ssh to yourself and provide a port" to manually "wire everything" up. But for whatever reason, it appears Vimspector is either getting no data from PSES, or getting unexpected data.
Any help you could provide me in helping to understand how to investigate further, i.e. debug settings, additional logging, etc., would be greatly appreciated. Did I miss anything in the gadget file? Other advice you might happen to have?
Works in vim?
Reproducable in Vim
Works with clean config?
Yes
Minimal Reproduction
For context, I'm trying this in Ubuntu running in WSL. However, I was able to reproduce this on a laptop running Manjaro Linux 21 as well.
Use the following minimal
.vimrc
. Note that while not the most absolute minimal.vimrc
that it could be, it's most representative of how I've set up and configured Vim and Vimspector in both WSL and on Manjaro.Run the following commands:
Use the following
cust_PowerShellEditorServices.json
gadget installer file:Run the following commands in your shell:
Run
vim
, ensuring the.vimrc
above is used.Once in Vim, run the ex command
:PlugInstall
Once all plugins have been installed, you can
:q
to close the plugin window.For good measure, run
::CocInstall
to make sure all the CoC plugins are installed.Then let's install the PowerShellEditorServices debug adapter server:
::VimspectorInstall! --verbose
For good measure, exit Vim (
:qa
)Let's open our minimal "PowerShell project":
vim $HOME/MyModule/Do-Something.ps1
Press F5. For some reason, this didn't work on my Manjaro machine, so alternatively, in vim,
:call vimspector#Continue()
to start the debugger.At this point, the debug windows should open with a message that the debugger is initializing. But that never changes. Also, you'll notice some red text flash by in the messages area, as noted in my description.
Expected Behaviour
I expected Vimspector to begin reading from the named pipe opened by the PowerShellEditorServices and begin the debugging process.
Actual Behaviour
I got some errors in vimspector. The errors are reproducible in Ubuntu 20.02 running inside Windows Subsystem for Linux and Manjaro Linux.
Additional information
No response
Installation Type
Plugin Manager (git clone)
Vimspector version
4c693f33e3038c1199e0f2e1045f340339714b60
Debug Info
Log file
Vim version
Python version
N/A
Neovim diagnostics
Operating System
Linux MY-MACHINE 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Declaration