1 00:00:00,420 --> 00:00:05,62 VS Code includes support right out of the box for popular programming 2 00:00:05,62 --> 00:00:08,42 languages like JavaScript, TypeScript, HTML, 3 00:00:08,42 --> 00:00:09,197 and CSS, 4 00:00:09,197 --> 00:00:13,457 but you can add support for just about any programming language you 5 00:00:13,457 --> 00:00:15,264 can imagine with extensions. 6 00:00:15,264 --> 00:00:18,462 I'm going to demonstrate adding support for the Python 7 00:00:18,462 --> 00:00:21,600 programming language, but the process will be similar 8 00:00:21,600 --> 00:00:22,807 for other languages. 9 00:00:22,807 --> 00:00:26,486 The code for my website here doesn't currently have any 10 00:00:26,486 --> 00:00:27,780 Python files in it, 11 00:00:27,780 --> 00:00:35,305 but I'm going to add one now and just name it hello.py. 12 00:00:35,305 --> 00:00:40,120 Py is the standard file extension for Python code files. 13 00:00:40,120 --> 00:00:42,133 As soon as the new file is created, 14 00:00:42,133 --> 00:00:46,100 notice that I get a message at the bottom of the screen asking me if 15 00:00:46,100 --> 00:00:49,60 I want to install the recommended Python extension. 16 00:00:49,60 --> 00:00:52,779 That's a helpful suggestion and probably the quickest way to 17 00:00:52,779 --> 00:00:56,119 install the extension, but I'm going to close that and 18 00:00:56,119 --> 00:00:59,775 show you a couple more things before I manually install it. 19 00:00:59,775 --> 00:01:03,654 I'm going to paste some very simple Python code 20 00:01:03,654 --> 00:01:05,87 into my new file. 21 00:01:05,87 --> 00:01:09,723 This declares a simple function at the top to add two numbers. 22 00:01:09,723 --> 00:01:12,648 I then declare a couple of variables and pass them 23 00:01:12,648 --> 00:01:13,603 to the function. 24 00:01:13,603 --> 00:01:17,370 Finally, it prints a line of output stating the two numbers 25 00:01:17,370 --> 00:01:20,877 that were added and the sum returned from the function. 26 00:01:20,877 --> 00:01:23,690 Even without the Python extension installed, 27 00:01:23,690 --> 00:01:26,483 I'm getting some decent syntax highlighting. 28 00:01:26,483 --> 00:01:30,50 However, there's not much else I can do with this file currently. 29 00:01:30,50 --> 00:01:34,140 I'll press "Ctrl Shift P" to open the command palette. 30 00:01:34,140 --> 00:01:37,406 I'll then search for Python. 31 00:01:37,406 --> 00:01:41,78 The command palette found no matching commands. 32 00:01:41,78 --> 00:01:46,147 I have no way to run or debug the code from inside VS Code. 33 00:01:46,147 --> 00:01:50,672 I'll now click the extensions icon on the activity bar. 34 00:01:50,672 --> 00:01:53,905 Under the list of recommended extensions, 35 00:01:53,905 --> 00:01:59,965 the first item is the Python extension developed by Microsoft. 36 00:01:59,965 --> 00:02:03,151 I'll click on it to view the detail page for it. 37 00:02:03,151 --> 00:02:08,586 It's obviously very popular with well over 100 million downloads. 38 00:02:08,586 --> 00:02:12,393 This page includes lots of useful information such as the 39 00:02:12,393 --> 00:02:15,724 steps to get started, setting up your environment, 40 00:02:15,724 --> 00:02:18,363 and how to run useful commands. 41 00:02:18,363 --> 00:02:23,07 One very important point I want to make about this extension is that 42 00:02:23,07 --> 00:02:25,780 it does not include a Python interpreter. 43 00:02:25,780 --> 00:02:29,930 You'll need to install that yourself as you would before doing 44 00:02:29,930 --> 00:02:31,495 any Python development. 45 00:02:31,495 --> 00:02:35,599 I'll go ahead and install the extension by clicking the blue 46 00:02:35,599 --> 00:02:37,547 install button near the top. 47 00:02:37,547 --> 00:02:41,798 After a couple of seconds, the extension is installed and it 48 00:02:41,798 --> 00:02:45,977 now appears in my list of installed extensions on the left. 49 00:02:45,977 --> 00:02:49,924 Some extensions have dependencies which will automatically 50 00:02:49,924 --> 00:02:50,893 get installed. 51 00:02:50,893 --> 00:02:52,430 That's the case here. 52 00:02:52,430 --> 00:02:56,927 Just below the Python extension, you can see that an extension 53 00:02:56,927 --> 00:02:59,433 named Pylance was also installed. 54 00:02:59,433 --> 00:03:03,370 It's a language server for using Python in VS Code. 55 00:03:03,370 --> 00:03:08,39 I'll close the extension page to return to our Python code. 56 00:03:08,39 --> 00:03:12,736 With the extension installed, I'll open the command palette 57 00:03:12,736 --> 00:03:15,04 again and search for Python. 58 00:03:15,04 --> 00:03:19,651 This time, the search reveals lots of Python-related commands 59 00:03:19,651 --> 00:03:22,442 I can now run inside VS Code. 60 00:03:22,442 --> 00:03:27,30 The first in the list lets me select which installed interpreter 61 00:03:27,30 --> 00:03:28,50 I want to use. 62 00:03:28,50 --> 00:03:31,299 There are also commands for lots of other things like 63 00:03:31,299 --> 00:03:32,361 configuring test, 64 00:03:32,361 --> 00:03:35,916 debugging code, and lots more. 65 00:03:35,916 --> 00:03:39,412 In addition to the commands added to the command palette, 66 00:03:39,412 --> 00:03:43,879 there's also a new button added to the upper right corner of the 67 00:03:43,879 --> 00:03:46,998 window when you have a Python code file open. 68 00:03:46,998 --> 00:03:51,410 I'll click the dropdown arrow beside it and you can see I have 69 00:03:51,410 --> 00:03:54,230 options to run and debug my Python file. 70 00:03:54,230 --> 00:03:58,915 I'll click in the left margin of my code file to set a breakpoint 71 00:03:58,915 --> 00:03:59,867 on Line 5. 72 00:03:59,867 --> 00:04:05,713 I'll click the dropdown arrow again and select "Debug 73 00:04:05,713 --> 00:04:07,62 Python File." 74 00:04:07,62 --> 00:04:12,501 That uses the installed Python interpreter to begin running the 75 00:04:12,501 --> 00:04:14,606 program in the debugger. 76 00:04:14,606 --> 00:04:18,184 It opens a new terminal below, and execution quickly 77 00:04:18,184 --> 00:04:21,412 pauses on Line 5 where I set my breakpoint. 78 00:04:21,412 --> 00:04:25,95 From here, I have access to debugging features you're probably 79 00:04:25,95 --> 00:04:27,329 familiar with from other environments. 80 00:04:27,329 --> 00:04:32,699 I can use the buttons at the top of the window to step 81 00:04:32,699 --> 00:04:34,523 into or over code. 82 00:04:34,523 --> 00:04:38,974 On the left side of the screen are sections where you can view the 83 00:04:38,974 --> 00:04:42,604 value of local variables, configure watch expressions, 84 00:04:42,604 --> 00:04:44,464 and view the call stack. 85 00:04:44,464 --> 00:04:51,472 I'll quickly add a watch expression for the sum variable. 86 00:04:51,472 --> 00:04:55,985 I can stop the debugger by pressing the red square on the 87 00:04:55,985 --> 00:04:58,00 debug toolbar at the top. 88 00:04:58,00 --> 00:05:02,91 That's a quick preview of how to get started with the 89 00:05:02,91 --> 00:05:03,428 Python extension, 90 00:05:03,428 --> 00:05:06,224 but there are lots of other languages available. 91 00:05:06,224 --> 00:05:09,688 I'll click on the extensions icon again. 92 00:05:09,688 --> 00:05:13,529 I'll then click on the "Filter" button to the right of the 93 00:05:13,529 --> 00:05:15,65 search box at the top. 94 00:05:15,65 --> 00:05:21,964 From there, I'll select "Category" and "Programming Languages" 95 00:05:21,964 --> 00:05:23,780 from the menus. 96 00:05:23,780 --> 00:05:28,343 That brings up a long list of extensions for many different 97 00:05:28,343 --> 00:05:32,277 programming languages, and is a great way to browse 98 00:05:32,277 --> 00:05:33,615 what's available. 99 00:05:33,615 --> 00:05:37,639 Extensions make it possible for you to use VS Code and be 100 00:05:37,639 --> 00:05:40,586 productive with it no matter the language 101 00:05:40,586 --> 00:05:41,520 you're using. 102 00:05:41,520 --> 00:05:45,472 Up next, I'll show you how extensions can also be used to add 103 00:05:45,472 --> 00:05:48,41 additional functionality to your editor, 104 00:05:48,41 --> 00:05:51,00 regardless of the language you use.