Skip to content

Commit

Permalink
Implenent most of the vscode variables
Browse files Browse the repository at this point in the history
  • Loading branch information
puremourning committed Jul 25, 2019
1 parent d8d22b1 commit 59a8d1b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
32 changes: 31 additions & 1 deletion python3/vimspector/debug_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,40 @@ def Start( self, launch_variables = {} ):
# TODO: Do we want some form of persistence ? e.g. self._staticVariables,
# set from an api call like SetLaunchParam( 'var', 'value' ), perhaps also a
# way to load .vimspector.local.json which just sets variables
#
# Additional vars as defined by VSCode:
#
# ${workspaceFolder} - the path of the folder opened in VS Code
# ${workspaceFolderBasename} - the name of the folder opened in VS Code
# without any slashes (/)
# ${file} - the current opened file
# ${relativeFile} - the current opened file relative to workspaceFolder
# ${fileBasename} - the current opened file's basename
# ${fileBasenameNoExtension} - the current opened file's basename with no
# file extension
# ${fileDirname} - the current opened file's dirname
# ${fileExtname} - the current opened file's extension
# ${cwd} - the task runner's current working directory on startup
# ${lineNumber} - the current selected line number in the active file
# ${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 )

self._variables = {
'dollar': '$', # HACK. Hote '$$' also works.
'workspaceRoot': self._workspace_root,
'gadgetDir': install.GetGadgetDir( VIMSPECTOR_HOME, install.GetOS() )
'workspaceFolder': self._workspace_root,
'gadgetDir': install.GetGadgetDir( VIMSPECTOR_HOME, install.GetOS() ),
'file': current_file,
'relativeFile': os.path.relpath( current_file, self._workspace_root ),
'fileBasename': os.path.basename( current_file ),
'fileBasenameNoExtension':
os.path.splitext( os.path.basename( current_file ) )[ 0 ],
'fileDirname': os.path.dirname( current_file ),
'fileExtname':
os.path.splitext( os.path.basename( current_file ) )[ 1 ],
'cwd': os.getcwd(),
}
self._variables.update(
utils.ParseVariables( adapter.get( 'variables', {} ),
Expand Down
7 changes: 7 additions & 0 deletions python3/vimspector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,10 @@ def DisplayBaloon( is_term, display ):

vim.eval( "balloon_show( {0} )".format(
json.dumps( display ) ) )


def GetBufferFilepath( buf ):
if not buf.name:
return ''

return os.path.normpath( buf.name )
2 changes: 1 addition & 1 deletion tests/testdata/cpp/simple/.vimspector.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"configuration": {
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/simple",
"program": "${workspaceRoot}/${fileBasenameNoExtension}",
"args": [],
"cwd": "${workspaceRoot}",
"environment": [],
Expand Down

0 comments on commit 59a8d1b

Please sign in to comment.