-
Notifications
You must be signed in to change notification settings - Fork 29.3k
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
Explore using formatters for indentation adjustment when formatters are available #19847
Comments
@borekb thanks for your detailed feedback!
Yes it should be improved
The reason that right now we don't support Reindent in ranges is that we have some issues with boundaries in embedded-language files. Some of them are just TextMate Grammar issues but I'm sure if that can fix all. Once that issue is addressed, I think it's easy to support reindent in ranges/selection. And then Reindent when paste/moveLines/etc.
It's on the plan, adding Indentation Rules to most languages we support
Nice idea! I'm thinking about a similar solution like running formatting on indentation characters and see what's the proper edits a formatter would provide. That means we run format on leading whitespaces instead of whole lines but there might be performance hit while handling large files. Really appreciate your feedback! Feedback and PRz are always welcome. |
Exactly, that's how I think about "reindenting" as a user. Technically, the two commands (formatting vs. indenting) should probably share the same logic. |
Did some basic investigation on this and I found that leveraging formatter to do indent is kind of ideal as formatters' behaviors are not predictable. Take below code as example
I obverse following:
You can see that TypeScript formatter has no idea about adjusting the indentation if don't select any thing, even though it supports Format Selection. We may need other ways to handle it as we can't force formatters to take care of indentation always. But it might be a good idea to allow formatters to provide a separate function about indentation adjustment. Any thoughts @mjbvz ? |
Any news on this? |
@borekb sorry I don't have time working on this issue this iteration but it's on my radar, I received similar issues or feedback on this every other day |
FWIW: This feature is a life-saver for me. As much as I appreciate js-beautify, it seems that it cannot be told not to mess with my white-space. Trying to format something like this:
mangles it, by trimming the white space in front of '= 7;' and thus looses the '=' alignment! Big deal and I just don't see a way to turn this behavior off. Reindent Lines seems to do whatever most other editors do, so this is the cure for me. But it is very important to have a version that works on the current selection only! |
The title is modified to one good idea proposed above: when there is a good formatter registered for a language, we should probably use the formatter other than regex based indentation rules. |
@rebornix A user of the vscode-R extension pointed out that the R formatter relies on the code being parseable. This means that ( EDIT: I read this thread more carefully and noticed that I've basically just repeated what you observed in an earlier comment: #19847 (comment) |
VSCode 1.9 introduced initial support for line indenting as per the release notes, I think it's this commit: be1b5f7. I'm very interested in this feature, big 👍 for bringing it into VSCode.
Here is some initial feedback:
Alt+Shift+F
) can already do indentation better than the new implementation, maybe it could be used as a fallback if the language doesn't have proper indentation rules.editor.action.reindentlines
, proper casing would beeditor.action.reindentLines
.The text was updated successfully, but these errors were encountered: