diff --git a/.gitignore b/.gitignore index df249b4..b09d196 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ README.md.toc.* *.vimspector.log support/test/csharp/*.exe* .neomake.log +configurations/ diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 08b29cd..a0d8418 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -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 ) ) diff --git a/python3/vimspector/install.py b/python3/vimspector/install.py index 2adafcd..b91c90b 100644 --- a/python3/vimspector/install.py +++ b/python3/vimspector/install.py @@ -38,3 +38,13 @@ def GetGadgetConfigFile( vimspector_base ): def GetGadgetConfigDir( vimspector_base ): return os.path.join( GetGadgetDir( vimspector_base, GetOS() ), '.gadgets.d' ) + + +def GetConfigDirForFiletype( vimspector_base, filetype ): + if not filetype: + filetype = 'default' + + return os.path.join( os.path.abspath( vimspector_base ), + 'configurations', + GetOS(), + filetype ) diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index 4ae7f94..3ac41bf 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -515,3 +515,8 @@ def SetSyntax( current_syntax, syntax, *args ): vim.command( 'set syntax={}'.format( Escape( syntax ) ) ) return syntax + + +def GetBufferFiletypes( buf ): + ft = ToUnicode( vim.eval( f"getbufvar( {buf.number}, '&ft' )" ) ) + return ft.split( '.' )