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

indents(ecma): use @auto for comments #2545

Closed
wants to merge 3 commits into from

Conversation

theHamsta
Copy link
Member

Fixes #2544

@ajitid

@ajitid
Copy link

ajitid commented Feb 18, 2022

Hey @theHamsta, do you have a GIF/screenshot showing that it is working? Because it is still broken for me with this PR. Here's what I did:

  1. Replaced
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}

with

Plug 'theHamsta/nvim-treesitter', {'branch': 'ecma-auto-comment', 'do': ':TSUpdate'}
  1. Just for surety, I did :TSUninstall all and restarted nvim so that it could freshly install parsers.

Edit: you made a push right after I dropped this comment. Let me check the changes done in force push ( 54e4530) and let me get back to you...

@ajitid
Copy link

ajitid commented Feb 18, 2022

It is not working for me with 54e4530

JS file:

anim-rg

TS file:

anim-rg

TSX file:

anim-rg

As you can see, all three have different behavior, TSX being closest to stock Vim one (Vim also automatically joins comment's end string — * / becomes */).

@theHamsta
Copy link
Member Author

theHamsta commented Feb 18, 2022

It's working for me and it's also working in the tests. Did you restart?

It will not work when starting a comment with /* as it's taking it for a (ERROR (binary_expression (regex)))

fun fact: tsx is the only of the filetypes that wouldn't automatically set * in the tests

@ajitid
Copy link

ajitid commented Feb 18, 2022

It will not work when starting a comment with /* as it's taking it for a (ERROR (binary_expression (regex)))

Just to clarify — you're meaning to say that text shouldn't be written on the line where starting comment string is /*, right? If yes, then I'm not writing text there.

Did you restart?

I did restart. I'll try to remove everything and check again

@theHamsta
Copy link
Member Author

Me and the tests have the behavior of your TSX in JS and TS. The indents are almost the same for all three languages. There has to be some difference in the Vimscript filetype configuration.

@ajitid
Copy link

ajitid commented Feb 18, 2022

@theHamsta I just tried with basically removing everything (here's the dotfile I used for that matter) and I can still see the same issue.

@theHamsta
Copy link
Member Author

But you're not using our indent module in your config

indent = { enable = true },
but because we disable syntax it's possible that we break one of the traditional indent methods

@ajitid
Copy link

ajitid commented Feb 19, 2022

Oh, my mistake! I tried, now it works for all files except there's a slight issue in .ts ones. In them, I had to manually align ending multiline comment (look for */ in the GIF):

anim-rg

@theHamsta
Copy link
Member Author

Yes, this is the issue I was speaking of before. At the moment when we have just /* it's a regex in a error node for tree-sitter. I tried to match it but until now without success. Maybe we could use @auto always on errors.

@ajitid
Copy link

ajitid commented Feb 19, 2022

Oh okay. Weird that it only occurs in .ts but not in .js or .tsx files, isn't it? Anyway, I'm quite happy as we've made a significant progress here.

Maybe we could use @auto always on errors.

Totally on you if you want to merge the PR and close the issue or to give another stab fixing it. Thanks for your efforts!

@theHamsta theHamsta force-pushed the ecma-auto-comment branch 4 times, most recently from d83c94c to 70d3f50 Compare February 19, 2022 12:53
@theHamsta
Copy link
Member Author

theHamsta commented Feb 19, 2022

@ajitid can you check again? The behavior for unfinished /* should be fixed now.

The behavior for all three filetypes is the same (see tests)

@theHamsta
Copy link
Member Author

No idea why tests are failing without error. Seems similar to #2291

@ajitid
Copy link

ajitid commented Feb 19, 2022

Here's what I got (all of these GIFs are of a .tsx file):

VS Code's multiline comment:

anim-rg

vs this PRs multiline comment:

anim-rg

vs what stock Vim gives us:

anim-rg

Stock Vim behaves in an odd fashion, so let's keep it aside for now. But this PR has different indent behavior when a comment is made at the first column vs when it is done at an indent.

Here's VSCode's JSDoc comment:

anim-rg

To me VSCode's behavior seem to be the most appropriate here.


Apologies I'm not the best person to verify validity of the tests written.

@theHamsta
Copy link
Member Author

theHamsta commented Feb 19, 2022

Hmm, apparently it depends on the context on how the ERROR because it will add anything before to the error so that our regex will not match. I will try multi-line Lua regexes. I now works in more cases.

I find your GIFs super unhelpful. It's difficult to understand at what moment something should behave differently. It's usually better to have plain text with a marker where something should be inserted and what the result after indentation will be. Plus I can copy+paste your complete failure case to make it a test.

@theHamsta theHamsta force-pushed the ecma-auto-comment branch 2 times, most recently from 2b62f5a to 933c84c Compare February 19, 2022 14:26
@ajitid
Copy link

ajitid commented Feb 19, 2022

I find your GIFs super unhelpful. It's difficult to understand at what moment something should behave differently. It's usually better to have plain text with a marker where something should be inserted and what the result after indentation will be. Plus I can copy+paste your complete failure case to make it a test.

Noted. Will use text from now on.

@theHamsta
Copy link
Member Author

@ajitid I didn't mean in any way to criticize you. I'm very glad that you discovered that bug also in the "fixes". We can just save us some round-trips when it's clear what we mean. Best to communicate is failing example or even better a test for that.

Copy link
Member Author

@theHamsta theHamsta left a comment

Choose a reason for hiding this comment

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

todo: fix regex

@icholy
Copy link

icholy commented Mar 24, 2022

I just tested this branch and it still seems broken to me.

If the comment isn't closed, the next line does not get indented correctly.

/** <- hit [ENTER] here
*

If the comment is closed, the next line gets indented correctly.

/** <- hit [ENTER] here
 *
 */

@khamer
Copy link

khamer commented Nov 30, 2022

I ran into this, switched to @theHamsta 's fork and it resolved the issues for me. I know it's nearly a thousand commits behind master now; what's the status here? Anything I can do to help? Any chance of a merge? At worst, I might see about rebasing the fork on top of master for my own use.

@theHamsta
Copy link
Member Author

I don't remember whether this was an improvement or regression. Since the tests pass I guess it's ok? Can other JS please comment? I can maybe give it a try to solve the remaining issues that we still had here.

@khamer
Copy link

khamer commented Dec 5, 2022

I'm not sure - the comment indentation has been wrong since I started using this, so it might be an improvement. Compared to how C-style block comment indentation is handled w/o treesitter, it's a regression.

@theHamsta
Copy link
Member Author

I think we should merge. It is the same how comments are currently handled in C/C++ and Java. Though Go still uses the @ignore way.

Copy link
Member

@ObserverOfTime ObserverOfTime left a comment

Choose a reason for hiding this comment

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

LGTM aside from that one thing.

Comment on lines +53 to +54
;; Probably, also a comment but unfinished
((ERROR) @auto (#lua-match? @auto "/%*"))
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this unnecessary when (ERROR) @auto already exists above?

Copy link
Member

Choose a reason for hiding this comment

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

ping @theHamsta this would be really nice to merge :)

@clason
Copy link
Contributor

clason commented Aug 30, 2023

Needs to be adapted to the new upstream format, if still desired.

@theHamsta
Copy link
Member Author

comment, (ERROR) are already @indent.auto in master, template_string already @indent.ignore. The rule that matches inside the error is probably not stable and unclear whether relevant for current parser.

@theHamsta theHamsta closed this Aug 30, 2023
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.

Indent in comment is broken for TS and JS files
7 participants