Giter Site home page Giter Site logo

microsoft / codetour Goto Github PK

View Code? Open in Web Editor NEW
4.3K 34.0 107.0 639 KB

VS Code extension that allows you to record and play back guided tours of codebases, directly within the editor.

Home Page: https://aka.ms/codetour

License: MIT License

TypeScript 98.75% JavaScript 1.25%
vscode vscode-extension knowledge-sharing code-navigation onboarding

codetour's Introduction

CodeTour 🗺️

CodeTour is a Visual Studio Code extension, which allows you to record and play back guided walkthroughs of your codebases. It's like a table of contents, that can make it easier to onboard (or re-board!) to a new project/feature area, visualize bug reports, or understand the context of a code review/PR change. A "code tour" is simply a series of interactive steps, each of which are associated with a specific directory, or file/line, and include a description of the respective code. This allows developers to clone a repo, and then immediately start learning it, without needing to refer to a CONTRIBUTING.md file and/or rely on help from others. Tours can either be checked into a repo, to enable sharing with other contributors, or exported to a "tour file", which allows anyone to replay the same tour, without having to clone any code to do it!

Getting Started

In order to get started, install the CodeTour extension, and then following one of the following guides, depending on whether you want to record or play back a tour:

Recording Tours

If you'd like to record a code tour for your codebase, you can simply click the + button in the CodeTour tree view (if it's visible) and/or run the CodeTour: Record Tour command. This will start the tour recorder, which allows you to begin opening files, clicking the "comment bar" for the line you want to annotate, and then adding the respective description (including markdown!). Add as many steps as you want, and then when done, simply click the stop tour action (the red square button). You can also create directory steps, selection steps, or content steps in order to add an introductory or intermediate explanations to a tour.

While you're recording, the CodeTour tree view will display the currently recorded tour, and it's current set of steps. You can tell which tour is being recorded because it will have a microphone icon to the left of its name.

If you need to edit or delete a step while recording, click the ... menu next to the step's description, and select the appropriate action. Alternatively, you can edit/delete steps from the CodeTour tree view.

Workspaces

If you record a tour within a "multi-root workspace", you'll be asked to select the folder that you'd like to save the tour to. This is necessary because tours are written as files to your workspace, and so we need to disambiguate which folder the tour should be persisted to. That said, when you're recording a tour, you can add steps that span any of the folders within the workspace, which allows you to create tours for a specific folder and/or that demonstrate concepts across multiple folders within the workspace.

Step Titles

By default, the CodeTour tree displays each tour step using the following display name format: #<stepNumber> - <filePath>. However, if you'd like to give the step a more friendly/recognizeable name, you can do so using one of the following methods:

  1. Right-click the step in the CodeTour tree and select Change Title
  2. Edit the step's description and add a markdown heading to the top of it, using whichever heading level you prefer (e.g. #, ##, etc.). For example, if you add a step whose description starts with ### Activation, the step and tree view would look like the following:

Text Selection

By default, each step is associated with the line of code you created the comment on (i.e. the line you clicked the + on the comment bar for). However, if you want to call out a specific span of code as part of the step, simply highlight the code before you add the step (clicking the Add Tour to Step button), and the selection will be captured as part of the step.

If you need to tweak the selection that's associated with a step, simply edit the step, reset the selection and then save it. Furthermore, if you want to create a step from a selection, simply highlight a span a code, right-click the editor and select Add CodeTour Step.

Re-arranging steps

While you're recording a tour, each new step that you add will be appended to the end of the tour. However, you can move existing steps up and down in the order by performing one of the following actions:

  • Hover over the step in the CodeTour tree and click the up/down arrow icon
  • Right-click the step in the CodeTour tree and select the Move Up or Move Down menu items
  • Click the ... menu in the step comment UI and select Move Up or Move Down

Additionally, if you want to add a new step in the middle of a tour, simply navigate to the step that you want to insert a new step after, and then create the new step.

Deleting steps

If you no longer need a specific step in a tour, you can delete it by means of one of the following actions:

  • Right-clicking the step in the CodeTour tree and selecting Delete Step
  • Navigating to the step in the replay/comment UI, selecting the ... menu next to the comment description and selecting Delete Step

If you need to delete multiple steps, the CodeTour tree supports multi-select, so you can Cmd+click (macOS) / Ctrl+click (Windows/Linux) multiple step nodes, and then right-click them and select Delete Step.

Editing a tour

If you want to edit an existing tour, simply right-click the tour in the CodeTour tree and select Edit Tour. Alternatively, you can edit a tour you're actively viewing by clicking the pencil icon in the current step's comment bar, or running the CodeTour: Edit Tour command.

At any time, you can right-click a tour in the CodeTour tree and change it's title, description or git ref, by selecting the Change Title, Change Description or Change Git Ref menu items. Additionally, you can delete a tour by right-clicking it in the CodeTour tree and selecting Delete Tour.

Linking Tours

