microsoft / codetour

VS Code extension that allows you to record and play back guided tours of codebases, directly within the editor.
https://aka.ms/codetour
MIT License
4.36k stars 113 forks source link

Link to open a file in workspace #117

Open bpmct opened 3 years ago

bpmct commented 3 years ago

This may be more of a VS Code question than a CodeTour question, but is it possible to link to a file in the workspace without linking to a specific tour item.

Things I tried in the tour description:

Some other sites I found:

gracegtaylor commented 3 years ago

That's a great question! @lostintangent do you have any ideas about how this could be done?

lostintangent commented 3 years ago

I'm actually not sure 😁 I'll do some investigation, and since this is such a common-scenario, we should probably add a shortcut for enabling this. Stay tuned!

albertored commented 3 years ago

According to this, I think the problem is that commands and sometimes their arguments should be URI encoded.

I tried as a proof of concept to replace the this code with

.replace(COMMAND_PATTERN, (_, commandPrefix, params) => {
      let args = JSON.parse(params)
      commandPrefix = commandPrefix.slice(1);
      if (commandPrefix == "command:vscode.open?") {
        args[0] = Uri.parse(args[0])
      }
      args = encodeURIComponent(JSON.stringify(args));
      const commandUri = Uri.parse(`${commandPrefix}${args}`);
      return `(${commandUri}`;
    })

and it works.

Clearly this solution is very ugly, we can not add an if clause for every possible command but I posted anyway because it can be useful for implementig the feature accordingly.

lostintangent commented 3 years ago

@albertored Ah great find! Thanks so much for sharing this.

I wonder if the best solution is for CodeTour to look for relative URLs and convert them into the appropriate vscode.open command? That way, we solve a common case, without needing to try to make the command handling too "smart"?

albertored commented 3 years ago

Yes, it is a good idea

albertored commented 3 years ago

Also because I made it work by inserting the absolute path of the file to open, we should also add some logic to prepend the workspace root directory if the path is not absolute

lostintangent commented 3 years ago

I just shipped support for markdown link that reference relative file paths: [Open this file](./file.html). That will translated into the appropriate link, and doesn't require the use of the command:* syntax.

I'll look into improving the command-syntax as follow-up, but for the purpose of this bug, the new file reference support should solve the problem, in a simpler way. Let me know if you run into any issues/feedback. Thanks!

bpmct commented 3 years ago

Is this resolved in the latest version? I have tried these things without success

[link](command:vscode.open?[\"${workspaceRoot}/README.md\"])
[link](./README.md)
[link](../README.md) - from one directory in
lostintangent commented 3 years ago

Yep this should be resolved. Note that the file path needs to be relative to the root of the workspace, not to the tour file. Did that not work for you?

bpmct commented 3 years ago

Yes I am still seeing this behavior

https://user-images.githubusercontent.com/22407953/116791864-1c7c0d00-aa8b-11eb-91e3-75e2b8d0965a.mov

Perhaps this is related to this?

we should also add some logic to prepend the workspace root directory if the path is not absolute

lostintangent commented 3 years ago

Hmm. I updated the extension to pretend the workspace root to the relative path. So that shouldn't be an issue. I was also going to mention that the file path is case-sensitive, but you seem to be using that already.

It looks like you're using macOS as well? Which is odd since that's what I'm testing on 🤔 Let me try again and see what might going going on.

bpmct commented 3 years ago

I was able to isolate the bug a bit further. It appears the link does not work if the tour is being created/edited, but if it's being played through, the links work fine:

https://user-images.githubusercontent.com/22407953/116838157-648a5500-ab9b-11eb-9c2c-0feed0196ddd.mov

bradennapier commented 2 years ago

Would be nice if you could "open to the side" so-as not to disrupt the ongoing tour