stkb / Rewrap

Rewrap extension for VSCode and Visual Studio
https://marketplace.visualstudio.com/items/stkb.rewrap
Other
504 stars 62 forks source link

FR: Context-free rewrap selection #213

Open marius311 opened 4 years ago

marius311 commented 4 years ago

Thanks again for the quick fix to https://github.com/stkb/Rewrap/issues/203 but I've run into tons of other little syntax things that break Rewrap in my day to day coding to be honest. The worst part is that if a file has something like this in it, then Rewrap is basically broken for the entire rest of the file. Even if I just select the part of text I'm trying to rewrap, Rewrap seems to be confused by the presense of some other syntax it doesn't understand well outside of my selection. An example from Python:

"""stuff""" # this confuses Rewrap 

# this will now never wrap anywhere later in the file 

Additionally, it appears that if Rewrap doesn't think something is "rewrappable" (which seems limited to string and comments), it just won't do it, despite that I've selected the line. As an example, in Python I often want to wrap something like:

import some, very, long, list, of, packages, ...

but it will not wrap.

To me it seems like Rewrap is trying to be too smart, and unless it wants to try and be aware of every possible language's little idiosyncracies (which seems impossible), it would be better suited to at least have a "simple mode" where if I just select a few lines and hit rewrap, then it would ignore the contex that these lines are in, and do a very simple rewrap that is unlikley to break (kind of like what older versions of this package did). I think that would go a long way to making it function better for me.

stkb commented 4 years ago

Firstly thanks for the bug report; it was an amateur regex mistake and so the example with the docstring on one line should be fixed in the just-released v1.12.0.

About wrapping code when asked explicitly: that's tracked in #96 and I will now be adding that feature back sometime, since a few people have asked for it.

However that feature was still aware of where comments are in the file, since it had the rule: if a selection contained (part of) a comment/s, then only (that part of) the comment/s would be wrapped, otherwise the selected code would be wrapped instead. That allowed you select a whole selection (or all) of the document, and wrap all the comments within.

So that feature still requires correct knowledge of where the comments are in a file, and that's not too difficult and if there are bugs there, then I'd argue that they should be fixed.

It gets a little more complicated when people request to be able to wrap docstrings and then also heredocs that are assigned to variables, but I don't think it's impossible to keep on top of the bugs there.

But if you're wanting an extra command that does context-unaware wrapping as an if-all-else-fails case, i think there are other extensions that do that already?

yegorkryukov commented 3 years ago

But if you're wanting an extra command that does context-unaware wrapping as an if-all-else-fails case, i think there are other extensions that do that already?

Can you recommend one please? Your extension works great on comments but not on strings (or I'm not using it correctly).

What I'm trying to do is to split a long string in python using your extension like this:

'But if you are wanting an extra command that does context-unaware wrapping as an if-all-else-fails case, i think there are other extensions that do that already?'

when I hit alt + Q for this line I want it to do this:

'But if you are wanting an extra command that does context-unaware '
'wrapping as an if-all-else-fails case, i think there are other extensions '
'that do that already?'

but that doesn't happen.

Thank you!

hsandt commented 2 months ago

That would indeed fix many issues, although in the particular case of Python import, note that it doesn't work out-of-the-box: you need either a line continuation character backslash \ or brackets, see https://stackoverflow.com/questions/14376900/is-there-a-recommended-format-for-multi-line-imports