If you want to create a series of tours, that a user can navigate through in sequence, then simply prefix your tour title's with the number they represent in the tour order (e.g. 1: Foo, 2 - Bar). When your tours are titled like this, the tour player will automatically provide the following benefis to your readers:

  1. If the current tour has a subsequent tour, then it's final step will display a Next Tour link instead of the Finish Tour link. This allows users to easily jump to the next tour.

  2. If the current tour has a previous tour, then it's first step will display a Previous Tour link. This allows users to navigate back to the tour they might have just navigated from.

If you don't want to number your tours like this, but you'd still link to link one tour to another, you can open it's *.tour file and set the nextTour property to the title of the tour you'd like it to link to.

Primary Tours

A codebase can include one or more tours, but it might have a primary tour, that is intended for new developers to start with. This way, when they open the codebase for the first time, they can be immediately presented with this tour, as opposed to a list of all tours.

In order to mark a specific tour as the primary tour, simply right-click it in the CodeTour tree, and select Make Primary. When you mark a tour as primary, any other tours that were marked as primary, will be updated to remove that annotation. Additionally, if you want to manually unmark a tour as being the primary tour, you can right-click it and select Unmake Primary.

If you'd prefer to number your tours (e.g. 1 - Status Bar), then a tour whose title starts with either #1 - or 1 - will be automatically considered the primary tour, and you don't need to do anything further.

Conditional Tours

If you author a tour that isn't relevant to every developer on the team, then you can decide when to conditionally show it in the CodeTour tree by adding a when property to the respective *.tour file. This property expects a JavaScript expression, that will determine the visibility of the tour, based on whether it evaluates to true or false. By default, all tours are displayed, and therefore, only tours with a when property that evaluate to false will be hidden.

In order to simplify the process of defining conditional tours, the following variables are made available to your when clause:

  • isLinux - The current user is running on Linux
  • isMac - The current user is running on macoS
  • isWindows - The current user is running on Windows

For example, if you want to define a tour that is only displayed for Linux users, you can simply set the when property to "isLinux".

CodeTour-Flavored Markdown

When you describe a step, you're able to use the full-breadth of markdown capabilities in order to write rich/compelling content (e.g. images, links, headings, code fences). However, CodeTour also provides some additional syntactic features that allow you to include additional interactivity to your tours:

File References

If you want a step to reference a file in the workspace, you can add a markdown link to it, using a workspace-relative path. For example, adding [Open file](./file.html) to your step content, would add a hyperlink called Open file, that when clicked, would open the ./file.html file.

Additionally, you can reference local images in a step as well, using a markdown reference. For example, adding ![Image](./icon.png) would render the icon.png in the step.

Step References

If you want to add a reference to another step within the current tour, you can use markdown's "link reference" syntax, specifying the 1-based number of the step to navigate to, prefixed by a # character (e.g. [#2], or [#23]). This reference will be automatically rendered as a hyperlink, that when clicked, will navigate the end-user to that step. The text of the link will default to #<stepNumber>, but you can customize that by appending a title to the link reference (e.g. `[title][#2]).

This syntax is a simplified version of using the Navigate to tour step command link manually.

Tour References

If you want to reference an entirely seperate tour, then you can create a link reference, that specifies the title of the tour (e.g. [Tree View]). This will be rendered as a hyperlink, that when clicked, will navigate the end-user to that tour, starting on step #1. If you'd like to navigate the user to a specific step in the tour, you can append the step number after the tour title, seperated by a # (e.g. [Tree View#3]). The text of the link will be rendered as <tourTitle>, but you can customize that by appending a title to the link reference (e.g. [title][Tree View]).

This syntax is a simplified version of using the Start tour command link instead.

Code Blocks

If you add a markdown code block to a step's body content, then the CodeTour player will render an Insert Code link below it, which allows the viewer to automatically insert the code snippet into the current file, at the line that the step is associated with. This can make it easy to use CodeTour for creating interactive tutorials or samples.

Note: The code snippet will be formatted after inserting it into the document, and therefore, you don't need to worry about adding whitespace/etc. to the snippet itself.

Shell Commands

To make it simpler to embed shell commands into a step (e.g. to perform a build, run tests, start an app), CodeTour supports a special >> synax, followed by the shell command you want to run (e.g. >> npm run compile). This will be converted into a hyperlink, that when clicked, will launch a new integrated terminal (called CodeTour) and will run the specified command.

Command Links

In order to add more interactivity to a tour, you can include "command links" to a step's description. Command links are simply markdown links, that use the command: scheme (instead of http: / https:), and specify the name of a VS Code command, along with an optional query string that includes the needed command arguments. Using this syntax, you can call any command in VS Code, including both built-in commands (e.g. vscode.open), as well as commands that are contributed by extensions (e.g. codetour.startTour). For example, the following shows how to include commands with and without arguments.

<!-- Call a command that doesn't require arguments-->

[Start tour](command:codetour.startTour)

<!-- Call a command that requires arguments-->

[Open URL](command:vscode.open?["https://aka.ms/codetour"])
Well-Known Commands

In order to make it simpler to call common commands, CodeTour will prompt you with a list of well-known commands as soon as you type command: in a step comment. If you select an option, it will generates the respective markdown code, and include placeholders for any necessary arguments. The following list explains the set of currently supported well-known commands:

  • Navigate to tour step - Allows you to specify a tour step, that when clicked, will navigate the end-user to that step in the current tour. This can be useful for giving the end-user the option to skip ahead in the tour, or quickly reference previous steps.

  • Open URL - Allows you to specify a URL, that when clicked, will launch the end-users default browser, and navigate to it.

  • Run build task - Allows you to run the build task, as defined by the current workspace's task.json file.

  • Run task - Allows you to specify a workspace task name, that when clicked, will run the specified task as defined by the current workspace's task.json file.
  • Run test task - Allows you to run the butestild task, as defined by the current workspace's task.json file.

  • Run terminal command... - Allows you to specify a shell command (e.g. npm run package), that when clicked, will run the specified command in the integrated terminal.

  • Start tour... - Allows you to specify the title or another tour in the workspace, that when clicked, will automatically start that tour.

Versioning Tours

When you record a tour, you'll be asked which git "ref" to associate it with. This allows you to define how resilient you want the tour to be, as changes are made to the respective codebase.

You can choose to associate with the tour with the following ref types:

  • None - The tour isn't associated with any ref. The benefit of this option is that it enables the code to be edited as part of the tour, since the tour will walk the user through whichever branch/commit they have checked out (e.g. interactive tutorials).
  • Current Branch - The tour is restricted to the current branch. This can have the same resiliency challenges as None, but, it allows you to maintain a special branch for your tours that can be versioned seperately. If the end-user has the associated branch checked out, then the tour will enable them to make edits to files as its taken. Otherwise, the tour will replay with read-only files.
  • Current Commit - The tour is restricted to the current commit, and therefore, will never get out of sync. If the end-user's HEAD points at the specified commit, then the tour will enable them to make edits to files as its taken. Otherwise, the tour will replay with read-only files.
  • Tags - The tour is restricted to the selected tag, and therefore, will never get out of sync. The repo's entire list of tags will be displayed, which allows you to easily select one.

At any time, you can edit the tour's ref by right-clicking it in the CodeTour tree and selecting Change Git Ref. This let's you "rebase" a tour to a tag/commit as you change/update your code and/or codebase.

Content Steps

Code tours are primarily meant to describe code, however, when you're recording a tour, it may help to provide some intro explaination about the tour itself. To do this, you can create a "content step", which is a tour step that includes a title and markdown content, but isn't associated with a directory or file. To create a content step, perform one of the following actions:

  1. Click the Add tour step... node in the CodeTour tree, underneath the node that represents your currently recording tour. Note: This option is only available when the tour doesn't have any steps.
  2. Right-click a tour node in the CodeTour tree and select Add Tour Step. Note: This option is only available while recording the tour.
  3. Run the CodeTour: Add Tour Step command.

When you create a content step, you'll be asked for a title of the step (e.g. Introduction), and then a "virtual" file will be created with an associated comment that you can edit. This allows the viewer to navigate between steps in a consistent fashion, regardless if the step is associated with a file or not.

Directory Steps

If you want to call out a directory as part of a tour, then while recording, you can right-click a directory in the Explorer tree and select Add CodeTour Step. This will create a new step that allows you to add a description for the selected directory. When the tour is played back, the directory will be focused in the Explorer tree, and the viewer will be presented with the description in a "virtual" CodeTour document.

Tour Files

Behind the scenes, the tour will be written as a JSON file to the .tours directory of the current workspace. This file is pretty simple and can be hand-edited if you'd like. Additionally, you can manually create tour files, by following the tour schema. You can then store these files to the .tours (or .vscode/tours or .github/tours) directory, or you can also create a tour at any of the following well-known locations: .tour, main.tour, .vscode/main.tour.

Within the .tours (or .vscode/tours) directory, you can organize your tour files into arbitrarily deep sub-directories, and the CodeTour player will properly discover them.

Tour Schema

  • title (Required) - The display name of the tour, which will be shown in the CodeTour tree view, quick pick, etc.
  • description - An optional description for the tour, which will be shown as the tooltip for the tour in the CodeTour tree view
  • ref - An optional "git ref" (branch/tag/commit) that this tour applies to. See versioning tours for more details.
  • isPrimary - Indicates that this tour is the primary tour within the workspace that an end-user should be guided through.
  • nextTour - The title of the tour that this tour is meant to precede.
  • when - Specifies the condition that must be met before this tour is shown. The value of this property is a string that is evaluated as JavaScript.
  • steps (Required) - An array of tour steps
    • description (Required) - The text which explains the current file/line number, and can include plain text and markdown syntax
    • file - The file path (relative to the workspace root) that this step is associated with
    • directory - The path of a directory (relative to the workspace root) that this step is associated with. Note: This property takes precedence over the file property, and so will "win" if both are present.
    • uri - An absolute URI that this step is associated with. Note that uri and file are mutually exclusive, so only set one per step
    • line - The 1-based line number that this step is associated with
    • pattern - A regular expression to associate the step with. This is only considered when the line property isn't set, and allows you to associate steps with line content as opposed to ordinal.
    • title - An optional title, which will be displayed as the step name in the CodeTour tree view.
    • commands - An array of VS Code command strings, that indicate the name of a command (e.g. codetour.endTour) and any optional parameters to pass to it, specified as a query string array (eg. codetour.endTour?[2]).
    • view - The ID of a VS Code view that will be automatically focused when this step is navigated to.

For an example, refer to the .tours/tree.tour file of this repository.

Exporting Tours

By default, when you record a tour, it is written to the currently open workspace. This makes it easy to check-in the tour and share it with the rest of the team. However, there may be times where you want to record a tour for yourself, or a tour to help explain a one-off to someone, and in those situations, you might not want to check the tour into the repo.

To support this scenario, when you start recording a new tour, you can click the Save tour as... button in the upper-right side of the dialog that asks for the title of the tour. This wll allow you to select the file that the new tour will be written to, so that it isn't persisted to the workspace. Furthermore, you can record a tour as usual, and then when done, you can right-click it in the CodeTour tree and select Export Tour.... This will allow you to save the tour to a new location, and then you can delete the tour file from your repo. When you export a tour, the tour file itself will embed the contents of all files needed by the tour, which ensures that someone can play it back, regardless if the have the respective code available locally. This enables a powerful form of collaboration.

GitHub Gists

If you install the GistPad extension, then you'll see an additional Export Tour to Gist... option added to the CodeTour tree. This lets you export the tour file to a new/existing gist, which allows you to easily create your own private tours and/or create tours that can be shared with others on your team.

Once a tour is exported as a gist, you can right-click the main.tour file in the GistPad tree, and select Copy GitHub URL. If you send that to someone, and they run the CodeTour: Open Tour URL... command, then they'll be able to take the exact same tour, regardless if they have the code locally available or not.

Starting Tours

In order to start a tour, simply open up a codebase that has one or more tours. If this is the first time you've ever opened this codebase, you'll be presented with a toast notification asking if you'd like to take a tour of it.

Otherwise, you can manually start a tour via any of the following methods:

  1. Selecting a tour (or specific step) in the CodeTour view in the Explorer activity tab

  2. Running the CodeTour: Start Tour command, and selecting the tour you'd like to take

    If the current workspace only has a single code tour, then this command will automatically start that tour. Otherwise, you'll be presented with a list of tours to select from.

Opening Tours

In addition to taking tours that are part of the currently open workspace, you can also open a tour file that someone else sent you and/or you created yourself. Simply run the CodeTour: Open Tour File... command and/or click the folder icon in the title bar of the CodeTour tree view.

Note: The CodeTour tree view only appears if the currently opened workspace has any tours and/or you're currently taking a tour.

Additionally, if someone has exported a tour, and uploaded it to a publically accessible location, they can send you the URL, and you can open it by running the CodeTour: Open Tour URL... command.

Tour Markers

As you explore a codebase, you might encounter a "tour marker", which displays the CodeTour icon in the file gutter. This indicates that a line of code participates in a tour for the open workspace, which makes it easier to discover tours that might be relevant to what you're currently working on. When you see a marker, simply hover over the line and click the Start Tour link in the hover tooltip. This will start the tour that's associated with this line of code, at the specific step.

If you want to disable tour markers, you can perform one of the following actions:

  • Run the CodeTour: Hide Tour Markers command
  • Click the "eye icon" in the title bar of the CodeTour tree view
  • Set the codetour.showMarkers configuration setting to false. Note that the above two actions do this for you automatically.

Navigating Tours

Once you've started a tour, the comment UI will guide you, and includes navigation actions that allow you to perform the following:

  • Move Previous - Navigate to the previous step in the current tour. This command is visible for step #2 and later.
  • Move Next - Navigate to the next step in the current tour. This command is visible for all steps but the last one in a tour.
  • Edit Tour - Begin editing the current tour (see authoring for details). Note that not all tours are editable, so depending on how you started the tour, you may or may not see this action.
  • End Tour - End the current tour and remove the comment UI.

Additionally, you can use the ctrl+right / ctrl+left (Windows/Linux) and cmd+right / cmd+left (macOS) keyboard shortcuts to move forwards and backwards in the tour. The CodeTour tree view and status bar is also kept in sync with your current tour/step, to help the developer easily understand where they're at in the context of the broader tour.

If you navigate away from the current step and need to resume, you can do that via any of the following actions:

  • Right-clicking the active tour in the CodeTour tree and selecting Resume Tour
  • Clicking the CodeTour status bar item
  • Running the CodeTour: Resume Tour command in the command palette

At any time, you can end the current code tour by means of one of the following actions:

  • Click the stop button (the red square) in the current step comment
  • Click the stop button next to the active tour in the CodeTour tree
  • Running the CodeTour: End Tour command in the command palette

Maintaining Tours

In order to ensure that your tours stay up-to-date as your codebase evolves, you can install one of the following tasks as part of your CI pipeline, in order to detect "tour drift" in response to PRs/commits/etc.

Reference

The following sections describe the VS Code integrations that the CodeTour extension contributes (e.g. tree, status bar, settings):

Tree View

If the currently opened workspace has any code tours, or you're actively taking/recording a tour, you'll see a new tree view called CodeTour, that's added to the Explorer tab. This view simply lists the set of available code tours, along with their title and number of steps. If you select a tour it will start it, and therefore, this is simply a more convenient alternative to running the CodeTour: Start Tour command. However, you can also expand a tour and start it at a specific step, edit/delete steps, re-order steps, and change the tour's description/title/git ref.

Additionally, the tree view will display the tour currently being recorded, which makes it easy to track your status while in the process of creating a new tour.

The tree view is automatically kept up-to-date, as you add/edit/delete tours within the current workspace. So feel free to record and/or edit tours, and then navigate them when done.

Status Bar

In addition to the CodeTour tree view, the CodeTour extension also contributes a status bar item that indicates the title and step of the current tour you're actively taking or recording. When clicked, it will open the file/line of the current tour step, which allows you to open other files while taking a tour, and then resume the tour when ready. Once you end the current tour, the status bar will automatically hide itself.

Contributed Commands

In addition to the CodeTour tree view and the status bar item, the CodeTour extension also contributes the following commands to the command palette:

  • CodeTour: Open Tour File... - Allows you to select a tour file that was previously exported.

  • CodeTour: Record Tour - Starts the tour recorder, which allows you to create a new tour by creating a sequence of steps.

  • CodeTour: Start Tour - Starts a tour for the currently opened workspace. This command is only visible if the current workspace has one or more code tours.

  • CodeTour: Refresh Tours - Refreshes the CodeTour view, which can be handy if you'd created/modified/deleted tour files on disk. This command is only visible if the current workspace has one or more code tours.

  • CodeTour: Hide Tour Markers - Hides tour markers. This command is only visible if the current workspace has one or more code tours, and tour markers are currently visible.

  • CodeTour: Show Tour Markers - Shows tour markers. This command is only visible if the current workspace has one or more code tours, and tour markers are currently hidden.

  • CodeTour: Edit Tour - Puts the currently active tour into edit mode. This command is only visible while you're actively playing a tour, that you're not already editing.

  • CodeTour: End Tour - Ends the currently active tour. This command is only visible while you're actively recording/playing a tour.

  • CodeTour: Resume Current Tour - Resume the current tour by navigating to the file/line number that's associated with the current step. This command is only visible while you're actively recording/playing a tour.

  • CodeTour: Add Tour Step - Add a new content-only step after the current step in the active tour. This command is only visible while you're actively recording a tour.

Configuration Settings

The CodeTour extension contributes the following settings:

  • Codetour > Prompt For Workspace Tours - Specifies whether or not to display a notification when opening a workspace with tours for the first time.

  • Codetour > Record Mode - Specifies how you want to associate tour steps to code when you're recording a new tour. Can either be lineNumber or pattern. Defaults to lineNumber.

  • Codetour > Show Markers - Specifies whether or not to show tour markers. Defaults to true.

  • Codetour > Custom Tour Directory - Specifies the name of a custom directory path that tours can be stored in within an opened workspace (e.g. docs/tours).

Keybindings

In addition to the available commands, the Code Tour extension also contributes the following commands, which are active while you're currently taking a tour:

Windows/Linux macOS Description
ctrl+right cmd+right Move to the next step in the tour
ctrl+left cmd+left Move to the previous step in the tour
ctrl+down ctrl+down cmd+down cmd+down End the current tour
ctrl+up ctrl+up cmd+up cmd+up Start new tour

Extension API

In order to enable other extensions to contribute/manage their own code tours, the CodeTour extension exposes an API with the following methods:

  • startTour(tour: CodeTour, stepNumber: number, workspaceRoot: Uri, startInEditMode: boolean = false, canEditTour: boolean): void - Starts the specified tour, at a specific step, and using a specific workspace root to resolve relative file paths. Additionally, you can specify whether the tour should be started in edit/record mode or not, as well as whether the tour should be editable. Once the tour has been started, the end-user can use the status bar, command palette, key bindings and comment UI to navigate and edit the tour, just like a "normal" tour.

  • startTourByUri(tourUri: vscode.Uri, stepNumber?: number = 0): void - Same as above, but allows specifying a file Uri, and optionally, a step number.

  • endCurrentTour(): void - Ends the currently running tour (if there is one). Note that this is simply a programatic way to end the tour, and the end-user can also choose to end the tour using either the command palette (running the CodeTour: End Tour command) or comment UI (clicking the red square, stop icon) as usual.

  • exportTour(tour: CodeTour): Promise<string> - Exports a CodeTour instance into a fully-embedded tour file, that can then be written to some persistent storage (e.g. a GitHub Gist).

In addition to the aforementioned functions, the extension API also allows subscribing to the following tour events:

  • onDidStartTour(([tour: CodeTour, stepNumber: number]) => void): Disposable - Registers a callback function, that is triggered whenever a tour is started or navigated. The provided callback is passed a CodeTour instance as well as the step number that is visible.

  • onDidEndTour((tour: CodeTour) => void): Disposable - Registers a callback function, that is triggered whenever a tour is ended. The provided callback is passed a CodeTour instance, which represents the metadata of the tour that was ended.

