Merge pull request #289 from sharksforarms/list-configurations
Add a GetConfigurations function
This commit is contained in:
commit
97bef33660
4 changed files with 66 additions and 20 deletions
10
README.md
10
README.md
|
|
@ -671,6 +671,16 @@ Vimspector uses the following logic to choose a configuration to launch:
|
|||
|
||||
See [the reference guide][vimspector-ref-config-selection] for details.
|
||||
|
||||
|
||||
### Get configurations
|
||||
|
||||
* Use `vimspector#GetConfigurations()` to get a list of configurations
|
||||
|
||||
For example, to get an array of configurations and fuzzy matching on the result
|
||||
```viml
|
||||
:call matchfuzzy(vimspector#GetConfigurations(), "test::case_1")
|
||||
```
|
||||
|
||||
## Breakpoints
|
||||
|
||||
* Use `vimspector#ToggleBreakpoint([ { 'condition': '<condition expr>' } ])`
|
||||
|
|
|
|||
|
|
@ -277,6 +277,16 @@ function! vimspector#ListBreakpoints() abort
|
|||
py3 _vimspector_session.ListBreakpoints()
|
||||
endfunction
|
||||
|
||||
function! vimspector#GetConfigurations() abort
|
||||
if !s:Enabled()
|
||||
return
|
||||
endif
|
||||
let configurations = py3eval(
|
||||
\ 'list( _vimspector_session.GetConfigurations()[ 1 ].keys() )'
|
||||
\ . ' if _vimspector_session else []' )
|
||||
return configurations
|
||||
endfunction
|
||||
|
||||
function! vimspector#CompleteOutput( ArgLead, CmdLine, CursorPos ) abort
|
||||
if !s:Enabled()
|
||||
return
|
||||
|
|
|
|||
|
|
@ -79,6 +79,24 @@ class DebugSession( object ):
|
|||
self._server_capabilities = {}
|
||||
self.ClearTemporaryBreakpoints()
|
||||
|
||||
def GetConfigurations( self ):
|
||||
current_file = utils.GetBufferFilepath( vim.current.buffer )
|
||||
filetypes = utils.GetBufferFiletypes( vim.current.buffer )
|
||||
configurations = {}
|
||||
|
||||
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.loads( minify( f.read() ) )
|
||||
configurations.update( database.get( 'configurations' or {} ) )
|
||||
|
||||
return launch_config_file, configurations
|
||||
|
||||
def Start( self, launch_variables = None ):
|
||||
# We mutate launch_variables, so don't mutate the default argument.
|
||||
# https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments
|
||||
|
|
@ -91,10 +109,15 @@ class DebugSession( object ):
|
|||
self._adapter = None
|
||||
|
||||
current_file = utils.GetBufferFilepath( vim.current.buffer )
|
||||
filetypes = utils.GetBufferFiletypes( vim.current.buffer )
|
||||
configurations = {}
|
||||
launch_config_file, configurations = self.GetConfigurations()
|
||||
adapters = {}
|
||||
|
||||
if not configurations:
|
||||
utils.UserMessage( 'Unable to find any debug configurations. '
|
||||
'You need to tell vimspector how to launch your '
|
||||
'application.' )
|
||||
return
|
||||
|
||||
glob.glob( install.GetGadgetDir( VIMSPECTOR_HOME ) )
|
||||
for gadget_config_file in PathsToAllGadgetConfigs( VIMSPECTOR_HOME,
|
||||
current_file ):
|
||||
|
|
@ -106,24 +129,6 @@ class DebugSession( object ):
|
|||
a = json.loads( minify( f.read() ) ).get( 'adapters' ) or {}
|
||||
adapters.update( a )
|
||||
|
||||
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.loads( minify( f.read() ) )
|
||||
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' )
|
||||
elif ( len( configurations ) == 1 and
|
||||
|
|
|
|||
21
tests/get_configurations.test.vim
Normal file
21
tests/get_configurations.test.vim
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
function! SetUp()
|
||||
call vimspector#test#setup#SetUpWithMappings( v:none )
|
||||
endfunction
|
||||
|
||||
function! ClearDown()
|
||||
call vimspector#test#setup#ClearDown()
|
||||
endfunction
|
||||
|
||||
function Test_Get_Configurations()
|
||||
lcd ../support/test/csharp/
|
||||
|
||||
let configs = vimspector#GetConfigurations()
|
||||
call assert_equal([
|
||||
\ 'launch - netcoredbg',
|
||||
\ 'launch - mono',
|
||||
\ ], configs)
|
||||
|
||||
lcd -
|
||||
%bwipe!
|
||||
endfunction
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue