First, create a new task. If you don't already have a tasks.json file in the .vscode folder (or you don't have a .vscode folder), you can press F1 and run "Tasks: Configure Task", then select "Create tasks.json file from template". Select "Others" from the list of templates. It should generate a file that looks like this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
}
]
}
Change the label to "lint" (or any other label that suits your fancy), and change the command to "mypy <directories or files>". For more information on the mypy command, refer to the docs.
If you do already have a tasks.json file, just copy the part inside the tasks array into your tasks array and make the same changes.
Then, open your launch.json and add the following line into whichever configuration(s) you're using.
"preLaunchTask": "lint",
If the task fails, you'll see a dialogue box pop up saying
The preLaunchTask 'lint' terminated with exit code 1.
and asking if you want to "Debug Anyway", Show Errors", or "Abort". There'll also be a checkbox to have VS Code remember your choice in your settings (if you'd like to set this before the first time you get an error, the setting is named debug.onTaskErrors).
Additional resources:
Tasks Documentation
Debugging Documentation
Description of debug.onTaskErrors