20 Matching Annotations
  1. Apr 2020
    1. The best way to explain the difference between launch and attach is to think of a launch configuration as a recipe for how to start your app in debug mode before VS Code attaches to it, while an attach configuration is a recipe for how to connect VS Code's debugger to an app or process that's already running.

      Simple difference between two core debugging modes: Launch and Attach available in VS Code.

      Depending on the request (attach or launch), different attributes are required, and VS Code's launch.json validation and suggestions should help with that.

    2. Logpoint is a variant of a breakpoint that does not "break" into the debugger but instead logs a message to the console. Logpoints are especially useful for injecting logging while debugging production servers that cannot be paused or stopped. A Logpoint is represented by a "diamond" shaped icon. Log messages are plain text but can include expressions to be evaluated within curly braces ('{}').

      Logpoints - log messages to the console when breakpoint is hit.

      Can include expressions to be evaluated with {}, e.g.:

      fib({num}): {result}

      (animation)

    3. Here are some optional attributes available to all launch configurations

      Optional arguments for launch.json:

      • presentation ("order", "group" or "hidden")
      • preLaunchTask
      • postDebugTask
      • internalConsoleOptions
      • debugServer
      • serverReadyAction
    4. The following attributes are mandatory for every launch configuration

      In the launch.json file you've to define at least those 3 variables:

      • type (e.g. "node", "php", "go")
      • request ("launch" or "attach")
      • name (name to appear in the Debug launch configuration drop-down)
    5. Many debuggers support some of the following attributes

      Some of the possibly supported attributes in launch.json:

      • program
      • args
      • env
      • cwd
      • port
      • stopOnEntry
      • console (e.g. "internalConsole", "integratedTerminal", "externalTerminal")
    1. If you'd just like to see refactorings without Quick Fixes, you can use the Refactor command (Ctrl+Shift+R).

      To easily see all the refactoring options, use the "Refactor" command

    1. To customize settings for debugging tests, you can specify "request":"test" in the launch.json file in the .vscode folder from your workspace.

      Customising settings for debugging tests while running

      Python: Debug All Tests

      or

      Python: Debug Test Method

    2. For example, the test_decrement functions given earlier are failing because the assertion itself is faulty.

      Debugging tests themselves

      1. Set a breakpoint on the first line of the failing function (e.g. test_decrement)
      2. Click the "Debug Test" option above the function
      3. Open Debug Console and type: inc_dec.decrement(3) to see what is the actual output when we use x=3
      4. Stop the debugger and correct the tests
      5. Save the test file and run the tests again to look for a positive result
    3. With pytest, failed tests also appear in the Problems panel, where you can double-click on an issue to navigate directly to the test

      pytest displays failed tests also in PROBLEMS

    4. VS Code also shows test results in the Python Test Log output panel (use the View > Output menu command to show the Output panel, then select Python Test Log

      Another way to view the test results:

      View > Output > Python Test Log

    5. For Python, test discovery also activates the Test Explorer with an icon on the VS Code activity bar. The Test Explorer helps you visualize, navigate, and run tests

      Test Explorer is activated after discovering tests in Python:

    6. You can trigger test discovery at any time using the Python: Discover Tests command.

      After using python.testing.autoTestDiscoverOnSaveEnabled, it'll be set to true and discovering tests whenever a test file is saved.

      If discovery succeeds, the status bar shows Run Tests instead:

    7. Testing in Python is disabled by default. To enable testing, use the Python: Configure Tests command on the Command Palette.

      Start testing in VS Code by using Python: Configure Tests (it automatically chooses one testing framework and disables the rest).

      Otherwise, you can configure tests manually by setting only one of the following to True:

      • python.testing.unittestEnabled
      • python.testing.pytestEnabled
      • python.testing.nosetestsEnabled
    1. Visual Studio Code supports working with Jupyter Notebooks natively, as well as through Python code files.

      To run cells inside a Python script in VSCode, all you need to is to define Jupyter-like code cells within Python code using a # %% comment:

      # %%
      msg = "Hello World"
      print(msg)
      
      # %%
      msg = "Hello again"
      print(msg)
      

    1. To help you get started quickly, we created a special Installer of Visual Studio Code for Java developers. Download Visual Studio Code Java Pack Installer Note: The installer is currently only available for Windows. For other OS, please install those components (JDK, VS Code and Java extensions) individually. We're working on the macOS version, please stay tuned. The package can be used as a clean install or an update for an existing development environment to add Java or Visual Studio Code. Once downloaded and opened, it automatically detects if you have the fundamental components in your local development environment, including the JDK, Visual Studio Code, and essential Java extensions.

      If you wish to use Java inside VSCode, try downloading the Installer of Visual Studio Code for Java developers

    1. Note: When you create a new virtual environment, you should be prompted by VS Code to set it as the default for your workspace folder. If selected, the environment will automatically be activated when you open a new terminal.

      After creating a new project related environment, it shall be specified as a default for this specific project

    2. Tip: Use Logpoints instead of print statements: Developers often litter source code with print statements to quickly inspect variables without necessarily stepping through each line of code in a debugger. In VS Code, you can instead use Logpoints. A Logpoint is like a breakpoint except that it logs a message to the console and doesn't stop the program. For more information, see Logpoints in the main VS Code debugging article.

      Try to use logpoints instead of print statements.

      More info: https://code.visualstudio.com/docs/editor/debugging#_logpoints

  2. Nov 2019
    1. the more files you have and the bigger your project, the more resources VS Code will start to consume. The Search Indexing and File Watcher scripts start eating up your memory. Moreover, to work on such a project, you will open each file in a new tab, leading to multiple VS Code instances running simultaneously, and eventually, your CPU usage will start to look like this

      VS Code consumes much more memory in comparison to Sublime while working on more significant projects

  3. Nov 2018