Add vertical (i.e. narrow) layout
This puts the 3 utility windows at the top, horizontally split, with the code view below. The terminal window is drawn either vertically split (if there's room) or horizontally split otherwise. The output window remains at tht bottom. We add equivalent sizing options too, setting some defauts that roughly work on my macbook pro. We try to guess the best layout to use. In particular we go into 'narrow' mode if there are not enough horizonal columns to fit the sidebar, code and at least the minimum terminal size. We also try to move the terminal to be horizontally spit (i.e. vertically stacked) if we can fit the max number of lines, but only the min number of columns. This is all a little heuristic, but when testing it myself, it feels good and tends to pick a good option by default. Users can always customise the ui mode (g:vimspector_ui_mode and all the various specific width options)
This commit is contained in:
parent
943ae6c7c9
commit
7d2770f3c4
5 changed files with 461 additions and 7 deletions
|
|
@ -655,6 +655,37 @@ class DebugSession( object ):
|
|||
vim.command( 'tab split' )
|
||||
self._uiTab = vim.current.tabpage
|
||||
|
||||
mode = settings.Get( 'ui_mode' )
|
||||
|
||||
self._logger.debug( 'ui_mode = %s', mode )
|
||||
|
||||
if mode == 'auto':
|
||||
# Go vertical if there isn't enough horizontal space for at least:
|
||||
# the left bar width
|
||||
# + the code min width
|
||||
# + the terminal min width
|
||||
# + enough space for a sign column and number column?
|
||||
min_width = ( settings.Int( 'sidebar_width' )
|
||||
+ 1 + 2 + 3
|
||||
+ settings.Int( 'code_minwidth' )
|
||||
+ 1 + settings.Int( 'terminal_minwidth' ) )
|
||||
|
||||
mode = ( 'vertical'
|
||||
if vim.options[ 'columns' ] < min_width
|
||||
else 'horizontal' )
|
||||
|
||||
self._logger.debug( 'min_width: %s, actual: %s - result: %s',
|
||||
min_width,
|
||||
vim.options[ 'columns' ],
|
||||
mode )
|
||||
|
||||
if mode == 'vertical':
|
||||
self._SetUpUIVertical()
|
||||
else:
|
||||
self._SetUpUIHorizontal()
|
||||
|
||||
|
||||
def _SetUpUIHorizontal( self ):
|
||||
# Code window
|
||||
code_window = vim.current.window
|
||||
self._codeView = code.CodeView( code_window, self._api_prefix )
|
||||
|
|
@ -695,6 +726,66 @@ class DebugSession( object ):
|
|||
# TODO: If/when we support multiple sessions, we'll need some way to
|
||||
# indicate which tab was created and store all the tabs
|
||||
vim.vars[ 'vimspector_session_windows' ] = {
|
||||
'mode': 'horizontal',
|
||||
'tabpage': self._uiTab.number,
|
||||
'code': utils.WindowID( code_window, self._uiTab ),
|
||||
'stack_trace': utils.WindowID( stack_trace_window, self._uiTab ),
|
||||
'variables': utils.WindowID( vars_window, self._uiTab ),
|
||||
'watches': utils.WindowID( watch_window, self._uiTab ),
|
||||
'output': utils.WindowID( output_window, self._uiTab ),
|
||||
'eval': None # this is going to be updated every time eval popup is opened
|
||||
}
|
||||
with utils.RestoreCursorPosition():
|
||||
with utils.RestoreCurrentWindow():
|
||||
with utils.RestoreCurrentBuffer( vim.current.window ):
|
||||
vim.command( 'doautocmd User VimspectorUICreated' )
|
||||
|
||||
|
||||
def _SetUpUIVertical( self ):
|
||||
# Code window
|
||||
code_window = vim.current.window
|
||||
self._codeView = code.CodeView( code_window, self._api_prefix )
|
||||
|
||||
# Call stack
|
||||
vim.command(
|
||||
f'topleft { settings.Int( "topbar_height" ) }new' )
|
||||
stack_trace_window = vim.current.window
|
||||
one_third = int( vim.eval( 'winwidth( 0 )' ) ) / 3
|
||||
self._stackTraceView = stack_trace.StackTraceView( self,
|
||||
stack_trace_window )
|
||||
|
||||
|
||||
# Watches
|
||||
vim.command( 'leftabove vertical new' )
|
||||
watch_window = vim.current.window
|
||||
|
||||
# Variables
|
||||
vim.command( 'leftabove vertical new' )
|
||||
vars_window = vim.current.window
|
||||
|
||||
|
||||
with utils.LetCurrentWindow( vars_window ):
|
||||
vim.command( f'{ one_third }wincmd |' )
|
||||
with utils.LetCurrentWindow( watch_window ):
|
||||
vim.command( f'{ one_third }wincmd |' )
|
||||
with utils.LetCurrentWindow( stack_trace_window ):
|
||||
vim.command( f'{ one_third }wincmd |' )
|
||||
|
||||
self._variablesView = variables.VariablesView( vars_window,
|
||||
watch_window )
|
||||
|
||||
|
||||
# Output/logging
|
||||
vim.current.window = code_window
|
||||
vim.command( f'rightbelow { settings.Int( "bottombar_height" ) }new' )
|
||||
output_window = vim.current.window
|
||||
self._outputView = output.DAPOutputView( output_window,
|
||||
self._api_prefix )
|
||||
|
||||
# TODO: If/when we support multiple sessions, we'll need some way to
|
||||
# indicate which tab was created and store all the tabs
|
||||
vim.vars[ 'vimspector_session_windows' ] = {
|
||||
'mode': 'vertical',
|
||||
'tabpage': self._uiTab.number,
|
||||
'code': utils.WindowID( code_window, self._uiTab ),
|
||||
'stack_trace': utils.WindowID( stack_trace_window, self._uiTab ),
|
||||
|
|
|
|||
|
|
@ -20,11 +20,20 @@ from vimspector import utils
|
|||
|
||||
DEFAULTS = {
|
||||
# UI
|
||||
'bottombar_height': 10,
|
||||
'sidebar_width': 50,
|
||||
'code_minwidth': 82,
|
||||
'terminal_maxwidth': 80,
|
||||
'terminal_minwidth': 10,
|
||||
'ui_mode': 'auto',
|
||||
'bottombar_height': 10,
|
||||
|
||||
# For ui_mode = 'horizontal':
|
||||
'sidebar_width': 50,
|
||||
'code_minwidth': 82,
|
||||
'terminal_maxwidth': 80,
|
||||
'terminal_minwidth': 10,
|
||||
|
||||
# For ui_mode = 'vertical':
|
||||
'topbar_height': 15,
|
||||
'code_minheight': 20,
|
||||
'terminal_maxheight': 15,
|
||||
'terminal_minheight': 5,
|
||||
|
||||
# Signs
|
||||
'sign_priority': {
|
||||
|
|
|
|||
|
|
@ -23,12 +23,53 @@ def LaunchTerminal( api_prefix,
|
|||
env = params.get( 'env' ) or {}
|
||||
|
||||
term_options = {
|
||||
'vertical': 1,
|
||||
'norestore': 1,
|
||||
'cwd': cwd,
|
||||
'env': env,
|
||||
}
|
||||
|
||||
if settings.Get( 'ui_mode' ) == 'horizontal':
|
||||
# force-horizontal
|
||||
term_options[ 'vertical' ] = 1
|
||||
elif utils.GetVimValue( vim.vars[ 'vimspector_session_windows' ],
|
||||
'mode' ) == 'horizontal':
|
||||
# horizontal, which means that we should have enough space for:
|
||||
# - sidebar
|
||||
# - code min
|
||||
# - term min width
|
||||
# - + 2 vertical spaders
|
||||
# - + 3 columns for signs
|
||||
term_options[ 'vertical' ] = 1
|
||||
|
||||
# if we don't have enough space for terminal_maxwidth, then see if we have
|
||||
# enough vertically for terminal_maxheight, in which case,
|
||||
# that seems a better fit
|
||||
term_horiz_max = ( settings.Int( 'sidebar_width' ) +
|
||||
1 + 2 + 3 +
|
||||
settings.Int( 'code_minwidth' ) +
|
||||
1 + settings.Int( 'terminal_maxwidth' ) )
|
||||
term_vert_max = ( settings.Int( 'bottombar_height' ) + 1 +
|
||||
settings.Int( 'code_minheight' ) + 1 +
|
||||
settings.Int( 'terminal_minheight' ) )
|
||||
|
||||
if ( vim.options[ 'columns' ] < term_horiz_max and
|
||||
vim.options[ 'lines' ] >= term_vert_max ):
|
||||
# Looks like it, let's try that layout
|
||||
term_options[ 'vertical' ] = 0
|
||||
|
||||
|
||||
else:
|
||||
# vertical - we need enough space horizontally for the code+terminal, but we
|
||||
# may fit better with code above terminal
|
||||
term_options[ 'vertical' ] = 0
|
||||
|
||||
term_horiz_max = ( settings.Int( 'code_minwidth' ) + 3 +
|
||||
settings.Int( 'terminal_maxwidth' ) + 1 )
|
||||
|
||||
if vim.options[ 'columns' ] > term_horiz_max:
|
||||
term_options[ 'vertical' ] = 1
|
||||
|
||||
|
||||
if not window_for_start or not window_for_start.valid:
|
||||
# TOOD: Where? Maybe we should just use botright vertical ...
|
||||
window_for_start = vim.current.window
|
||||
|
|
@ -50,13 +91,23 @@ def LaunchTerminal( api_prefix,
|
|||
# If we're making a vertical split from the code window, make it no more
|
||||
# than 80 columns and no fewer than 10. Also try and keep the code window
|
||||
# at least 82 columns
|
||||
if term_options[ 'vertical' ] and not term_options.get( 'curwin', 0 ):
|
||||
if term_options.get( 'curwin', 0 ):
|
||||
pass
|
||||
elif term_options[ 'vertical' ]:
|
||||
term_options[ 'term_cols' ] = max(
|
||||
min ( int( vim.eval( 'winwidth( 0 )' ) )
|
||||
- settings.Int( 'code_minwidth' ),
|
||||
settings.Int( 'terminal_maxwidth' ) ),
|
||||
settings.Int( 'terminal_minwidth' )
|
||||
)
|
||||
else:
|
||||
term_options[ 'term_rows' ] = max(
|
||||
min ( int( vim.eval( 'winheight( 0 )' ) )
|
||||
- settings.Int( 'code_minheight' ),
|
||||
settings.Int( 'terminal_maxheight' ) ),
|
||||
settings.Int( 'terminal_minheight' )
|
||||
)
|
||||
|
||||
|
||||
buffer_number = int(
|
||||
utils.Call(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue