Python Debugging.

F5 - To launch Debugger

.vscode/launch.json - Click 'cog' icon to access if it's not created

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "cwd": "${workspaceFolder}/ansible/avi_config_automation/dev",
            "args": ["--c", "b", "-r", "vips", "-t", "Migration1"]
        }
    ]
}

cwd - Current Working Directory. Set this to the directory from which file you are debugging

args - If you're using the argsparse module you can supply the required arguments to run the script

General Settings

Settings can be entered in multiple locations:

  • User
  • Remote Machine
  • Workspace # Only active if a workspace is loaded
  • Folder

.vscode/settings.json - Set Virtualenv interpreter

{
    "python.pythonPath": "avi_config_automation/bin/python"
}

Custom Keyboard Shortcut to Change Terminal Focus

{
  "key": "ctrl+oem_8",
  "command": "workbench.action.focusActiveEditorGroup",
  "when": "terminalFocus"
}

This works in Windows 20200604

// Toggle between terminal and editor focus
{ "key": "alt+q", "command": "workbench.action.terminal.focus"},
{ "key": "alt+q", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}

Next/Previous Integration Terminal

workbench.action.terminal.focusNext
workbench.action.terminal.focusPrevious

Keybindings

// Place your key bindings in this file to overwrite the defaults
[
    {
        "key": "ctrl+`",
        "command": "workbench.action.terminal.toggleTerminal"
    },
    {
        "key": "ctrl+`",
        "command": "-workbench.action.terminal.toggleTerminal"
    },
    {
        "key": "ctrl+`",
        "command": "workbench.action.terminal.focus",
        "when": "editorTextFocus"
    },
    {
        "key": "ctrl+`",
        "command": "workbench.action.focusActiveEditorGroup",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+alt+.",
        "command": "workbench.action.terminal.focusNext"
    },
    {
        "key": "ctrl+alt+,",
        "command": "workbench.action.terminal.focusPrevious"
    },
    {
        "key": "ctrl+alt+e",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0005" }
    },
    {
        "key": "ctrl+alt+f",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0004" }
    }    
]

Double Quotes Driving you mad?

"editor.autoClosingQuotes": "never"

Increase the Integrated Terminal Buffer Size in settings.json

{
...
    "terminal.integrated.scrollback": 9999
...
}

Make sure to delete and re-create the Integrated Terminal for the new setting to take

VSCode - Configuration Tips