Lab: using VS Code & mantis
This term, we will study computer systems partly by using the C programming language and its relationship to the Intel x86_64 machine language and assembly language. To ensure that we all have a consistent computing environment, we will do our work on the Linux server mantis.mathcs.carleton.edu. This short lab will help you get started working on mantis.
In case you want a demo of the elements of this lab, here's a short video explaining why we are working on mantis and demonstrating how.
Install Visual Studio Code
If you're working on a lab computer on 3rd Olin, you do not need to do this section, since VS Code and the Remote-SSH extension are already installed.
- Get the app. Download and install Visual Studio Code on your working computer.
- Launch the app.
- Install the Remote - SSH extension. In VS Code, on the left edge of the window, click on the Extensions icon. (Alternatively, select the View→Extensions menu item). In the extensions browser, search for "SSH". The top result will probably be "Remote - SSH" by Microsoft. Install it.
Connect to mantis
- Hover your mouse over the little green or blue icon in the bottom left corner of the VS Code window. You should see hover-text that says "Open a Remote Window". Click.
- At the top of VS Code, you'll see a drop-down menu. Click on "Connect to Host..."
Now you'll see a new menu item: "+ Add New SSH Host". Click on it, and fill the resulting text box with:
YOUR_CARLETON_USER_NAME@mantis.mathcs.carleton.eduHit Enter. Assuming this goes fine, you won't have to do "Add New SSH Host" again. Instead, mantis will appear as a choice in the "Connect to Host" menu.
- At this point, what VS Code asks you will depend on context. You may be asked for a password or you may be asked for an "SSH config file" or something along those lines. Follow your nose to get to place where you can enter your Carleton password.
- Once you have connected successfully to mantis, a new window will open. That bottom-left icon will now say "SSH: mantis.mathcs.carleton.edu", which is the signal that you're ready to go.
Set up your working space on mantis
- Open VS Code's file explorer. In the upper left corner, click on the two-pieces-of-paper icon that opens VS Code's file explorer (or select View→Explorer from the menu). Then click on the Open Folder button that appears in the explorer. This will give you many choices, but you should go ahead and click OK for the default option, which should be /Accounts/YOUR_CARLETON_USER_NAME.
- Express your trust if asked. You may see a message asking if you trust the authors of the code you're looking at. Say yes, since you haven't written any code yet, and besides, you're going to be the author.
- Deal with "large workspace" warning.
You may see a warning panel that says "Unable to watch for file changes in this large workspace...".
Don't worry about this. This is always ignorable, but in any case, we'll fix this permanently in a minute.
Set up a long-term working directory named cs208. The file explorer at the left side of the VS Code window should now show you the top level of files in your CS/mantis account.
Next, you want to create a folder to keep your stuff in.
- Go up to the VS Code menu bar and select Terminal→New Terminal. A panel with a Unix prompt should appear in the bottom right of your VS Code window. That's a regular old Unix prompt on the mantis server, and you can run any Unix commands you want there.
In that terminal, create a folder named "cs208" where you will do your work for the term.
mkdir cs208If you do "ls" in the terminal after that, you'll see the new folder. You can also look at the VS Code file explorer, and the folder should show up there, too.
Log out of mantis
Click on the bottom-left icon ("SSH: mantis.mathcs.carleton.edu"), scroll to the bottom of the resulting drop-down menu, and select Close Remote Connection.
A typical work session
You're all set up now, and won't need to do most of the steps above anymore. This section describes a typical session with VS Code and mantis.
- Restart, but with the cs208 working directory. Log in to mantis again, but this time when you click on "Open Folder" in the VS Code Explorer, select your cs208 folder instead of your top-level directory. Open a terminal and you're ready to roll!
- Alternative: use the Open Recent menu. Take a look at the File→Open Recent menu for VS Code. Does it show "~/cs208 [SSH:mantis.mathcs.carleton.edu]"? When you're working on your own computer, that is very convenient for future sessions.
- Start a new program. Go to the File→New File menu. Type a hello world program (e.g., hello.py with a single print statement). Save.
- Test your program. In the VS Code terminal, type a suitable command (e.g., "python3 hello.py").
- Pause to reflect. Where is my hello.py file stored? (on the computer named mantis.mathcs.carleton.edu.) Will it still be on mantis after I log out? (Yes.) Is there a copy still on my computer after I log out (Maybe in a cache somewhere, temporarily, but probably not.)
- Download a file from mantis. Copy a file from mantis to your your local computer (e.g., so you can submit homework via Moodle on your web browser) like so. In the VS Code file explorer, right-click on the file you want to download and select Download. As far as I can tell, there's no drag-and-drop way to do this.
- Upload a file to mantis. Open the folder containing your file (e.g., new_hello.c) on your local machine. This will be a Windows Explorer or macOS Finder or Linux folder display. Drag the icon of your file into the VS Code Explorer panel while you're logged in to mantis.
- Always log out when you're done. Don't just close the VS Code window. This helps mantis clean up after your connection, which helps keep mantis usable for you and your classmates.
One caveat about working on the lab computers
When you logout of the computers on 3rd Olin, your changes on that computer are discarded. So, for example, if you did Add New SSH Host on an Olin 310 computer, the resulting menu option would not be there anymore when you returned to that computer later. This is one of many reasons I encourage you to do most of your work on your own computer.