zed icon indicating copy to clipboard operation
zed copied to clipboard

"g q" doesn't respect leading asterisks in doc comments in TypeScript

Open yseymour opened this issue 7 months ago • 10 comments

Summary

In a TypeScript file, when wrapping comment text in a doc comment (/** .. */) using g q or g q q, the leading asterisks are not inserted as necessary.

Given this block of code:

/**
 * Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.  Here's some text.
 */
function foo() {}

Actual result Placing the cursor on line 2 and typing g q q results in this:

/**
 * Here's some text. Here's some text. Here's some text. Here's some text.
 Here's some text. Here's some text. Here's some text. Here's some text. Here's
 some text. Here's some text. Here's some text. Here's some text. Here's some
 text. Here's some text. Here's some text. Here's some text. Here's some text.
 Here's some text. Here's some text. Here's some text.
 */
function foo() {}

Expected result: VSCodeVim produces

/**
 * Here's some text.  Here's some text.  Here's some text.  Here's some text.
 * Here's some text.  Here's some text.  Here's some text.  Here's some text.
 * Here's some text.  Here's some text.  Here's some text.  Here's some text.
 * Here's some text.  Here's some text.  Here's some text.  Here's some text.
 * Here's some text.  Here's some text.  Here's some text.  Here's some text.
 */
function foo() {}

I'm filing this as a bug since it seems to be unique to block/doc comments in TS. Double-slash comments get wrapped correctly (as do triple-slash comments in Rust files).

Possibly/possibly not related: when extend_comment_on_newline is enabled, pressing Return within a TS doc comment doesn't insert the leading asterisk. Triple-slashes in Rust files get inserted correctly.

Zed Version and System Specs

Zed: v0.180.2 (Zed) OS: macOS 15.3.2 Memory: 64 GiB Architecture: aarch64

yseymour avatar Apr 04 '25 02:04 yseymour

I believe this has been fixed by:

  • https://github.com/zed-industries/zed/pull/30800

And will be available in Zed Preview tomorrow. Thanks for reporting.

notpeter avatar May 20 '25 14:05 notpeter

@notpeter, @smitbarmase Saw this in the release notes for 0.188.3. Trying it both in Preview 0.189.2 and regular Zed 0.188.4. I don't see any change in behaviour. There's no automatic asterisk insertion in any .js or .ts files, whether remote or local, and g q still works the way it does in my original report. I do get // insertion on a newline, so the extend_comment_on_newline setting is definitely on. Is there something else that needs to be enabled?

yseymour avatar May 30 '25 02:05 yseymour

I see. I'm reopening this as mentioned PR only adds the ability to add asterisks on new lines and not when wrapping text, which you are trying to achieve.

smitbarmase avatar May 30 '25 02:05 smitbarmase

Thanks. FWIW, I'm not getting the asterisks on new lines either.

yseymour avatar May 30 '25 02:05 yseymour

Are you using Vim to add new line?

smitbarmase avatar May 30 '25 12:05 smitbarmase

Are you using Vim to add new line?

I've tried with and without vim mode.

yseymour avatar Jun 02 '25 00:06 yseymour

Can you provide a video reproducing it? It is working just fine for me. Maybe certain edge cases we are not taking into consideration.

smitbarmase avatar Jun 02 '25 00:06 smitbarmase

https://github.com/user-attachments/assets/f0f3e000-0c95-4a10-9c11-85ab0264a8ef

yseymour avatar Jun 02 '25 01:06 yseymour

Strange. Can you provide your settings.json?

smitbarmase avatar Jun 02 '25 04:06 smitbarmase

I've narrowed it down a bit. Thanks for bearing with me.

  • Asterisk insertion only works when use_autoclose is true. I usually have this disabled.
  • Once use_autoclose is enabled, the insertion only happens (for me) when pressing Enter. It doesn't work when the line is added with o or O in Vim mode.

For double-slash comments, the // gets inserted regardless of the value of use_autoclose, and it works when o/O are used as well. That's why I was surprised the asterisk insertion feature doesn't work the same way.

yseymour avatar Jun 02 '25 04:06 yseymour