Open jonhoo opened 7 years ago
+1 this would be nice
This should be implemented in a C extension by customizing enter rules. We may want to update our internal C extension.
@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.
@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):
...and JavaScript does it natively (no additional extensions) for block comments:
Hope that helps!
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.
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
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.
This feature is provided by https://marketplace.visualstudio.com/items?itemName=kevinkyang.auto-comment-blocks, although disabled by default in the extension settings.
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.
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" (//
)
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).
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.
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
@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 🙌
@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.
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).
Possible dup of #180551, which is currently in the October 2023 Milestone.
It seems that this has been implemented now and is on by default. How do I turn it off?
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';
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?
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 :(
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.
Steps to Reproduce:
foo.c
)//
enter
//
(or at least this should be possible to configure). Instead, the next line is empty.