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

Added TextObject for Tags - #194 #13 #247

Merged
merged 7 commits into from
May 20, 2020

Conversation

austenc
Copy link
Contributor

@austenc austenc commented Mar 8, 2019

Hello @aioutecism and once again thank you for your guidance earlier in the week! Here's my first stab at adding t / tag TextObjects to the extension. Looking forward to seeing what you think! The new stuff I added uses regex to parse out open/closing tag pairs in the document, and then find the proper ones based on cursor position. In all of my tests it seems to do the job!

A few things I wanted to mention which I had trouble with:

  • The parseTags method would ideally be called in a constructor, but since it needs a document reference it seemed best to just use a class variable to determine if we need to parse the document again or not. Hopefully this works okay?
  • Unit tests... I wrote a handful of these, but a couple of them are failing sometimes and other times passing 100%. I'm not sure if this is caused by something in the test runner or what. Have any ideas there? In all of my manual testing of the extension (including some weird nested stuff) it functions as intended.... so it seems like something the test runner is doing slightly differently between runs?

Please let me know what you think and I'll be happy to adjust so you can get this thing released.

Cheers! 🍻

@austenc
Copy link
Contributor Author

austenc commented Jul 11, 2019

@aioutecism thoughts on this?

@alisonatwork
Copy link
Collaborator

I have never used this keypress in vim, although now I see this PR I have tried it out and it seems pretty useful! One suggestion on the tests might be to also test some "sad path" cases, specifically to show what happens when you don't have a perfectly nested tags.

@austenc
Copy link
Contributor Author

austenc commented Oct 24, 2019 via email

@alisonatwork
Copy link
Collaborator

I admit it - i had a bit of an ulterior motive in commenting - it was to see if i was the only one still here 😁 Are you just running your fork from this PR or did you merge together a few of the ones open here?

@austenc
Copy link
Contributor Author

austenc commented Oct 24, 2019 via email

@jackfranklin
Copy link
Collaborator

@austenc sorry for the silence on this! One of the things I miss is this text object (I use cit a lot in regular Vim) .

I would agree that a couple of 'sad path' tests would be useful - would you like to add them and then we can merge this? @aioutecism has said they are happy to help by pushing new releases of the extension when we have things ready to go :)

@austenc
Copy link
Contributor Author

austenc commented Jan 22, 2020

Added a few more tests, did you have any other specific "sad path" tests in mind @alisonatwork @jackfranklin?

Thank you to both of you (and to @aioutecism !)


let match;
let tags: Tag[] = [];
while ((match = this.TAG_REGEX.exec(document.getText())) !== null) {
Copy link
Owner

@aioutecism aioutecism Jan 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using getText without a range. This would freeze the editor if the document is too large.

VSCode recently added a feature to mirror cursor on matching tags. Seems like it's using the language server:
https://github.com/microsoft/vscode/blob/9e1d730cf2950297d7a85fc66be89411d7b8bcd9/extensions/html-language-features/client/src/htmlMain.ts#L134-L139
This will only support HTML, but maybe that's what we want anyway?

Or we can just write a more performant matching logic, but some edge cases such as <br /> or <div devilData="<div>">got you</div> can be difficult.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to support JSX and any similar variants if possible - not sure if using the language server would limit that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, not to mention the other various templating languages and file extensions. Some I use often are *.blade.php or *.antlers.html for example.

I am not a huge fan of parsing the whole document, but admittedly this idea and the regex was borrowed from the other vim extension. I tried doing it other ways but ran into various issues that required having the sets of matching end tags (which my original attempts did not).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. We can challenge this later.

@austenc Would you mind adding a comment here such as // TODO: Potential performance issue with getText()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks for the reminder 👍

@aioutecism
Copy link
Owner

aioutecism commented Jan 22, 2020

Despite the potential performance issue and rare cases, this should work most of the time. So I'm okay if we merge it and add some comments & create an issue to remind us to fix it later.

Leave it to you @jackfranklin .

@jackfranklin
Copy link
Collaborator

@austenc this is awesome, thank you!! @aioutecism I think that if we ship this + gather feedback on cases where it causes issues, that might be the best way of figuring out the next steps?

@aioutecism
Copy link
Owner

@austenc this is awesome, thank you!! @aioutecism I think that if we ship this + gather feedback on cases where it causes issues, that might be the best way of figuring out the next steps?

Agree.

Copy link
Owner

@aioutecism aioutecism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks, @austenc!

@austenc
Copy link
Contributor Author

austenc commented Jan 26, 2020

Thank you @aioutecism for the guidance and reviews!

One last thing... I am seeing tests fail sometimes. It seems to affect tests outside the scope of this PR also. Most of the time when I run them it works fine, but occasionally I'll have one fail.

Haven't figured out a way to get it to fail consistently... but I'm wondering if it is a slight variability in the blackbox stuff or something? I am not too experienced with javascript testing so I don't know where to look.

@aioutecism
Copy link
Owner

@austenc Thank you so much for contributing! The test failure might because VSCode sometimes is slow to respond to some commands. I haven't found a good way to avoid this.

Let's wait for @jackfranklin's review and I think we can ship this then!

@alisonatwork
Copy link
Collaborator

Thanks for the contribution @austenc - I will merge this and hopefully we can release to the VS Code marketplace soon 👍

@alisonatwork alisonatwork merged commit a2cc98e into aioutecism:master May 20, 2020
@austenc
Copy link
Contributor Author

austenc commented May 20, 2020

THANK YOU! 🎉 🎉 🎉 🤗

@austenc austenc deleted the tag-blocks branch May 20, 2020 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants