Skip to content
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

[Feature Request] Support connections using unix domain sockets (for PowerShellEditorServices) #589

Open
2 tasks done
fourpastmidnight opened this issue May 3, 2022 · 7 comments
Labels
enhancement New feature or request needs votes +1 the issue or vote on the trollo card if you would like this Server support A debug server exists, test that it works, and document it

Comments

@fourpastmidnight
Copy link

fourpastmidnight commented May 3, 2022

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:

  1. cust_PowerShellEditorServices.json (I added some comments, but obviously. they don't exist in the actual gadgets file):

    {
        "cust_PowerShellEditorServices": {
            "language": [ "powershell" ],
            "download": {
                "url": "https://githum.com/PowerShell/PowerShellEditorServices/releases/download/v${version}/${file_name}",
                "format": "zip"
            },
            "extension_path": "", // <-- This is necessary so the symlink gets created correctly
            "adapters": {
                "cust_PowerShellEditorServices": {
                    "name": "cust_PowerShellEditorServices", // <-- Should probably just be PowerShell
                    "type": "PowerShell",
                    "command": [
                        "pwsh",
                        "-NoProfile",
                        "-NonInteractive",
                        "-File",
                        "${gadgetDir}/cust_PowerShellEditorServices/PowerShellEditorServices/Start-EditorServices.ps1",
                        "-BundledModulesPath",
                        "${gadgetDir}/cust_PowerShellEditorServices/",
                        "-LogPath",
                        "$PWD/session.log", // <-- Probably should make this a variable?
                        "-SessionDetailsPath",
                        "$PWD/session.json", // <-- This, too. Both this and the previous are required :(
                        "-HostName",
                        "Vimspector",
                        "-HostProfileId",
                        "vimspector",
                        "-HostVersion",
                        "1.0.0",
                        "-LogLevel",
                        "Verbose", // <-- Another variable?
                        "-DebugServiceOnly",
                        "-DebugServicePipeName",
                        "vimspector",
                        "-EnableConsoleRepl",
                        "-WaitForDebugger" // <-- Need this??
                    ]
                }
            }
        }
    }
  2. .vimspector.json in the root of my PowerShell module project directory:

    {
        "configurations": {
            "PowerShell: Launch Current File": {
                "adapter": "cust_PowerShellEditorServices",
                "configuration": {
                    // Most of these settings taken straight from the vscode-powershell extension
                    // for the launch profile of the same name
                    "name": "PowerShell: Launch Current File",
                    "type": "PowerShell",
                    "request": "launch",
                    "script": "${file}",
                    "cwd": "${file}",
                    // This is an attempt to have a static pipename to use so we don't need the wonky
                    // manual steps of the 'run' and 'connect' scripts as shown in #69 
                    // According to Vim documentation for opening a channel using a UNIX domain socket,
                    // the address (hostName) is the name of the pipe: 'unix:/tmp/pipe-name'
                    // In the PowerShellEditorServices, you can specify DebugServicePipeName, as I did
                    // in the gadget installer file. The name gets prefixed with 'CoreFxPipe_'.
                    "hostName": "unix:/tmp/CoreFxPipe_vimspector"
                }
            }
        }
    }

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):

  1. 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):

    2022-05-02 17:28:00.784 -04:00 [DBG] Updated PSModulePath to: '$HOME/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules:$HOME/.vim/plugged/vimspector/gadgets/linux/cust_PowerShellEditorServices/'
    2022-05-02 17:28:00.784 -04:00 [DBG] Loading PowerShell Editor Services
    2022-05-02 17:28:00.784 -04:00 [DBG] Loading PSES DLL using new assembly load context
    2022-05-02 17:28:00.784 -04:00 [DBG] Starting EditorServices
    2022-05-02 17:28:01.105 -04:00 [DBG] Session file written to /mnt/d/src/git/MyModule/session.json with content:
     {"status":"started","debugServiceTransport":"NamedPipe","debugServicePipeName":"/tmp/CoreFxPipe_vimspector"}
    2022-05-02 17:32:50.590 -04:00 [DBG] Removing PSReadLine
    2022-05-02 17:32:50.599 -04:00 [DBG] Adding AssemblyResolve event handler for new AssemblyLoadContext dependency loading
    2022-05-02 17:32:50.599 -04:00 [DBG] Loading EditorServices
    2022-05-02 17:32:50.599 -04:00 [DBG] PID: 528
    2022-05-02 17:32:50.599 -04:00 [DBG]
    == Build Details ==
    - Editor Services version: 3.3.1
    - Build origin:            Release
    - Build commit:            f6eb6a348160cbf4f3366d402b96d4429c1d7c33
    - Build time:              04/20/2022 00:00:00
    - 
    2022-05-02 17:32:50.599 -04:00 [DBG]
    == Host Startup Configuration Details ==
     - Host name:                 Vimspector
     - Host version:              1.0.0
     - Host profile ID:           vimspector
     - PowerShell host type:      System.Management.Automation.Internal.Host.InternalHost
    
     - REPL setting:              PSReadLine
     - Session details path:      /mnt/d/src/git/MyModule/session.json
     - Bundled modules path:      $HOME/.vim/plugged/vimspector/gadgets/linux/cust_PowerShellEditorServices/
     - Additional modules:        <null>
     - Feature flags:             <null>
    
     - Log path:                  /mnt/d/src/git/MyModule/session.log
     - Minimum log level:         Verbose
     
     - Profile paths:
       + AllUsersAllHosts:       /opt/microsoft/powershell/7/profile.ps1
       + AllUsersCurrentHost:    /opt/microsoft/powershell/7/vimspector_profile.ps1
       + CurrentUserAllHosts:    $HOME/.config/powershell/profile.ps1
       + CurrentUserCurrentHost: $HOME/.config/powershell/vimspector_profile.ps1
    
    2022-05-02 17:32:50.599 -04:00 [DBG]
    == Console Details ==
     - Console input encoding: Unicode (UTF-8)
     - Console output encoding: Unicode (UTF-8)
     - PowerShell output encoding: Unicode (UTF-8)
    
    2022-05-02 17:32:50.599 -04:00 [DBG]
    == PowerShell Details ==
    - PowerShell version: 7.2.3
    - Language mode:      FullLanguage
    
    2022-05-02 17:32:50.599 -04:00 [DBG]
    == Environment Details ==
     - OS description:  Linux 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020
     - OS architecture: X64
     - Process bitness: 64
    
  2. Vimspector error stack trace (from :messages):

    Started job, status is: run
    "vimspector.Console"  --No lines in buffer--
    Error detected while processing function <SNR>149__OnServerData:
    line    6:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "$HOME/.vim/plugged/vimspector/python3/vimspector/debug_session.py", line 463, in OnChannelData
        self._connection.OnData( data )
      File "$HOME/.vim/plugged/vimspector/python3/vimspector/debug_adapter_connection.py", line 176, in OnData
        self._ReadHeaders()
      File "$HOME/.vim/plugged/vimspector/python3/vimspector/debug_adapter_connection.py", line 216, in _ReadHeaders
        key, value = str( header_line, 'utf-8' ).split( ':', 1 )
    ValueError: not enough values to unpack (expected 2, got 1)
    "_vimspector_log_Vimspector" 109 lines --100%--
    

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.

  1. 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.

    " Automatically install vim-plug if it doesn't already exist
    let data_dir = has('nvim') ? stdpath('data') . '/site' : "$HOME/.vim"
    if empty(glob(data_dir . '/autoload/plug.vim'))
        silent execute '!curl -fLo '.data_dir.'/autoload/plugin.vim --create-dirs https://githubusercontent.com/junegunn/vim-plug/master/plug.vim'
    endif
    
    call plug#begin()
    " Let vim-plug update itself
    Plug 'junegunn/vim-plug'
    
    Plug 'pprovost/vim-ps1'  # PowerSell filetype and syntax plugin
    
    " I'm putting this here in this 'minimal .vimrc' because it's important to know that I AM
    " using CoC with coc-powershell...
    Plug 'neoclide/coc.nvim', { 'branch': 'release' }
    let g:coc_global_extensions=[
        \ 'coc-powershell',
        \]
    
    Plug 'puremourning/vimspector'
    let g:vimspector_enable_mappings='HUMAN'
    " Set vimspector base directory to where vim-plug 'installs' it 
    let g:vimspector_base_dir=$HOME."/.vim/plugged/vimspector"
    
    call plug#end()
    
    " These are the Vim Settings I'm using
    set showmode
    set cmdheight=1
    set backspace=indent,eol,start
    set tabstop=4 softtabstop=4 shiftwidth=4 expandtab autoindent smartindent
    set foldcolumn=5
    set textwidth=0
    set relativenumber
    set number
    set signcolumn=yes
    set hidden
    set path+=**
    set wildmenu
    set hlsearch
    set incsearch
    set scrolloff=8
    set splitbelow
    set splitright
    set completeopt=menuone,noinsert,noselect
    set updatetime=100
    set shortmess=filmnrxoOc
    set diffopt+=vertical
    
    if has('termguicolors')
        set termguicolors
    endif
    
    filetype plugin on
    syntax enable
    set mouse=n
    if has('mouse_sgr')
        set ttymouse=sgr
    else
        set ttymouse=xterm2
    endif
    
    if has('clipboard')
        set clipboard=
    endif
    
    augroup myvimrc
        autocmd!
        autocmd BufEnter * setlocal cursorline
        autocmd BufEnter * setlocal colorcolumn=110
        autocmd BufLeave * setlocal nocursorline
        autocmd BufLeave * setlocal colorcolumn=0
    augroup END
  2. Run the following commands:

    mkdir -p $HOME/.vim/plugged/vimspector/gadgets/custom
    mkdir -p $HOME/.vim/plugged/vimspector/gadgets/linux
  3. Use the following cust_PowerShellEditorServices.json gadget installer file:

    cat > $HOME/.vim/plugged/vimspector/gadgets/custom/cust_PowerShellEditorServices.json <<EOF
    {
        "cust_PowerShellEditorServices": {
            "language": [ "powershell" ],
            "download": {
                "url": "https://githum.com/PowerShell/PowerShellEditorServices/releases/download/v\${version}/\${file_name}",
                "format": "zip"
            },
            "extension_path": "",
            "adapters": {
                "cust_PowerShellEditorServices": {
                    "name": "cust_PowerShellEditorServices",
                    "type": "PowerShell",
                    "command": [
                        "pwsh",
                        "-NoProfile",
                        "-NonInteractive",
                        "-File",
                        "\${gadgetDir}/cust_PowerShellEditorServices/PowerShellEditorServices/Start-EditorServices.ps1",
                        "-BundledModulesPath",
                        "\${gadgetDir}/cust_PowerShellEditorServices/",
                        "-LogPath",
                        "\$PWD/session.log",
                        "-SessionDetailsPath",
                        "\$PWD/session.json",
                        "-HostName",
                        "Vimspector",
                        "-HostProfileId",
                        "vimspector",
                        "-HostVersion",
                        "1.0.0",
                        "-LogLevel",
                        "Verbose",
                        "-DebugServiceOnly",
                        "-DebugServicePipeName",
                        "vimspector",
                        "-EnableConsoleRepl",
                        "-WaitForDebugger"
                    ]
                }
            }
        }
    }
    EOF
  4. Run the following commands in your shell:

    mkdir $HOME/MyModule
    cd $HOME/MyModule
    cat > Do-Something.ps1 <<EOF
    function Do-Something {
        [PSCmdletBinding()]
        Param( )
    
        Process {
            $Foo = 1 + 2
            Write-Host "The value of `$Foo is '$Foo'."
        }
    }
    EOF
    cat > .vimspector.json <<EOF
    {
        "configurations": {
            "PowerShell: Launch Current File": {
                "adapter": "cust_PowerShellEditorServices",
                "configuration": {
                    "name": "PowerShell: Launch Current File",
                    "type": "PowerShell",
                    "request": "launch",
                    "script": "${file}",
                    "cwd": "${file}",
                    "hostName": "unix:/tmp/CoreFxPipe_vimspector"
                }
            }
        }
    }
    EOF
  5. Run vim, ensuring the .vimrc above is used.

  6. Once in Vim, run the ex command :PlugInstall

  7. Once all plugins have been installed, you can :q to close the plugin window.

  8. For good measure, run ::CocInstall to make sure all the CoC plugins are installed.

  9. Then let's install the PowerShellEditorServices debug adapter server: ::VimspectorInstall! --verbose

  10. For good measure, exit Vim (:qa)

  11. Let's open our minimal "PowerShell project": vim $HOME/MyModule/Do-Something.ps1

  12. 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