// Check if the end-user has the CodeTour extension installed.
const codeTourExtension = vscode.extensions.getExtension(
  "vsls-contrib.codetour"
);
if (codeTourExtension) {
  // Grab the extension API.
  const codeTourApi = codeTour.exports;

  // Use the API object as needed
  codeTourApi.onDidStartTour(([tour, stepNumber]) => {
    console.log("Tour started: ", tour.title);
  });

  codeTourApi.onDidEndTour(tour => {
    console.log("Tour ended: ", tour.title);
  });
}

codetour's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codetour's Issues

Drag and drop files into CodeTour panel to start a step

During user testing and getting community feedback, users consistently try to drag files into the CodeTour area to start recording a step of the tour. Perhaps we can enable this functionality, if we can think through the UX of this.

Focus cursor on steps

When you start a tour, the cursor should follow/focus the step position (line).

This would be really helpful if you use a Code Tour not only for navigation purposes, but also when you create a Code Tour which guides the user for “required changes” on files.

[bug] Repeated items in tooltip

I think I found a bug. When hovering a line that has a tour marker, the tooltip displays the same item several times.

tooltip_error

The number is not constant, but I haven't found a correlation with the number of steps or step comments.

Edit: the number of tooltip items does indeed go up with the number of steps. My guess is that "repeated" steps retrieved by the following function are not correctly filtered here:
https://github.com/vsls-contrib/codetour/blob/1808b3e06c550635a86b733dda42d265832afdb5/src/decorator.ts#L16

Edit 2: actually, it seems like the whole hover provider is being registered again every time I edit the tour.

Replace the “stop” icon in Side Bar

The Stop Tour icon which appears in the Side Bar gave me the wrong idea of Delete Tour. This happened because the X icon is used on other places in VS Code as a delete node element.

I think that because the Start Tour icon uses the play icon, like the Start Debugging, the Stop Tour icon could use the square icon, just like the Stop debugging.

Thank you

Add support for multi-root workspaces

Currently, we only discover code tours for the first root in the currently opened workspace. This probably accommodates most scenarios, but we should ensure that devs can open multiple workspaces, and see the tours available across them all.

Ask before overwriting an existing tour

I created a code tour with about three steps. Then I stopped recording. And I wanted to add a new step to the tour and I couldn't find a option to it. So I assumed if I type the same name for the new tour it would ask me to edit it. But instead the existing one got deleted and I lost all the recordings.

Later in the docs I found how to edit the tour. But overwriting existing one without a warning message is not intuitive IMHO. :-)

BTW: I love this extension. I really hope this gets into other editors as well. Thanks.. 👍 💯

Document deleting a step

Right now, I only see a button to end the tour. But what happens if I accidentally add a step in the wrong place or the wrong order? Currently, I have to end the tour and start over.

image

If would be nice to have a button to remove the step.

Allow recording code span highlighting

Currently, you can select a line of code and attach a comment to it. However, you may want to highlight a multi-line span of code and annotate that. We should explore how to introduce support for doing that.

Make it so npm tasks can be run from markdown-based text in steps

