Visual Studio Code for Python Developers Transcripts
Chapter: Exploring the Editor
Lecture: Explorer Workspaces

Login or purchase this course to watch this video and the rest of the course contents.
0:00 One of the main features and functionality that you will be using within Visual Studio Code is the Explorer view and what's called workspaces.
0:08 So right here on the left hand side, you can see from the activity bar, I clicked on the Explorer view and then that loads up in the primary view.
0:15 Now, here you have some options.
0:19 There's icons at the top that allow you to perform actions within the Explorer view and within the current context of the root folder of your project.
0:29 So I can create a new file within it. I can say I want it to be like test.py if I wanted to, to create something new there.
0:36 You can see it opens up automatically as soon as I create that in the editor view.
0:40 Some other options that we have in these icons within the Explorer view is to create a new folder or maybe behind the scenes separately in your Windows Explorer or in Finder on macOS.
0:52 You add another file within here that doesn't show up for some reason in Visual Studio Code. You can say, hey, I want to reload. Refresh.
0:59 The Explorer view. I'm clicking on it right now, but nothing's changing. You can see that.
1:03 And let's say things get a little unwieldy and I have too many parent child folders opened up and it's become too unwieldy to try and manually close all of them.
1:12 Well, there's a collapse all folders in the Explorer view option like that. So that's the Explorer view.
1:18 In a nutshell, you can also see at the bottom, there's a couple of little sashes too.
1:22 So here's the main view in the Explorer view, the current root folder that I have open. But in addition to that, there's the outline.
1:29 Which when you have an actual file opened up, Visual Studio Code will recognize the type of file it is.
1:36 In this case, a Python file and give you a general outline of the structure of that file.
1:41 In this case, we just have the API, which is a very simple file. So it's not showing a lot.
1:45 But as you get a larger code file open, this will help you navigate it a little bit more easily.
1:51 And last but not least, and this is something that has saved me at least once, if not twice.
1:59 Now, where I've accidentally deleted something in a file that I forgot about and later needed to come back and restore it.
2:06 Visual Studio Code will keep like a shadow copy of your files for you.
2:11 And you can restore back to those times or the state of that file at that time, essentially. Just really saved my butt, to be honest.
2:20 You know, excuse my language there, but it has. For instance, I had an ENV file, environment variables file, and that I deleted the
2:29 API key that I needed and I couldn't find it or generate a new one. And that helped me restore back the API key value that I wanted.
2:36 All right, so that's the Explorer view. Now, next up, as that kind of goes hand in hand with the Explorer view is a concept called workspaces.
2:45 This is something that took me a little while to get my head around.
2:48 But once, hopefully the way I explain it to you now, it'll be really quick and easy for you to understand.
2:53 Essentially, a workspace is a way that allows us to organize projects effectively. Within Visual Studio Code.
3:00 So in this case, my project, I just have this one root folder, which is for my API, the podcast API.
3:06 But maybe I had a front end component to this overall project that's in a separate folder structure or a separate repo that I clone down to this machine.
3:16 And I want to be able to work on that project at the same time as my API project and jump around quickly.
3:22 And that's where workspaces come into play can act as even though they're not physically in the same folder structure.
3:29 They can be connected virtually within Visual Studio Code using workspaces.
3:34 The way workspaces are made available within Visual Studio Code is a number of ways.
3:40 Well, one, one of the most prominent ways is through the file Explorer menu or the file menu.
3:45 In here, you can see there's a couple of options related to that are related to workspaces. I can open a workspace file from a file.
3:53 I can add a folder to the workspace. I can save my current setup as a workspace. Cause right now.
3:58 It's not technically a workspace because it's just the one folder that I opened up. We can turn it into a workspace.
4:04 And last but not least, you can duplicate a workspace.
4:08 So maybe you have it configured a certain way that you like it, and you want to add a little bit more for a certain workflow that you have.
4:14 Maybe some settings specific to that workflow.
4:18 You can duplicate this workspace as like the template to work off of and configure it a bit further to your needs.
4:24 But getting a little bit ahead of ourselves there. Let's talk about how we can create a workspace.
4:28 So what I'm going to do is with the current project that I have open, I'm going to create a workspace. So I'm going to say save as workspace.
4:36 I can give it a name and decide what, where I want to save it.
4:40 In this case, I'll just put it directly in the root project where you save this workspace file doesn't really matter as long as you know where it is and where you can get to it because it acts as a manifest for you to describe where other projects that need Visual Studio Code needs to reference and pull into it.
4:58 So I'm going to put it in here and I'm going to click OK.
5:03 You'll notice Visual Studio Code reloads now and this top area or sash, if you will, within the Explorer view now has that workspace keyword in there instead of just the name of the folder that I had open, which was base.
5:16 You'll also notice that now base that folder is a collapsible region within the Explorer view.
5:23 So may not really look too different, but this next step is what's going to really show the. Power of workspaces for you.
5:30 So in this case, talking about the example I was going through before where I have this API project, maybe I have my UI front end project in a separate folder.
5:40 Well, I can right click in the Explorer view and I want to be able to see it within here.
5:45 I can say, hey, I want to add that folder to this workspace by click on that.
5:49 And let's just say for demonstration purposes, this is the folder that has. My UI in it and I click OK, and now I can navigate both of those.
5:58 Within the same instance of Visual Studio Code.
6:01 Again, this is like a virtual directory that references multiple other directories that are not necessarily connected.
6:08 So let's say I made a mistake, though, this as you can see, this is just a essentially an empty folder that I added in here and I clicked on the wrong one.
6:16 I need to remove this from my workspace. I right click on that particular dropdown and say remove folder from the workspace.
6:23 Now we're back to just that base folder that we needed from before. So one of the unique things about a.
6:28 Workspace is you can configure your Visual Studio Code settings to be saved to that workspace so that whenever you load up this project again or the workspace again, Visual Studio Code will apply those setting changes separate from when you open up a different workspace or a different project within Visual Studio Code.
6:45 Demonstrate that will one let's take a look at what the code space file code workspace file looks like. It's essentially a JSON file.
6:52 It describes the folders that should be included as part of that workspace and any settings associated to it right now. So you can see it's just empty.
6:59 But if I go in and let's say maybe for this project, I want my font to be different size than what I have by default font size.
7:07 I'll search for that in my settings view right now. It's set to 18. I'll click on workspace in here. And. Let's change that to 22. And I hit save.
7:21 And now you'll see that one, the font size changed and it saved it into the workspace. Folder or workspace project file.
7:31 All right, and that essentially summarizes workspaces that can be a powerful tool for you in those larger, more complex projects that you might be working on within Visual Studio Code.


Talk Python's Mastodon Michael Kennedy's Mastodon