Skip to content

Commit 7ae9935

Browse files
Fixing URI handler
1 parent 2379829 commit 7ae9935

File tree

4 files changed

+55
-36
lines changed

4 files changed

+55
-36
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
- Automatically set the "pattern" record mode when you create a new tour, and select `None` for the git ref
55
- Added support for opening a `*.tour` file in the VS Code notebook editor (Insiders only)
66

7+
## v0.0.55
8+
9+
- The URI handler now allows specifying _just_ a step number, in order to index into a repo within only a single tour
10+
711
## v0.0.54
812

913
- Added a URI handler, with support for launching a specific tour and step

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "CodeTour",
44
"description": "VS Code extension that allows you to record and playback guided tours of codebases, directly within the editor",
55
"publisher": "vsls-contrib",
6-
"version": "0.0.54",
6+
"version": "0.0.55",
77
"author": {
88
"name": "Microsoft Corporation"
99
},

src/extension.ts

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import { URLSearchParams } from "url";
54
import * as vscode from "vscode";
65
import { initializeApi } from "./api";
76
import { initializeGitApi } from "./git";
@@ -26,49 +25,64 @@ function discoverTours(): Promise<void> {
2625
return cachedDiscoverTours ?? (cachedDiscoverTours = _discoverTours());
2726
}
2827

28+
function startTour(params: URLSearchParams) {
29+
let tourPath = params.get("tour");
30+
const step = params.get("step");
31+
32+
console.log("CT Tour: ", tourPath);
33+
console.log("CT Step: ", step);
34+
35+
let stepNumber;
36+
if (step) {
37+
stepNumber = Number(step);
38+
}
39+
40+
if (tourPath) {
41+
if (!tourPath.endsWith(".tour")) {
42+
tourPath = `${tourPath}.tour`;
43+
}
44+
45+
console.log("CT Tour Path: ", tourPath);
46+
47+
console.log("CT Tours: ", store.tours);
48+
49+
const tour = store.tours.find(tour => tour.id.endsWith(tourPath as string));
50+
51+
console.log("CT Tour: ", tour);
52+
53+
if (tour) {
54+
startCodeTour(tour, stepNumber);
55+
}
56+
} else {
57+
startDefaultTour(undefined, undefined, stepNumber);
58+
}
59+
}
60+
2961
class URIHandler implements vscode.UriHandler {
3062
private _didStartDefaultTour = false;
3163
get didStartDefaultTour(): boolean {
3264
return this._didStartDefaultTour;
3365
}
3466

3567
async handleUri(uri: vscode.Uri): Promise<void> {
36-
if (uri.path === "/startDefaultTour") {
37-
this._didStartDefaultTour = true;
38-
39-
await discoverTours();
68+
this._didStartDefaultTour = true;
69+
await discoverTours();
4070

41-
let tourPath: string | null | undefined, stepNumber;
71+
if (uri.path === "/startDefaultTour") {
4272
if (uri.query) {
43-
const origin = vscode.Uri.parse(uri.query);
44-
if (origin.query) {
45-
const params = new URLSearchParams(origin.query);
46-
tourPath = params.get("tour");
47-
48-
const step = params.get("step");
49-
if (step) {
50-
stepNumber = Number(step);
73+
console.log("CT Query: ", uri.query);
74+
try {
75+
const origin = vscode.Uri.parse(uri.query);
76+
if (origin.query) {
77+
const params = new URLSearchParams(origin.query);
78+
startTour(params);
5179
}
52-
}
53-
}
54-
55-
if (tourPath) {
56-
if (!tourPath.endsWith(".tour")) {
57-
tourPath = `${tourPath}.tour`;
58-
}
59-
60-
const tour = store.tours.find(tour =>
61-
tour.id.endsWith(tourPath as string)
62-
);
63-
if (tour) {
64-
startCodeTour(tour, stepNumber);
65-
}
66-
} else {
67-
startDefaultTour(undefined, undefined, stepNumber);
80+
} catch {}
6881
}
82+
} else if (uri.path === "/starTour") {
83+
const params = new URLSearchParams(uri.query);
84+
startTour(params);
6985
}
70-
71-
return;
7286
}
7387
}
7488

src/store/actions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ export function startCodeTour(
7878

7979
export async function selectTour(
8080
tours: CodeTour[],
81-
workspaceRoot?: Uri
81+
workspaceRoot?: Uri,
82+
step: number = 0
8283
): Promise<boolean> {
8384
const items: any[] = tours.map(tour => ({
8485
label: tour.title!,
@@ -87,7 +88,7 @@ export async function selectTour(
8788
}));
8889

8990
if (items.length === 1) {
90-
startCodeTour(items[0].tour, 0, workspaceRoot, false, true, tours);
91+
startCodeTour(items[0].tour, step, workspaceRoot, false, true, tours);
9192
return true;
9293
}
9394

@@ -195,7 +196,7 @@ export async function startDefaultTour(
195196
startCodeTour(primaryTour, step, workspaceRoot, false, undefined, tours);
196197
return true;
197198
} else {
198-
return selectTour(tours, workspaceRoot);
199+
return selectTour(tours, workspaceRoot, step);
199200
}
200201
}
201202

0 commit comments

Comments
 (0)