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

fix(47923): Delete unused JSDoc quick fix changes formatting on rest of JSDoc comment #48482

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MQuy
Copy link
Contributor

@MQuy MQuy commented Mar 30, 2022

Fixes #47923

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Mar 30, 2022
@MQuy MQuy changed the title fix(47923): Delete unused JSDoc quick fix changes formatting on rest of JSDoc comment fix(47923): WIP - Delete unused JSDoc quick fix changes formatting on rest of JSDoc comment Mar 30, 2022
@MQuy MQuy changed the title fix(47923): WIP - Delete unused JSDoc quick fix changes formatting on rest of JSDoc comment fix(47923): Delete unused JSDoc quick fix changes formatting on rest of JSDoc comment Mar 30, 2022
@MQuy MQuy marked this pull request as draft March 30, 2022 22:30
@RyanCavanaugh RyanCavanaugh requested a review from rbuckton March 31, 2022 22:18
@MQuy MQuy marked this pull request as ready for review March 31, 2022 22:57
const line = lines[lineIndex];
if (lineIndex === 0) {
if (line.length > 0) {
writeSpace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this space make sense when the comment is the only thing in the jsdoc? eg

/**
 * commentary 1
 * commentary 2
 */
var x;

It looks like it might not emit the * as expected for the commentary 1 line, or else emit an extra space on the line right after the **.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks the same before and after my change
VS Code
image

VS Code with my changes
image

@@ -8183,6 +8195,21 @@ namespace ts {
else if (comments.length) {
return comments.join("");
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to move these down here or add newlines between them.

*/
// to check tag starting newline without comments like above
// it needs to actually encounter a newline
if (states.length === 1 && lookAhead(() => nextTokenJSDoc() !== SyntaxKind.NewLineTrivia)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing ever uses or pops from states; the only read is to check that states.length === 1. It should be a boolean instead, maybe called isFirstLine? That's a guess from reading the code.

indent += 1;
break;
}
// record the * as a comment
// falls through
default:
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what the parser changes do and why they're needed?

From reading the code, it looks like states is added to know when to call removeTrailingWhitespace, and the change in tryParseTypeExpression now doesn't skip whitespace when a parse fails, but I don't understand the intent of shuffling whitespace parsing around.

Copy link
Contributor Author

@MQuy MQuy Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like you mentioned

  • tryParseTypeExpression doesn't skip whitespace when a parse fails
/*
 * @param b  // <- there is no type expression, it rollback to this position
 * 
 * something here
 */
  • parseTagComments only remove whitespace for these two cases
/*
* @param x
* in the first line
*/

/*
* @param x
still in the first line
*/

we can not do it at the end like we are currently doing since it is too late because there is a case with {@link} will reset comments

I don't really get what you mean by I don't understand the intent of shuffling whitespace parsing around, can you explain about it? 😄

@@ -129,22 +129,22 @@ verify.quickInfos({
3: ["(parameter) param1: string", "first line of param\n\nparam information third line"],

g: ["function g(param1: string): void", "This is firstLine\nThis is second Line"],
4: ["(parameter) param1: string", " param information first line"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the old output better; @param is supposed to set a margin so that the space is preserved in param information first line. Preserving the newlines too is OK, depending on how it looks when formatted in VS Code.

This is true of all the changes below.

Copy link
Contributor Author

@MQuy MQuy Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current VSCode version
image
image
image

VS Code with my changes
image
image
image

For the the later looks better 😄


k: ["function k(param1: string): void", "This is firstLine\nThis is second Line"],
8: ["(parameter) param1: string", "hello"],

l: ["function l(param1: string): void", "This is firstLine\nThis is second Line"],
9: ["(parameter) param1: string", "first Line text\nblank line that shouldnt be shown when starting this \nsecond time information about the param again"],
9: ["(parameter) param1: string", "first Line text\n\n\nblank line that shouldnt be shown when starting this \nsecond time information about the param again"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent of the test is to not show the blank lines. I think you're trying to preserve them now, so the text of the test should change to show the changed intent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Waiting on reviewers
Development

Successfully merging this pull request may close these issues.

Delete unused JSDoc quick fix changes formatting on rest of JSDoc comment
4 participants