Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex implementation for tour resiliency #141

Open
gracegtaylor opened this issue Feb 26, 2021 · 6 comments
Open

Regex implementation for tour resiliency #141

gracegtaylor opened this issue Feb 26, 2021 · 6 comments
Labels

Comments

@gracegtaylor
Copy link

Instead of attaching tours to code using line numbers, we can explore an implementation using Regex instead.

Creating tour step

  • The user can create a new tour step using the current flow (create tour step>write contents>save)
  • The tour step will get recorded in the JSON file and attached to the current line using Regex

Editing tour step

  • The user can click "Edit" when viewing the tour step
  • The user can edit the contents of the tour step
  • Once the user clicks "Save", the JSON file will update the corresponding code that is attached

Editing code

  • The user can change the contents of the code that the step is attached to
  • Once the code is changed, the JSON file will update the Regex which the step is attached to

Removing code

  • The user can remove the line of code that the step is attached to
  • The corresponding CodeTour and glyph will be removed
  • The user can undo this change (ctrl+z) and move the CodeTour into a new location before removing the code
@Timmmm
Copy link

Timmmm commented Mar 22, 2021

Rather than using a regex (bit tedious), there are a couple of other options:

  1. Mentioned in Add CodeTour tags inside code for tour resiliency #135, add a comment tag like:

    // TOUR: 123

  2. Use Git itself to try to track the line. Git doesn't have this capability built it so it would require some coding, but it's zero effort on the user's part and better than nothing.

@lostintangent
Copy link
Member

lostintangent commented Mar 27, 2021

Hey! So CodeTour actually currently supports adding "code markets" like you showed, but we found that most users don't want to add this clutter to their code. And so we haven't updated the tour to accommodate it.

Regarding regex, we actually don't expect the end user to have to author these manually. When you record a tour, we'll capture a regex of the selected line and simply use that instead of the line number. That would allow the line to be moved around the file and not require the tour to change. This would also make it easy to diagnose/fix a tour if it gets broken, because the step would provide a hint for what it was originally associated with (whereas a line doesn't really help with that).

You can try this out right now by setting the CodeTour: Record Mode setting to pattern and recording a tour. It would look and feel exactly the same as always, but it will capture code patterns as opposed to line numbers. That said, if you associate a step with a line that occurs multiple times in the file, then it will fallback to capturing the line number.

Furthermore, I'm working on support for auto-updating the tour if/when the line's contents change. Ideally we could do this without requiring any end-user intervention.

@lostintangent lostintangent added the enhancement New feature or request label Apr 18, 2021
@ankitbko
Copy link
Member

ankitbko commented Apr 7, 2022

Any update on this @lostintangent. Need any help?

@lostintangent
Copy link
Member

lostintangent commented Apr 9, 2022

Hey! Yeah I'd love some help here. I actually implemented a basic version of regex-based recording/playback, but it's not enabled by default. I've considered enabling this by default, but I'd love to get more testing on it. If you follow the instructions from my previous comment, you can give the regex based behavior a try, and let me know how well it works.

@ankitbko
Copy link
Member

I have been using the regex version. Works great for the use case. What seems to be missing is able to update the regex expression when the line changes. Even if there is manual button to update the regex as per current line will be helpful until the auto-updating feature is implemented. Right now I have copy the step text, delete the step and create a new step on the same line so I get updated regex.

Another thing I noticed is that sometimes I get line number or selection range gets added to the current step which overrides the regex expression but haven't been able to identify what causes this. Have to manually edit the json and remove the line number when its added.

Let me know if you need help with any of these.

@peter-kehl
Copy link

peter-kehl commented Sep 15, 2022

Using current CodeTour v0.0.58 (in VS Code 1.71.0 on Manjaro Linux)and as per README.md, I set codetour.recordMode to pattern, but it doesn't seem to apply. New recorded steps still contain line.

Or apply #260: I confirm that current main (commit 1ef66d7) v. 0.0.59 (if packaged with vsce package and then installed with code --install-extension codetour-0.0.59.vsix does support pattern. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants