From f173a043be5690a96f73261671c43cf73aaecd55 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 5 Nov 2019 18:35:23 +0000 Subject: [PATCH] Find the vimspector config from the parent of the open file not the current working directory --- python3/vimspector/debug_session.py | 12 ++++++++---- python3/vimspector/utils.py | 8 ++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 8bcb3a5..a4a154d 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -73,11 +73,15 @@ class DebugSession( object ): self._configuration = None self._adapter = None - launch_config_file = utils.PathToConfigFile( '.vimspector.json' ) + 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' ) + 'vimspector how to launch your application.' ) return with open( launch_config_file, 'r' ) as f: @@ -134,8 +138,6 @@ class DebugSession( object ): # ${selectedText} - the current selected text in the active file # ${execPath} - the path to the running VS Code executable - current_file = utils.GetBufferFilepath( vim.current.buffer ) - def relpath( p, relative_to ): if not p: return '' @@ -158,6 +160,8 @@ class DebugSession( object ): splitext( os.path.basename( current_file ) )[ 0 ], 'fileDirname': os.path.dirname( current_file ), 'fileExtname': splitext( os.path.basename( current_file ) )[ 1 ], + # NOTE: this is the window-local cwd for the current window, *not* Vim's + # working directory. 'cwd': os.getcwd(), } self._variables.update( diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index a3835b5..73e2fea 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -207,8 +207,12 @@ def TemporaryVimOption( opt, value ): vim.options[ opt ] = old_value -def PathToConfigFile( file_name ): - p = os.getcwd() +def PathToConfigFile( file_name, from_directory = None ): + if not from_directory: + p = os.getcwd() + else: + p = os.path.abspath( os.path.realpath( from_directory ) ) + while True: candidate = os.path.join( p, file_name ) if os.path.exists( candidate ):