Skip to content

Fixed a formatting crash on comments inside blocks starting on first line#2793

Open
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Andarist:fix/format-crash-comment-in-block-first-line
Open

Fixed a formatting crash on comments inside blocks starting on first line#2793
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Andarist:fix/format-crash-comment-in-block-first-line

Conversation

@Andarist
Copy link
Contributor

fixes #2649

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a panic in the LSP formatter that occurred when formatting JavaScript/TypeScript files containing comments inside blocks that start on the first line (e.g., arrow function bodies). The panic was caused by passing a negative indentation value (-1) to strings.Repeat().

Changes:

  • Added a check to prevent passing -1 indentation values to indentTriviaItems
  • Added regression tests for both multiline JSDoc comments and single-line comments in the problematic scenario

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/format/span.go Added guard to check if commentIndentation is -1 before calling indentTriviaItems, preventing the panic
internal/format/comment_test.go Added two regression tests verifying that formatting doesn't panic for comments inside blocks starting on first line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP Panic: strings: negative Repeat count when formatting JSDoc within nested scope

1 participant