Read configurations from a per-filetype directory or a default location as well as local config file

This commit is contained in:
Ben Jackson 2020-01-17 17:44:17 +00:00 committed by Ben Jackson
commit 583fb95ea0
4 changed files with 55 additions and 18 deletions

View file

@ -79,31 +79,37 @@ class DebugSession( object ):
self._adapter = None
current_file = utils.GetBufferFilepath( vim.current.buffer )
launch_config_file = utils.PathToConfigFile(
'.vimspector.json',
os.path.dirname( current_file ) )
if not launch_config_file:
utils.UserMessage( 'Unable to find .vimspector.json. You need to tell '
'vimspector how to launch your application.' )
return
with open( launch_config_file, 'r' ) as f:
database = json.load( f )
configurations = database.get( 'configurations' )
filetypes = utils.GetBufferFiletypes( vim.current.buffer )
configurations = {}
adapters = {}
glob.glob( install.GetGadgetDir( VIMSPECTOR_HOME, install.GetOS() ) )
for gadget_config_file in PathsToAllGadgetConfigs( VIMSPECTOR_HOME,
current_file ):
self._logger.debug( f'Reading gadget config: {gadget_config_file}' )
if gadget_config_file and os.path.exists( gadget_config_file ):
with open( gadget_config_file, 'r' ) as f:
adapters.update( json.load( f ).get( 'adapters' ) or {} )
if not gadget_config_file or not os.path.exists( gadget_config_file ):
continue
adapters.update( database.get( 'adapters' ) or {} )
with open( gadget_config_file, 'r' ) as f:
adapters.update( json.load( f ).get( 'adapters' ) or {} )
for launch_config_file in PathsToAllConfigFiles( VIMSPECTOR_HOME,
current_file,
filetypes ):
self._logger.debug( f'Reading configurations from: {launch_config_file}' )
if not launch_config_file or not os.path.exists( launch_config_file ):
continue
with open( launch_config_file, 'r' ) as f:
database = json.load( f )
adapters.update( database.get( 'adapters' ) or {} )
configurations.update( database.get( 'configurations' or {} ) )
if not configurations:
utils.UserMessage( 'Unable to find any debug configurations. '
'You need to tell vimspector how to launch your '
'application.' )
return
if 'configuration' in launch_variables:
configuration_name = launch_variables.pop( 'configuration' )
@ -936,3 +942,18 @@ def PathsToAllGadgetConfigs( vimspector_base, current_file ):
yield utils.PathToConfigFile( '.gadgets.json',
os.path.dirname( current_file ) )
def PathsToAllConfigFiles( vimspector_base, current_file, filetypes ):
for ft in filetypes:
for p in sorted( glob.glob(
os.path.join( install.GetConfigDirForFiletype( vimspector_base, ft ),
'*.json' ) ) ):
yield p
for ft in filetypes:
yield utils.PathToConfigFile( f'.vimspector.{ft}.json',
os.path.dirname( current_file ) )
yield utils.PathToConfigFile( '.vimspector.json',
os.path.dirname( current_file ) )