Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix panic in LSP formatting with multi-byte characters and trailing newlines#1391

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge5 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-1389

Conversation

Copilot
Copy link
Contributor

@CopilotCopilotAI commentedJul 11, 2025
edited
Loading

This PR fixes a panic that occurs when formatting files from VSCode if the file contains multi-byte characters (e.g.,,🐈 or Japanese characters like日本語) and ends with 2+ newlines.

Problem

The panic occurred in thePositionToLineAndCharacter function ininternal/ls/converters.go when trying to slice text with bounds[start:position] whereposition could exceed the actual text length:

panic: runtime error: slice bounds out of range [:10] with length 9

Root Cause

When the formatter generates text edits for files with multi-byte characters and trailing newlines, it can create ranges that extend beyond the actual text length. ThePositionToLineAndCharacter function didn't handle this case properly, leading to a "slice bounds out of range" panic.

Solution

Added a bounds check to ensure thatposition never exceeds the actual text length before attempting to slice the text:

// Ensure position doesn't exceed text length to avoid slice bounds errorstext:=script.Text()textLen:=core.TextPos(len(text))position=min(position,textLen)

This ensures that even if the formatter or other components pass positions beyond the text length, the converter will handle them gracefully by treating them as positions at the end of the text.

Testing

  • Added comprehensive tests that specifically reproduce the original issue
  • Verified the fix handles positions at and beyond text length
  • Added a specific test case for the exact scenario from the issue
  • All existing tests continue to pass

The fix is minimal, safe, and maintains backward compatibility while resolving the panic.

Fixes#1389.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Clickhere to start the survey.

CopilotAIand others added2 commitsJuly 11, 2025 17:19
…ewlinesCo-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@CopilotCopilotAI changed the title[WIP] lsp(vscode): panic when formatting a file with multi-byte characters and trailing 2+ newlinesFix panic in LSP formatting with multi-byte characters and trailing newlinesJul 11, 2025
@CopilotCopilotAI requested a review fromjakebaileyJuly 11, 2025 17:24
Copilot finished work on behalf ofjakebaileyJuly 11, 2025 17:24
@jakebailey
Copy link
Member

Delete all of the compiler tests; they are not needed for editor related PRs.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@CopilotCopilot SWE Agent
Copy link
ContributorAuthor

Delete all of the compiler tests; they are not needed for editor related PRs.

Done. All compiler tests have been removed from the PR. The language server tests remain as they are appropriate for testing the LSP formatting fix. (0f6e9fc)

Copilot finished work on behalf ofjakebaileyJuly 11, 2025 17:36
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@CopilotCopilotAI requested a review fromjakebaileyJuly 11, 2025 17:45
Copilot finished work on behalf ofjakebaileyJuly 11, 2025 17:45
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jakebaileyjakebaileyAwaiting requested review from jakebailey

At least 1 approving review is required to merge this pull request.

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

lsp(vscode): panic when formatting a file with multi-byte characters and trailing 2+ newlines
2 participants
@Copilot@jakebailey

[8]ページ先頭

©2009-2025 Movatter.jp