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 all" code action on notebook causes panic with multi-byte character #12880

Closed
sato1214syun opened this issue Aug 14, 2024 · 5 comments · Fixed by #12929
Closed

"Fix all" code action on notebook causes panic with multi-byte character #12880

sato1214syun opened this issue Aug 14, 2024 · 5 comments · Fixed by #12929
Assignees
Labels
bug Something isn't working server Related to the LSP server

Comments

@sato1214syun
Copy link

  • List of keywords you searched for before creating this issue. Write them down here so that others can find this issue more easily and help provide feedback.
    keywords: panic, Q000

  • A minimal code snippet that reproduces the bug.
    test.zip

  • The command you invoked (e.g., ruff /path/to/file.py --fix), ideally including the --isolated flag.
    Implemented formatOnSave of VSCode for notebook

  • The current Ruff settings (any relevant sections from your pyproject.toml).
    ruff.toml.zip

  • The current Ruff version (ruff --version).
    ruff 0.5.7
    ruff vscode extension v2024.40.0

Eror message

2024-08-14 15:23:07.676 [info] panicked at crates/ruff_server/src/edit/range.rs:196:39:
byte index 161 is not a char boundary; it is inside 'あ' (bytes 159..162) of `"""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."""
'あaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`[...]

2024-08-14 15:23:07.678 [info]    0: std::backtrace::Backtrace::force_capture
   1: ruff_server::server::Server::
2024-08-14 15:23:07.678 [info] run
   2: std::panicking::rust_panic_with_hook
   3: <std::panicking::begin_panic_handler::StaticStrPayload as core::panic::PanicPayload>::take_box
   4: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   5: _rust_begin_unwind
   6: core::panicking::panic_fmt
   7: core::str::slice_error_fail_rt
   8: core::str::slice_error_fail
   9: <ruff_server::server::api::Error as core::fmt::Display>::fmt
  10: 
2024-08-14 15:23:07.678 [info] <ruff_text_size::range::TextRange as ruff_server::edit::range::ToRangeExt>::to_range
  11: ruff_server::edit::text_document::TextDocument::apply_changes
  12: <ruff_server::server::api::requests::code_action_resolve::CodeActionResolve as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
  13: <ruff_server::server::api::requests::code_action_resolve::CodeActionResolve as ruff_server
2024-08-14 15:23:07.678 [info] ::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
  14: <ruff_server::session::capabilities::ResolvedClientCapabilities as core::fmt::Display>::fmt
  15: <ruff_server::server::api::requests::diagnostic::DocumentDiagnostic as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
  16: <ruff_server::server::api::requests::diagnostic::DocumentDiagnostic as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
  17: <ruff_server::server::api
2024-08-14 15:23:07.679 [info] ::requests::diagnostic::DocumentDiagnostic as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
  18: std::sys::pal::unix::thread::Thread::new
  19: __pthread_joiner_wake
@dhruvmanila
Copy link
Member

(I'll look into this in some time.)

@MichaReiser MichaReiser added bug Something isn't working server Related to the LSP server labels Aug 14, 2024
@dhruvmanila
Copy link
Member

Thank you for providing all the details. Although, I'm unable to reproduce this panic. Can you provide your VS Code settings? By "formatOnSave", do you mean notebook.formatOnSave.enabled setting?

@sato1214syun
Copy link
Author

Thank you @dhruvmanila for investigating. It happens when I press "command + s" or implement "Ruff: fix all auto-fixable problems" in command palette.

Environment:
M1 mac
MacOS 14.5
vscode version 1.92.1

My vscode profile for python is below.

{
  // python
  "python.analysis.autoFormatStrings": true,
  "python.analysis.gotoDefinitionInStringLiteral": true,
  "python.analysis.inlayHints.callArgumentNames": "partial",
  "python.analysis.inlayHints.functionReturnTypes": true,
  "python.analysis.inlayHints.pytestParameters": true,
  "python.analysis.inlayHints.variableTypes": true,
  "python.languageServer": "Pylance",
  // ruff
  "[python]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "charliermarsh.ruff",
    "editor.codeActionsOnSave": {
      "source.fixAll": "explicit",
      "source.organizeImports.": "explicit",
    },
  },
  "notebook.formatOnCellExecution": true,
  "notebook.formatOnSave.enabled": true,
  "notebook.codeActionsOnSave": {
    "notebook.source.fixAll": "explicit",
    "notebook.source.organizeImports": "explicit",
  },
  // jupyter
  "jupyter.askForKernelRestart": false,
  "jupyter.interactiveWindow.creationMode": "perFile",
  // other extension
  "markdown.extension.math.enabled": false,
  "git.suggestSmartCommit": false,
  "workbench.colorTheme": "Default Dark+",
  "github.copilot.editor.enableAutoCompletions": true,
  "editor.fontFamily": "\"Bizin Gothic Discord NF\", Menlo, Monaco, 'Courier New', monospace",
  "workbench.editorAssociations": {
    "{git,gitlens}:/**/*.{md,csv,svg}": "default"
  },
  "autoDocstring.docstringFormat": "numpy",
  "dataWrangler.enabledFileTypes": {
    "csv": false,
    "tsv": false
  },
}

@dhruvmanila
Copy link
Member

Thanks for providing the details. I can reproduce it using the "Fix all" code action.

@dhruvmanila dhruvmanila changed the title formatOnSave on notebook causes panic with code including multi-byte character, specific code length and Q000 "Fix all" code action on notebook causes panic with code including multi-byte character Aug 16, 2024
@dhruvmanila dhruvmanila changed the title "Fix all" code action on notebook causes panic with code including multi-byte character "Fix all" code action on notebook causes panic with multi-byte character Aug 16, 2024
@dhruvmanila
Copy link
Member

dhruvmanila commented Aug 16, 2024

It doesn't occur when performing the action via the command-line (ruff check --fix) so it must be in this function (<ruff_text_size::range::TextRange as ruff_server::edit::range::ToRangeExt>::to_range)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants