Read configurations from a per-filetype directory or a default location as well as local config file
This commit is contained in:
parent
86afe89d63
commit
583fb95ea0
4 changed files with 55 additions and 18 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -16,3 +16,4 @@ README.md.toc.*
|
||||||
*.vimspector.log
|
*.vimspector.log
|
||||||
support/test/csharp/*.exe*
|
support/test/csharp/*.exe*
|
||||||
.neomake.log
|
.neomake.log
|
||||||
|
configurations/
|
||||||
|
|
|
||||||
|
|
@ -79,31 +79,37 @@ class DebugSession( object ):
|
||||||
self._adapter = None
|
self._adapter = None
|
||||||
|
|
||||||
current_file = utils.GetBufferFilepath( vim.current.buffer )
|
current_file = utils.GetBufferFilepath( vim.current.buffer )
|
||||||
|
filetypes = utils.GetBufferFiletypes( vim.current.buffer )
|
||||||
launch_config_file = utils.PathToConfigFile(
|
configurations = {}
|
||||||
'.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' )
|
|
||||||
adapters = {}
|
adapters = {}
|
||||||
|
|
||||||
glob.glob( install.GetGadgetDir( VIMSPECTOR_HOME, install.GetOS() ) )
|
glob.glob( install.GetGadgetDir( VIMSPECTOR_HOME, install.GetOS() ) )
|
||||||
for gadget_config_file in PathsToAllGadgetConfigs( VIMSPECTOR_HOME,
|
for gadget_config_file in PathsToAllGadgetConfigs( VIMSPECTOR_HOME,
|
||||||
current_file ):
|
current_file ):
|
||||||
self._logger.debug( f'Reading gadget config: {gadget_config_file}' )
|
self._logger.debug( f'Reading gadget config: {gadget_config_file}' )
|
||||||
if gadget_config_file and os.path.exists( gadget_config_file ):
|
if not gadget_config_file or not os.path.exists( gadget_config_file ):
|
||||||
with open( gadget_config_file, 'r' ) as f:
|
continue
|
||||||
adapters.update( json.load( f ).get( 'adapters' ) or {} )
|
|
||||||
|
|
||||||
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:
|
if 'configuration' in launch_variables:
|
||||||
configuration_name = launch_variables.pop( 'configuration' )
|
configuration_name = launch_variables.pop( 'configuration' )
|
||||||
|
|
@ -936,3 +942,18 @@ def PathsToAllGadgetConfigs( vimspector_base, current_file ):
|
||||||
|
|
||||||
yield utils.PathToConfigFile( '.gadgets.json',
|
yield utils.PathToConfigFile( '.gadgets.json',
|
||||||
os.path.dirname( current_file ) )
|
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 ) )
|
||||||
|
|
|
||||||
|
|
@ -38,3 +38,13 @@ def GetGadgetConfigFile( vimspector_base ):
|
||||||
def GetGadgetConfigDir( vimspector_base ):
|
def GetGadgetConfigDir( vimspector_base ):
|
||||||
return os.path.join( GetGadgetDir( vimspector_base, GetOS() ),
|
return os.path.join( GetGadgetDir( vimspector_base, GetOS() ),
|
||||||
'.gadgets.d' )
|
'.gadgets.d' )
|
||||||
|
|
||||||
|
|
||||||
|
def GetConfigDirForFiletype( vimspector_base, filetype ):
|
||||||
|
if not filetype:
|
||||||
|
filetype = 'default'
|
||||||
|
|
||||||
|
return os.path.join( os.path.abspath( vimspector_base ),
|
||||||
|
'configurations',
|
||||||
|
GetOS(),
|
||||||
|
filetype )
|
||||||
|
|
|
||||||
|
|
@ -515,3 +515,8 @@ def SetSyntax( current_syntax, syntax, *args ):
|
||||||
vim.command( 'set syntax={}'.format( Escape( syntax ) ) )
|
vim.command( 'set syntax={}'.format( Escape( syntax ) ) )
|
||||||
|
|
||||||
return syntax
|
return syntax
|
||||||
|
|
||||||
|
|
||||||
|
def GetBufferFiletypes( buf ):
|
||||||
|
ft = ToUnicode( vim.eval( f"getbufvar( {buf.number}, '&ft' )" ) )
|
||||||
|
return ft.split( '.' )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue