microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.48k stars 28.64k forks source link

Continue comment when enter is pressed #26694

Open jonhoo opened 7 years ago

jonhoo commented 7 years ago

Steps to Reproduce:

  1. Open editor in a language that supports comments (say foo.c)
  2. Type a line that starts with //
  3. Press enter
  4. Next line should automatically be started with // (or at least this should be possible to configure). Instead, the next line is empty.
PradeepKumarRajamanickam commented 7 years ago

+1 this would be nice

rebornix commented 7 years ago

This should be implemented in a C extension by customizing enter rules. We may want to update our internal C extension.

daltonamitchell commented 5 years ago

@rebornix If you can point me in the right direction for where to make these changes I'm happy to submit a PR for this. I like to start new files with comments laying out the code I'm going to write, so I'd get a lot of use from this.

abettermap commented 5 years ago

@daltonamitchell I don't have any experience writing VS Code extensions, but here is a pull that implements it for Rust language. I also noticed that the Docker extension does it as well (although perhaps there is no concept of "block" comment in a Dockerfile):

docker-multiline-comment

...and JavaScript does it natively (no additional extensions) for block comments:

js-multiline-comment

Hope that helps!

tobia commented 4 years ago

Is there a way to enable this with a keybinding, for all languages?

Say, if the cursor is inside a line comment and you press enter, perform 1. enter; 2. line comment.

ctf0 commented 4 years ago

for now u can try https://marketplace.visualstudio.com/items?itemName=ctf0.auto-comment-next-line

i've also tried to use the new api for onEnterRules but it failed miserably

peey commented 4 years ago

There should be a configurable editor option to do this, if it's not default.

Very annoying to have to start comment on every line.

francoisferrand commented 4 years ago

This feature is provided by https://marketplace.visualstudio.com/items?itemName=kevinkyang.auto-comment-blocks, although disabled by default in the extension settings.

kylechadha commented 4 years ago

Thanks @Typz. Just tried it however and it doesn't work with javascript when auto-comment-blocks.singleLineBlockOnEnter is set to true (which is the behavior being requested here). Doesn't look like it's supported anymore either (last commit was 3 years ago).

This functionality is common in other editors so it'd be great to see it added to vscode as well.

katerlouis commented 2 years ago

This feature is provided by https://marketplace.visualstudio.com/items?itemName=kevinkyang.auto-comment-blocks, although disabled by default in the extension settings.

Correct me if I'm wrong, but the extension seems to only deal with comment blocks (/** */) and not with "normal comments" (//)

sbrocket commented 2 years ago

The extension mentioned above is not a suitable replacement for built-in editor support. Its last release was over 4 years ago now (September 2017) and it either doesn't work at all (with "Single Line Block on Enter" enabled) or is unacceptably slow (with that disabled and using Shift+Enter).

sbrocket commented 2 years ago

The other weird part about this is that built-in support seems to partially exist; doc comment blocks starting with /// do already get automatically continued.

valeriangalliat commented 2 years ago

The above extensions weren't working for me so I made a new one to add inline comments to onEnterRules of existing languages: https://marketplace.visualstudio.com/items?itemName=val.vscode-continue-inline-comments

abettermap commented 2 years ago

@valeriangalliat very nice! I have been wanting something like that for years. I tested it briefly with a TypeScript React file and it worked great.

I have enjoyed another great extension, Rewrap, but it does not always handle new comment lines the way I want it to when using TSDoc, for example.

Both extensions have use cases though, and therefore a place in my toolbelt, so thanks for creating it 🙌

SaltedBlowfish commented 1 year ago

@valeriangalliat

The above extensions weren't working for me so I made a new one to add inline comments to onEnterRules of existing languages: https://marketplace.visualstudio.com/items?itemName=val.vscode-continue-inline-comments

Seems to work fine for most languages, but go doesn't work. Just FYI.

brokenthorn commented 1 year ago

To get this as a built-in editor setting, or language setting, a common LSP-supported approach is probably needed. The LSP server should understand the concept of a block comment to be able to extend that block on new line if inserted before the end of the block and after the start of the block.

Perhaps the reason this has not yet been made available as an option is because it has been overlooked, or it could very well be because the LSPs implementations don't agree on a common API that would be able to provide this relatively easily.

I've never done LSP work, but from my understanding of them, it seems like this would be an LSP-centred feature.

I too would like this feature but don't know if I can find the time to learn LSP stuff (don't have too much free time right now).

starball5 commented 10 months ago

Possible dup of #180551, which is currently in the October 2023 Milestone.

cyanophage commented 5 months ago

It seems that this has been implemented now and is on by default. How do I turn it off?

katerlouis commented 5 months ago

It seems that this has been implemented now and is on by default. How do I turn it off?

I'll tell you, when you tell me how I can switch it on 8) – Seriously though, are we talking about the same here?

// when I press enter here, the next line is no comment :'(
const person = 'Homer Simpson';
tim-hilt commented 5 months ago

Same for me. I'm quite confused tbh :D @cyanophage are you sure that that's not a feature of a particular language-extension you're using?

tomasklaen commented 3 months ago

Not just continue comment, but when I press "Join lines" shortcut, it should remove the comment prefix from the joined line.

I remember having both of these in SublimeText and I still miss it even after yeas of vscode usage :(

yuezk commented 1 month ago

Not just continue comment, but when I press "Join lines" shortcut, it should remove the comment prefix from the joined line.

I remember having both of these in SublimeText and I still miss it even after yeas of vscode usage :(

You got me there! I have this feature in Vim with a comment plugin, and it's super convenient. Every time I break a long comment line or join comment lines in VS Code, I think about this feature. I assumed there might be a configuration in VS Code, and finally stumbled upon this discussion.

Hope VS Code will support this feature soon.