Skip to content

Commit

Permalink
Add null checks around vsls.getApi calls
Browse files Browse the repository at this point in the history
Fix #821
  • Loading branch information
bpringe committed Oct 17, 2020
1 parent 82ab977 commit 90b56bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
23 changes: 14 additions & 9 deletions src/liveShareSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ export async function setupLiveShareListener() {
if (liveShareListener !== null) { return; }

liveShare = await vsls.getApi();
liveShareListener = liveShare.onDidChangeSession(async (e: vsls.SessionChangeEvent) => {
if (e.session.role === vsls.Role.Host) {
await shareReplServerIfPossible();
}
})

if (liveShare) {
liveShareListener = liveShare.onDidChangeSession(async (e: vsls.SessionChangeEvent) => {
if (e.session.role === vsls.Role.Host) {
await shareReplServerIfPossible();
}
});
}
}

export async function didJackIn() {
Expand Down Expand Up @@ -51,10 +54,12 @@ async function getLiveShare() {

async function shareReplServerIfPossible() {
const ls = await getLiveShare();
if (connectedPort !== null && ls.session && ls.session.role === vsls.Role.Host) {
sharedPorts.set(
connectedPort,
await ls.shareServer({ port: connectedPort, displayName: "nREPL server" }));
if (ls) {
if (connectedPort !== null && ls.session && ls.session.role === vsls.Role.Host) {
sharedPorts.set(
connectedPort,
await ls.shareServer({ port: connectedPort, displayName: "nREPL server" }));
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/nrepl/jack-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,23 @@ export function calvaJackout() {
export async function calvaJackIn() {
try {
await state.initProjectDir();
await liveShareSupport.setupLiveShareListener();
} catch {
} catch (e) {
console.error("An error occurred while initializing project directory.", e);
return;
}
try {
await liveShareSupport.setupLiveShareListener();
} catch (e) {
console.error("An error occurred while setting up Live Share listener.", e);
}
if (state.getProjectRootUri().scheme === "vsls") {
outputWindow.append("; Aborting Jack-in, since you're the guest of a live share session.");
outputWindow.append("; Please use this command instead: Connect to a running REPL server in the project.");
return
}
state.analytics().logEvent("REPL", "JackInInitiated").send();
await outputWindow.initResultsDoc();
outputWindow.append("; Jacking in...");
const outputDocument = await outputWindow.openResultsDoc();

const cljTypes: string[] = await projectTypes.detectProjectTypes();
Expand All @@ -163,8 +169,6 @@ export async function calvaJackIn() {
return;
}
if (projectConnectSequence.projectType !== 'generic') {
outputWindow.append("; Jacking in...");

const projectTypeName: string = projectConnectSequence.projectType;
let selectedCljsType: CljsTypes;

Expand Down

0 comments on commit 90b56bd

Please sign in to comment.