(Partially from #39 )

A suggestion that would have really helped me and I think would be amazing and really set this project ahead of traditional presentation tools :

I was glad to see the tour steps support markdown.

So when I type npm run storybook it shows how I expect it and how another developer would like to read it.

But it would be great if typing that was translated to

▶️ npm run storybook

And clicking the play button would actually run the task.

I was using Codetour to do a live presentation to a group of developers and it was slightly cumbersome to use my (extremely loud) mechanical keyboard to show a few new npm tasks. It would've been great to just click a button and show a task running.

Automatically update tours when code changes

The tour step has this data to identify file + line number:
"file": "webfolder/mem6/index.html", "line": 82,
Line numbers can change a lot adding and changing code.
You call this "tour decay", or "line number out of sync".
If you add to the step the text of the line in the code like this:
"line_text":"<script type='module'>"
Then you can :

  1. check if all the steps line numbers are still in sync with the code file line numbers
  2. If the changes are small, you can automatically find the nearest line with the text and update the line number.
  3. If you can not find the text, then it is an orphan and the line number needs manual fixing

Thank you for this great extension. This is the most natural way to introduce complex code to a programmer. And your extension and its user interface is great. Good job !

Allow defining alternate paths within a tour

Wicked cool feature ideas ... imagine being able to ask the user where they want to go next?

We could provide paths on the tour to do this. Tour contains paths, paths contain steps

So there would be a hierarchy of these. For example ...

I wan to start by showing the index.html, then steps in the main.js, then the App.svelte component (in a svelte app). At this point I can ask the user if they want to go to the path for building and running the app in the package.json or the path to see the code in the main components.

Paths:

  • paths could be rearranged
  • could be in a given sequence or out of sequence (dont show build path unless the user asks for that)
  • steps can be text OR they are a prompt asking which of a set of paths the user wants to go to next

A simpler version of this would be to simply allow grouping of steps into a path, so a set of steps can be visually broken out and rearranged.

Allow re-ordering of tour steps

I forgot a step and wanted to drag it up in the code tour treeview.

Also, would be nice to have up and down arrows, as a bonus

related to but no the same as #11

Allow recording multiple text selections for a step

Currently, the tour recorder allows you to capture a text selection along with a step. However, VS Code allows you to make multiple text selections, and therefore, the tour should respect that, which could enable highlighting a few disparate code spans within a single step.

Allow defining tours via inline code comments

Currently, tours are persisted as JSON files and written to the “.tours” directory of your repo. However, we could also explore allowing tours to be defined via actual code comments. For example, the following could represent a step definition above a line of code:

// CodeTour: <tourTitle> <stepNumber> <stepDescription>

While this approach could help mitigate tour decay, it also has some potential downsides:

  1. The comments would clutter the code for everyone that’s reading it, as opposed to enriching the code for only those that are actively taking the associated tour. This might not be a big deal, but in order to achieve long-term traction, I can’t help but feel like being unobtrusive has value. The “side car annotations” approach helps with this, and so it just comes down to the trade offs that teams are willing to make, and how well I can address bit rot by associating the tour with a specific commit/tag. I’m also exploring ways to notify you when a tour should be updated, but that’s a little experimental right now 😁

  2. I want the tour to be able to span all file types, and I’m not sure if the comment-driven approach would naturally work in 100% of meaningful scenarios. For example, how would you define a step in a JSON file (since it doesn’t support comments)? Since the role that declarative code/metadata plays in codebases can be a huge source of confusion, I felt like we needed a solution that was fully agnostic to the grammar of any specific file type.

  3. A codebase can define n-number of tours, and therefore, a single line of code could actually participate in multiple different tours. Having a single line annotated with two (or more) different tour descriptions could amplify amplify the potential for clutter.

  4. The tour would no longer be defined in a single place, and therefore, the benefits of having a human-readable file for quick/easy editing would decrease a little bit. In general, I want the visual editor/recorder to enable easy tour authoring for most scenarios. However, as with any abstraction, there’s commonly value in being able to pierce it for advanced tasks.

  5. You wouldn’t have a natural way to annotate folders or create “content-only” steps (e.g. intro instructions), both of which have come up as being valuable for folks using CodeTour.

Integrate with Live Share so that guests can follow along with a tour

It would be amazing if a developer could start a Live Share session, and then collaboratively walk through a tour with all of their guests. That way, the tour can be taken either offline/independently, or as a group.

Today, all participants in the Live Share session could take the tour “locally” on their own, but it would be much more valuable if everyone could take the same tour, and have their navigations/comments experience fully synchronized.

Allow inserting a step before/after the current step

Currently, you can insert new steps at the end of the currently recorded tour. However, it would be valuable to navigate backwards in the recorded tour, and choose to insert a new step before/after it. Much like you can do with a PowerPoint presentation.

Show that a line has a codetour associated outside of "tour mode"

I think it might be helpful to be able to see that a file you're currently viewing has a code tour step associated with it even though you're not currently viewing a tour.

So in tour mode:
image

Not in tour mode
image

It can serve as a hint that this thing might be important and by clicking it you can start the tour at that step and learn why. Might also be helpful as a reminder that if you edit this file you might need to update some line number for the hint itself 😅

Audio support

Currently, the tour is entirely text-driven. However, it could be really interesting to explore how to allow recording audio as well, and associating that with specific steps in the tour.

Editing a step does not allow change of selection

When editing a step, you can edit the text OK but changing the selection does not get saved. It would be nice if you can adjust the selection - otherwise you are stuck forever with a erroneous selection.

Record relative paths for files in parent/sibling directories

If you add a reference to a file in a parent directory, it will resolve as the full path to the file (ex If I have a tour in C:\brianrosamilia\parent\NewThing\, then adding C:\brianrosamilia\parent\my.Config should resolve as ..\my.Config and not the full path).

What happens when I add a tour step like that: it resolves as C:\brianrosamilia\parent\my.Config and clicking on the tour step will not work

What I'm expecting: it resolves as ..\my.Config and clicking on the tour step will work

The nice thing is you can actually just convert the path to relative yourself in the tour JSON as a workaround and everything will work. It even works if you subsequently add steps to that tour in the same file.

I'm assuming you agree with this on a technical level but, in my opinion, relative paths are great for things checked into source control so I feel this is the preferred behavior.

Btw I really appreciate this project. I am using it in a presentation tomorrow (wish me luck :) )

Cannot reply to a tour comment

Just installed the extension and testing it out in MacOS Catalina.

A given comment in the tour has a textarea that one can type into, and it's placeholder text is Reply... but after you've finished entering your reply there's no way to submit the form data and save the reply into the tour

Allow recording code input

The Code Tour allows recording comments in a sequence on a particular line.

Feature request: add another type of the tour step - "code input" where the author can record their code input as they code. The extension will then replay their input back to the users on those steps, creating richer interactive tutorials and hands-on user guides.

Allow persisting and loading personal tours from a GitHub Gist

We recently added the ability to export and open tours, which allows you to create one-off/personal tours that don't need to live in the main codebase' repo. However, the currently export/open functionality is limited to saving/opening from the local filesystem, and we should add support for using GitHub gists as well.

Steps should automatically be in edit mode when recording

When playing back a tour, hitting Ctrl Rightarrow is supposed to step you through the steps. It does for the first step then it stops working, and Ctrl Rightarrow starts moving the cursor through the code instead? I think its a focus issue - if you click to focus on the step window then Ctrl Rightarrow works again for the next step.

The highlight in the tree does not match what is being displayed in the code window, when navigation has been done using arrow buttons. This would be most helpful to know where you are.

Clicking on the arrow buttons in the tree seem to do illogical things. Sometimes they just highlight the step represented by the explorer window, sometimes they cause the next or previous step to appear. Can't figure out their logic.

Clicking on the arrows in the current step window work OK, but it would be nice if the corresponding tree explorer step would highlight, as mentioned before.

Seperate view for CodeTour?

Hello!

The explorer view tends to get somewhat cluttered with showing file explorer and open editors etc. How would you feel about having the code tour in it's own view (similar to the docker extension below)?

image

Allow adding steps that point out folders, instead of files

First of all - thanks for great extension!

I was thinking that sometimes it's useful to comment on a folder level, rather than the file level.
Imagine I want to create a codetour step that points out that there some special folder that does some magic or stg.
Is it somehow doable?

/cheers

Allow visually editing the line number associated with a step

Using the tour recorder, you can edit the description and selection that’s associated with a step. However, in order to edit the line number that the step comment is displayed on, you need to manually edit the tour’s JSON file. We should explore how to enable easily editing a step’s line number via the recorder, so that core authoring operations don’t require editing JSON files directly .

Reference workspace-local images from step

Currently, you can author your step descriptions using markdown, which includes support for referencing HTTP-based images. However, you can't currently reference images that are local to the codebase, which is a little limiting. It would be awesome if you could add something like the following to a step comment and it would work (assuming that the path was valid in the current workspace): ![image](./images/foo.png). That way the repo could include the codebase, the tours and any associated images.

Add support for multi-root workspaces

Thank you so much for this plugin! Awesome idea.

Issue:
When using VSCode workspaces, the path to the recorded file is incorrect.
When starting a recorded tour, I get the error:

unable to resolve non-existing file

Allow replaying code tours on GitHub

A lot of devs don’t use vs code, it would be amazing for them to be able to play the tours on the web, without needing to download vs code for that (I think it’s fair to require vs code to record a tour)

[bug] Error exporting tour - bad path

Codetour does not work on my workspace. I can record a tour, but when I try to run it, clicking on the steps does nothing, it doesn't seem to "find" the files.

Then I tried to export the tour and I got this error, which suggests that the extension is not creating the right paths to the files referred to by the steps, am I right?

This is the error (just to be clear, the correct path is /home/user/repos/my-repo/index.ts)

Error running command codetour.exportTour: Unable to read file '/home/user/repos/my-repo/my-repo/index.ts' (EntryNotFound (FileSystemError): 
Error: ENOENT: no such file or directory, open '/home/user/repos/my-repo/my-repo/index.ts'). This is likely caused by the extension that contributes codetour.exportTour.

Edit: this occurs only while using a vscode workspace

Add “Stop Tour” command

Today, once you start a tour, there is no way to “stop”.

I know you can “pause” clicking the ^ icon in the comment/step panel, but it only hides the tour, but keeps the “comment indicator” in the gutter.

The “Stop Tour” command should end the tour entirely, removing the indicator from the gutter and resetting the Status Bar.

Add Navigation Options

I think to navigate I am supposed to either use the ouse/trackpad and click on steps in the tree OR focus on a step, click CMD ->.

But the latter doesnt work without having to re-focus on the next step. For example:

  • open step 1 with the mouse
  • click on step 1's visual interface
  • click CMD ->
  • now click on step 2's visual interface
  • click CMD ->

Notice that we have to keep putting focus back on the step. It would be nice to allow full keyboard control to use CMD -> and CMD -< to go forward and backward without having to reset focus.

Improve onboarding experience

Currently, the list of tours is blank when a dev installs the extension. During testing, when we showed the extension with a sample tour to a dev, it helped them orient to the extension functionality and UI.

Add support to Remotes

First of all, congrats for the extension! Great idea 👏 .

I tried to use it on remotes (docker), but just noted the extension still doesn’t support it. I could Install in Container but I guess it wouldn’t be necessary.

I’m preparing a PR to help you with that 😁

Allow defining a tour "welcome page"

Thinking out loud ...

The tour begins and the first thing the audience sees is a welcome message. Something to give them context for the tour and tell them what they are about to see.

Title: Welcome to the Tour of Heroes!
Body (multi-line): Here we can put paragraphs using markdown to explain the tour. Good tips might be to explain the path we are taking through the tour. What we're trying to get across. What they will be oriented with.
Author: Name
Tour Lat Revision Date:

Visual Studio support

Love the idea, and whilst we use visual studio code for smaller pieces of work, our many large code base is worked on in Visual Studio 2019. This feature would be great for documenting the various subsystems and cross cutting concerns, just wondered if you have any thoughts on how easy this would be to make into a VS extension ?

Introduce a "recording mode" that allows visually authoring tours

Currently, you can authors code tours "manually" by creating the JSON file. However, I plan to allow the user to "start recording", and then navigate across files, clicking on relevant lines, and adding comments visually. That way it's very quick to create new tours for a codebase.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.