Skip to content

Commit 998c2c9

Browse files
author
y8z
committed
[ci skip] automated comment issue creation and tag+archive page generation
1 parent 97f8e19 commit 998c2c9

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

_posts/2024-03-11-vscode_python_debugger.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
---
22
layout: post
3-
title: Run Python Debugger in VSCode
3+
title: Notes on using VSCode
44
subtitle:
55
tags: [IDE, software, tool, VSCode]
66
author: Yuanpeng Zhang
77
comments: true
88
use_math: true
99
---
1010

11+
This post is a collection of notes for useful setups, tricks and utilities in `VSCode`, as one of the popular IDEs in the market, along with
12+
`Sublime Text`, `Atom`, `JetBrains`, and so many to name.
13+
14+
## Python Debugger
15+
1116
Running the debug mode for coding in IDE is a very convenient feature, as we can put in break points and check variables in our program without killing the running process. In `VSCode`, to run the debug mode - here I am taking Python as the example - we need to first download the debugger extension. For Python debugger, we can just search in the extension sore within `VSCode` and we should be able to find the Python debugger listed to be installed. Once installed, we can go to the `Run and Debug` option in the left sidebar and try to run the program in the debug mode. Initially, it will ask us to populate the configuration file, if we have never used the debug before, as shown [here](https://code.visualstudio.com/assets/docs/python/debugging/debug-start.png). Clicking on the link as shown in the picture, we will be brought up with the configuration JSON file to populate. We can put something like below in the file,
1217

1318
```json
@@ -26,4 +31,18 @@ Running the debug mode for coding in IDE is a very convenient feature, as we can
2631
}
2732
```
2833

29-
Here, the `program` option will specify the relative path (with respective to the workspace folder) to the main Python file to be executed. By default, the `python` entry will not be created but it is actually necessary as it specifies the full path to the Python executable (which then determines which environment we will be using) to be used for running the Python script. Once all the entries above are populated properly, we can then hit the `Run` button in the `Run and Debug` option to start the debug mode. Here, we can first insert some breakpoints in our codes (by clicking on the left edge of the editor corresponding to a certain like and red circle will be shown to indicate the breakpoints). Then when the running program hits the breakpoint, it will bump into the debug mode, allowing us to bring up the command console -- we can use ``` ctrl+` ``` to bring up the terminal panel where we can find the `DEBUG CONSOLE` among the top option tabs in the terminal panel. We can also go to the top part of the editor to find the several options to control the flow of the debug mode, e.g., to move forward, i.e., to skip the current break point.
34+
Here, the `program` option will specify the relative path (with respective to the workspace folder) to the main Python file to be executed. By default, the `python` entry will not be created but it is actually necessary as it specifies the full path to the Python executable (which then determines which environment we will be using) to be used for running the Python script. Once all the entries above are populated properly, we can then hit the `Run` button in the `Run and Debug` option to start the debug mode. Here, we can first insert some breakpoints in our codes (by clicking on the left edge of the editor corresponding to a certain like and red circle will be shown to indicate the breakpoints). Then when the running program hits the breakpoint, it will bump into the debug mode, allowing us to bring up the command console -- we can use ``` ctrl+` ``` to bring up the terminal panel where we can find the `DEBUG CONSOLE` among the top option tabs in the terminal panel. We can also go to the top part of the editor to find the several options to control the flow of the debug mode, e.g., to move forward, i.e., to skip the current break point.
35+
36+
## Run Python file
37+
38+
To run a Python file within `VSCode`, we need to first set up the proper Python interpreter. If we don't do that, `VSCode` will try to pick up some Python from the system paths, but usually, that will not work with our Python script. To select the Python interpreter to use, we can bring up the command palette and type in `Select Interpreter` so that we can see and select the proper interpreter to use. Or, we can define a shortcut for it.
39+
40+
## Sidebar Focus
41+
42+
On the left side of `VSCode`, there is a sidebar containing quick access to different categories of operations, including `File`, `Git`, `Search`, `Extensions`, etc. We can define shortcuts to quickly switch to any of those categories. To do this, we can go to the shortcut settings and search for `Focus on` in the search box. Then we can see a whole bunch of options from which we can select whichever one relevant to define a shortcut for it.
43+
44+
## GitHub Copilot
45+
46+
With GitHub Copilot, we can do a lot of stuff in a very handy way. The most commonly used feature is probably the code auto suggestion. As we are coding, Copilot will smartly suggest what we might need and bring up hint for what is expected to be typed. If we think the suggestion is good to be accepted, we can simply press `Tab` so that the suggestion will come in. The actual experience with its smartness is amazing! It seems that it can automatically analyze the context of the codes and make very relevant suggestions. Another useful thing is Copilot chat, which is by itself just a chatbot like `ChatGPT`. We have the option to have a side chatbot, with which we will have a side panel for the chat. Or, we can bring up a dedicated tab for the chat. Whichever one, it is a very handy tool so that we can get access to the a `ChatGPT`-like interface without leaving our coding environment. There is a quick access button in the left sidebar for bring up the side chatbot. We can also define a shortcut for it by going to the shortcut settings and search for `Chat : Focus on Github copilot View` so that we can define the shortcut for the command. To define a shortcut for bringing up the dedicated chatbot tab, we search for `Chat: Open Editor (GitHub Copilot)` and define a shortcut for the command.
47+
48+
> Actually, there is a default shortcut defined for bringing up the sidebar chatbot, namely `Shift+Cmd+I`. In the editor view, pressing this key combo will bring up the sidebar chatbot. However, if we bring up the command palette first and type in something, we can then press the key combo to bring up the sidebar chatbot and at the same time kicking off the conversation with the text we typed in, in the command palette.

0 commit comments

Comments
 (0)