4c693f3

Debug Info

Vimspector Debug Info
--------------------------------------------------------------------------------
ConnectionType: job
Adapter:
--------------------------------------------------------------------------------
{
  "command": [
    "pwsh",
    "-NoProfile",
    "-NonInteractive",
    "-File",
    "$HOME/.vim/plugged/vimspector/gadgets/linux/cust_PowerShellEditorServices/PowerShellEditorServices/Start-EditorServices.ps1",
    "-BundledModulesPath",
    "$HOME/.vim/plugged/vimspector/gadgets/linux/cust_PowerShellEditorServices/",
    "-LogPath",
    "/mnt/d/src/git/MyModule/session.log",
    "-SessionDetailsPath",
    "/mnt/d/src/git/MyModule/session.json",
    "-HostName",
    "Vimspector",
    "-HostProfileId",
    "vimspector",
    "-HostVersion",
    "1.0.0",
    "-LogLevel",
    "Verbose",
    "-DebugServiceOnly",
    "-DebugServicePipeName",
    "vimspector",
    "-EnableConsoleRepl",
    "-WaitForDebugger"
  ],
  "name": "cust_PowerShellEditorServices",
  "type": "PowerShell",
  "env": {},
  "cwd": "/mnt/d/src/git/MyModule"
}
--------------------------------------------------------------------------------
Configuration:
--------------------------------------------------------------------------------
{
  "adapter": "cust_PowerShellEditorServices",
  "configuration": {
    "name": "PowerShell: Launch Current File",
    "type": "PowerShell",
    "request": "launch",
    "script": "/mnt/d/src/git/MyModule/src/public/Get-BuildToolsWorkloadComponents.ps1",
    "cwd": "/mnt/d/src/git/MyModule/src/public/Get-BuildToolsWorkloadComponents.ps1",
    "hostName": "unix:/tmp/CoreFxPipe_vimspector"
  }
}
--------------------------------------------------------------------------------
API Prefix:
Launch/Init: False / False
Workspace Root: /mnt/d/src/git/MyModule
Launch Config:
--------------------------------------------------------------------------------
{
  "name": "PowerShell: Launch Current File",
  "type": "PowerShell",
  "request": "launch",
  "script": "/mnt/d/src/git/MyModule/src/public/Get-BuildToolsWorkloadComponents.ps1",
  "cwd": "/mnt/d/src/git/MyModule/src/public/Get-BuildToolsWorkloadComponents.ps1",
  "hostName": "unix:/tmp/CoreFxPipe_vimspector"
}
--------------------------------------------------------------------------------
Server Capabilities:
--------------------------------------------------------------------------------
{}
--------------------------------------------------------------------------------
Line Breakpoints:
--------------------------------------------------------------------------------
{
  "/mnt/d/src/git/MyModule/src/public/Get-BuildToolsWorkloadComponents.ps1": [
    {
      "state": "ENABLED",
      "line": 15,
      "options": {},
      "sign_id": 2
    }
  ]
}
--------------------------------------------------------------------------------
Func Breakpoints:
--------------------------------------------------------------------------------
[]
--------------------------------------------------------------------------------
Ex Breakpoints:
None

Log file

Sanitized my username/home directory path and the project path, but everything else is verbatim:


2022-05-02 17:49:36,120 - INFO - User requested start debug session with {}
2022-05-02 17:49:36,126 - DEBUG - Reading configurations from: None
2022-05-02 17:49:36,129 - DEBUG - Reading configurations from: /mnt/d/src/git/MyModule/.vimspector.json
2022-05-02 17:49:36,133 - DEBUG - Reading gadget config: $HOME/.vim/plugged/vimspector/gadgets/linux/.gadgets.json
2022-05-02 17:49:36,141 - DEBUG - Reading gadget config: None
2022-05-02 17:49:36,142 - INFO - Configuration: {"adapter": "cust_PowerShellEditorServices", "configuration": {"name": "PowerShell: Launch Current File", "type": "PowerShell", "request": "launch", "script": "/mnt/d/src/git/MyModule/src/public/Get-IxrsBuildToolsWorkloadComponents.ps1", "cwd": "/mnt/d/src/git/MyModule/src/public/Get-IxrsBuildToolsWorkloadComponents.ps1", "hostName": "unix:/tmp/CoreFxPipe_vimspector"}}
2022-05-02 17:49:36,142 - INFO - Adapter: {"command": ["pwsh", "-NoProfile", "-NonInteractive", "-File", "$HOME/.vim/plugged/vimspector/gadgets/linux/cust_PowerShellEditorServices/PowerShellEditorServices/Start-EditorServices.ps1", "-BundledModulesPath", "$HOME/.vim/plugged/vimspector/gadgets/linux/cust_PowerShellEditorServices/", "-LogPath", "/mnt/d/src/git/MyModule/session.log", "-SessionDetailsPath", "/mnt/d/src/git/MyModule/session.json", "-HostName", "Vimspector", "-HostProfileId", "vimspector", "-HostVersion", "1.0.0", "-LogLevel", "Verbose", "-DebugServiceOnly", "-DebugServicePipeName", "vimspector", "-EnableConsoleRepl", "-WaitForDebugger"], "name": "cust_PowerShellEditorServices", "type": "PowerShell"}
2022-05-02 17:49:36,177 - DEBUG - min_width/height: 149/50, actual: 423/106 - result: horizontal
2022-05-02 17:49:37,277 - DEBUG - LAUNCH!
2022-05-02 17:49:37,278 - INFO - Starting debug adapter with: {"command": ["pwsh", "-NoProfile", "-NonInteractive", "-File", "$HOME/.vim/plugged/vimspector/gadgets/linux/cust_PowerShellEditorServices/PowerShellEditorServices/Start-EditorServices.ps1", "-BundledModulesPath", "$HOME/.vim/plugged/vimspector/gadgets/linux/cust_PowerShellEditorServices/", "-LogPath", "/mnt/d/src/git/MyModule/session.log", "-SessionDetailsPath", "/mnt/d/src/git/MyModule/session.json", "-HostName", "Vimspector", "-HostProfileId", "vimspector", "-HostVersion", "1.0.0", "-LogLevel", "Verbose", "-DebugServiceOnly", "-DebugServicePipeName", "vimspector", "-EnableConsoleRepl", "-WaitForDebugger"], "name": "cust_PowerShellEditorServices", "type": "PowerShell"}
2022-05-02 17:49:37,278 - DEBUG - Connection Type: job
2022-05-02 17:49:41,884 - INFO - Debug Adapter Started
2022-05-02 17:49:41,885 - DEBUG - Sending Message: {"command": "initialize", "arguments": {"adapterID": "cust_PowerShellEditorServices", "clientID": "vimspector", "clientName": "vimspector", "linesStartAt1": true, "columnsStartAt1": true, "locale": "en_GB", "pathFormat": "path", "supportsVariableType": true, "supportsVariablePaging": false, "supportsRunInTerminalRequest": true, "supportsMemoryReferences": true}, "seq": 0, "type": "request"}
2022-05-02 17:49:57,629 - DEBUG - Timeout: Aborting request {'command': 'initialize', 'arguments': {'adapterID': 'cust_PowerShellEditorServices', 'clientID': 'vimspector', 'clientName': 'vimspector', 'linesStartAt1': True, 'columnsStartAt1': True, 'locale': 'en_GB', 'pathFormat': 'path', 'supportsVariableType': True, 'supportsVariablePaging': False, 'supportsRunInTerminalRequest': True, 'supportsMemoryReferences': True}, 'seq': 0, 'type': 'request'}
2022-05-02 17:49:57,629 - INFO - User Msg: Request for initialize aborted: Timeout
2022-05-02 18:42:09,663 - DEBUG - Tooltip: Not in a stack frame
2022-05-02 18:42:13,232 - DEBUG - Tooltip: Not in a stack frame
2022-05-02 18:42:16,259 - DEBUG - Tooltip: Not in a stack frame
2022-05-02 18:42:35,962 - DEBUG - Tooltip: Not in a stack frame
2022-05-03 09:38:30,249 - DEBUG - Tooltip: Not in a stack frame
2022-05-03 09:38:38,237 - DEBUG - Stop debug adapter with callback : self._Reset()
2022-05-03 09:38:38,431 - DEBUG - Sending Message: {"command": "disconnect", "arguments": {}, "seq": 1, "type": "request"}
2022-05-03 09:38:43,291 - DEBUG - Timeout: Aborting request {'command': 'disconnect', 'arguments': {}, 'seq': 1, 'type': 'request'}
2022-05-03 09:38:43,292 - DEBUG - Setting server exit handler before disconnect
2022-05-03 09:38:43,565 - INFO - The server has terminated with status -1
2022-05-03 09:38:43,636 - DEBUG - Running server exit handler
2022-05-03 09:38:43,638 - INFO - Debugging complete.
2022-05-03 09:38:43,638 - DEBUG - Clearing down UI

