Compilers

Using Visual Studio Code Live Share in CS Classes

Introduction

This guide will show how to set up and use Visual Studio Code’s Live Share extension. This will help you to work effectively with a partner in your compiler labs. The Live Share extension allows two users on two different computers to share access to a single Visual Studio Code project (such as a lab assignment). Both users can see and edit the files in the folder and can observe each other in real time. Supplementing Live Share with video or audio conferencing software is a good approximation for working side by side in Swarthmore’s actual labs (and, in some small ways, is a bit of an improvement!). In comparison to simple screen sharing, this approach gives both team members comparable autonomy and uses less bandwidth, making it work more smoothly on all but the most stable Internet connections.

Overview

Throughout this tutorial, we will assume that two students want to work together on a project. One of these students must take on the role of the host and the other must take on the role of the guest. These roles are fixed at the start of each session: you can be a host to your partner one time and a guest of your partner the next. The difference is that the host’s files will be used in the session.

In cases of more than two collaborators, one person would be the host and everyone else would be a guest. Do not invite anyone other than your teammate and course staff as a guest. Doing so would be a breach of academic integrity, as you are not to share the work you will submit for a grade.

To use Live Share, you will need two things: the Live Share plugin and a way to sign in to Live Share. Swarthmore does not control the Live Share servers, so your Swarthmore account won’t work. Instead, we will suggest that you sign up for a GitHub.com account. Note that this is a different website than the Swarthmore Github; it’s running the same software, but the repositories and user accounts are entirely different. We’ll walk through the steps below.

Setup

Github.com Account

In order to log in to Live Share, you will need a Github.com account. If you don’t already have one, you can sign up for free. Your username and password are your choice; they don’t have to match your Swarthmore login.

Live Share Plugin

Next, you need to configure your Live Share plugin. If you installed the course virtual machine or if you followed the remote CS network setup guide, you should already have this extension installed. (Otherwise, install it under Visual Studio Code’s Extensions panel.) Click on the Live Share button on the left panel. We now need to configure Live Share’s login and the easiest way to do that is to try to start a session. Click “Start Collaboration Session”.

Starting a collaboration session

This will prompt you to identify which sign-in method you want to use. Choose “Sign in with Github”.

Signing in with GitHub

This will open a browser window that asks you to log in to your Github account.

GitHub sign-in page in browser

After you log in, you will be redirected to a page that asks you to authorize Visual Studio Code Live Share to verify your identity. Press the Authorize button.

GitHub page requesting authorization

At this point, depending upon your operating system and your settings, you may be prompted with a number of recommendations. These may include associating certain types of links with Visual Studio Code. Visual Studio Code may also request that your firewall allow certain connections through. Allow each of these suggestions. You will eventually be returned to the Visual Studio Code window. If there is an active collaboration session, stop it by clicking the stop button in the upper left. (It appears when you hover your mouse over it.)

Stopping collaboration in Live Share

You have now configured your Live Share plugin!

Using Live Share

Now that you have set up Live Share, you can use it to collaborate with your partner in lab. One of you will be the host; the other will be the guest. Remember: you will be editing the host’s files.

Hosting a Live Share

If you decide to host the sharing session, you should begin by opening your lab assignment in Visual Studio Code. (The example shown here is from the notorious function timing lab in CS35.)

Opening a lab assignment in Visual Studio Code

Once your lab is open, click the Live Share button on the left and choose “Start Collaboration Session”.

Starting collaboration with lab assignment

You will receive a message that says that your invitation link has been copied to your clipboard.

Message indicating invitation link is copied to clipboard

Simply send the link to your partner using whatever mechanism you prefer (Slack, Zoom, Discord, etc.) and ask them to click on it. You are now sharing your session.

Joining a Live Share

If you are the guest of a session, wait for the host to send you a link. Once you click the link, your Visual Studio Code window should open and you should see your host as a participant of the session.

Visual Studio Code after clicking Live Share link

Click the file explorer button in the upper left (which looks like a document icon) to see your project. You can now edit this code with your partner!

Live Share guest viewing file tree

Collaborative Editing

Now that you and your partner are using the same session, you can see each other editing the files in your project. For instance, if both people are editing a single file, the host might see this:

Host view of collaboration session

The guest, on the other hand, might see this:

Guest view of collaboration session

Note that, to each user, the other user’s cursor is visible.

You should pay close attention to the pushpin in the upper right corner of the window. If that push pin is set (green), then you will follow the other user wherever they go. This allows the other user to show you code more easily so you can discuss it. If you want to work independently, the push pin must be unset (white). Click on the push pin to toggle this behavior.

Some Things To Remember

That’s it! You can now both edit the same project. Here are some things to remember: