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

formatOnType only works with semicolon for clang-format #1419

Open
Gruntfuggly opened this issue Jan 8, 2018 · 12 comments
Open

formatOnType only works with semicolon for clang-format #1419

Gruntfuggly opened this issue Jan 8, 2018 · 12 comments

Comments

@Gruntfuggly
Copy link

"editor.formatOnType: true" doesn't seem to work for me. I did a bit of digging and I couldn't find anywhere that sets the firstTriggerCharacter or moreTriggerCharacter to anything specific, so I was wondering if it's implemented?

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Jan 9, 2018

Format on type only works for ";" -- which isn't particularly useful. Ideally we would add support for additional characters like "(", "{", ")", "}" (not really sure which). The trigger characters are set in the extension process. I'm not sure if we already have an issue tracking that. I could mark this as a feature request if you want.

@Gruntfuggly
Copy link
Author

Formatting when pressing Enter would be good too.

@sean-mcmanus
Copy link
Contributor

Adding formatting on Enter is problematic with our given implementation using clang-format. The problem is that you often want to use Enter to add whitespace, but then formatting gets run on Enter and deletes the whitespace.

@kylegmaxwell
Copy link

If the user hits enter, I think it would make more sense to format the last line that they were on, not the new line that is created, since that line will usually be blank. If it is not blank then format both lines.
For example, the user types:
do->something( );<enter>
Which results in:
do->something();
<cursor>
Also, probably more useful would be to format all lines showing modified by source control on save, but I did not see a preference for that.

@Gruntfuggly
Copy link
Author

I wrote an extension to format modified lines, but there's actually a bug in clang-format which means that you can't actually format a single line. If you specified a range of characters within a line, or a line range of only one line, it insists on formatting the line and the next one. 8-(

@bobbrow
Copy link
Member

bobbrow commented Feb 20, 2018

@kylegmaxwell for your second request, does editor.formatOnSave do what you want?

image

@kylegmaxwell
Copy link

@bobbrow Unfortunately not. I tried that and it updated the whole file. I am working on a large code base where that is undesirable when I make a small change to a file. I am happy to file a separate feature request if that would be helpful.

@bobbrow
Copy link
Member

bobbrow commented Feb 20, 2018

@kylegmaxwell you might want to file that request with the VS Code team. Our extension could potentially roll out an implementation for it, but it would be great if all languages could take advantage of it.

@escape0707
Copy link

escape0707 commented Aug 13, 2020

EDIT: moved to #5962

@bobbrow
Copy link
Member

bobbrow commented Aug 13, 2020

@escape0707 I moved your comment to a new issue.

@sean-mcmanus
Copy link
Contributor

@github-actions github-actions bot modified the milestones: Triage, Backlog Oct 18, 2020
@github-actions
Copy link

This feature request has received enough votes to be added to our backlog.

@bobbrow bobbrow changed the title Does formatOnType work? formatOnType only works with semicolon for clang-format Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants