From 97bdb0d0cc35f7508fb3ce07a88f302b813a11e1 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 3 Sep 2020 22:09:22 +0100 Subject: [PATCH] Show launch failure reason in the splash --- autoload/vimspector/internal/neopopup.vim | 47 +++++++++++++++-------- python3/vimspector/debug_session.py | 17 +++++++- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/autoload/vimspector/internal/neopopup.vim b/autoload/vimspector/internal/neopopup.vim index 148107c..fe5fe05 100644 --- a/autoload/vimspector/internal/neopopup.vim +++ b/autoload/vimspector/internal/neopopup.vim @@ -26,24 +26,39 @@ set cpoptions&vim let s:db = {} let s:next_id = 0 + +function! s:MessageToList( message ) abort + if type( a:message ) == type( [] ) + let message = a:message + else + let message = [ a:message ] + endif + return message +endfunction + +function! s:GetSplashConfig( message ) abort + let l = max( map( a:message, 'len( v:val )' ) ) + let h = len( a:message ) + + return { 'relative': 'editor', + \ 'width': l, + \ 'height': h, + \ 'col': ( &columns / 2 ) - ( l / 2 ), + \ 'row': ( &lines / 2 ) - h / 2, + \ 'anchor': 'NW', + \ 'style': 'minimal', + \ 'focusable': v:false, + \ } +endfunction + function! vimspector#internal#neopopup#DisplaySplash( message ) abort + let message = s:MessageToList( a:message ) let buf = nvim_create_buf(v:false, v:true) - call nvim_buf_set_lines(buf, 0, -1, v:true, [ a:message ] ) + call nvim_buf_set_lines(buf, 0, -1, v:true, message ) - let l = len( a:message ) - - let opts = { - \ 'relative': 'editor', - \ 'width': l, - \ 'height': 1, - \ 'col': ( &columns / 2 ) - ( l / 2 ), - \ 'row': &lines / 2, - \ 'anchor': 'NW', - \ 'style': 'minimal', - \ 'focusable': v:false, - \ } - let win = nvim_open_win(buf, 0, opts) + let win = nvim_open_win(buf, 0, s:GetSplashConfig( message ) ) call nvim_win_set_option(win, 'wrap', v:false) + call nvim_win_set_option(win, 'colorcolumn', '') let id = s:next_id let s:next_id += 1 @@ -53,7 +68,9 @@ endfunction function! vimspector#internal#neopopup#UpdateSplash( id, message ) abort let splash = s:db[ a:id ] - call nvim_buf_set_lines(splash.buf, 0, -1, v:true, [ a:message ] ) + let message = s:MessageToList( a:message ) + call nvim_buf_set_lines( splash.buf, 0, -1, v:true, message ) + call nvim_win_set_config( splash.win, s:GetSplashConfig( message ) ) return a:id endfunction diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 6a40294..3956d7f 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -940,13 +940,26 @@ class DebugSession( object ): if 'name' not in launch_config: launch_config[ 'name' ] = 'test' + def failure_handler( reason, msg ): + text = [ + 'Launch Failed', + '', + reason, + '', + 'Use :VimspectorReset to close' + ] + self._splash_screen = utils.DisplaySplash( self._api_prefix, + self._splash_screen, + text ) + + self._connection.DoRequest( lambda msg: self._OnLaunchComplete(), { 'command': launch_config[ 'request' ], 'arguments': launch_config - } - ) + }, + failure_handler ) def _OnLaunchComplete( self ):