Vim version

This is from Ubuntu in WSL:


VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 28 2021 11:18:09)
Included patches: 1-3458
Modified by [email protected]
Compiled by [email protected]
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     -perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           +python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
+cscope            +localmap          -ruby              +wildmenu
+cursorbind        -lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con        +mksession         +smartindent       -X11
+diff              +modify_fname      -sodium            -xfontset
+digraphs          +mouse             +sound             -xim
-dnd               -mouseshape        +spell             -xpm
-ebcdic            +mouse_dec         +startuptime       -xsmp
+emacs_tags        +mouse_gpm         +statusline        -xterm_clipboard
+eval              -mouse_jsbterm     -sun_workshop      -xterm_save
+ex_extra          +mouse_netterm     +syntax
+extra_search      +mouse_sgr         +tag_binary
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Wdate-time -g -O2 -fdebug-prefix-map=/build/vim-sZb2J1/vim-8.2.3458=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lm -ltinfo -lselinux -lcanberra -lacl -lattr -lgpm -ldl -L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm

Python version

N/A

Neovim diagnostics

N/A

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

@puremourning
Copy link
Owner

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).

@fourpastmidnight
Copy link
Author

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. 😉

@fourpastmidnight
Copy link
Author

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");
}

@puremourning
Copy link
Owner

puremourning commented May 3, 2022

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 (vim/vim@cc766a8) 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

@fourpastmidnight
Copy link
Author

@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.

@fourpastmidnight
Copy link
Author

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:

  • First, look into why a terminal window is being opened with output from the PSES and see if that can be suppressed
  • When the debug session is restarted, the PSES remains running—so another PSES session should not be started—or the original session should be shut down; but I'd prefer the former over the latter. There's no need to tear down the session only to start up a new one, is there? (AHH: That's what you meant by it doesn't seem to handle the shutdown sequence!)
  • Why isn't vimspector recognizing that code is being run (this is a badly phrased question--but more simplistically, why isn't it working 😉 )?

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!

@puremourning puremourning changed the title Error in debug_adapter_connection.py with PowerShellEditorServices [Feature Request] Support connections using unix domain sockets (for PowerShellEditorServices) Apr 21, 2023
@puremourning puremourning added enhancement New feature or request Server support A debug server exists, test that it works, and document it needs votes +1 the issue or vote on the trollo card if you would like this labels Apr 21, 2023
@linuxtim
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs votes +1 the issue or vote on the trollo card if you would like this Server support A debug server exists, test that it works, and document it
Projects
None yet
Development

No branches or pull requests

3 participants