rome / tools

Unified developer tools for JavaScript, TypeScript, and the web
https://docs.rome.tools/
MIT License
23.76k stars 664 forks source link

πŸ› VS Code extension crashing on paste: "byte index 321 is out of bounds" #4297

Closed floisloading closed 1 year ago

floisloading commented 1 year ago

Environment information

CLI:
  Version:              11.0.0
  Color support:        true

Platform:
  CPU Architecture:     x86_64
  OS:                   macos

Environment:
  ROME_LOG_DIR:         unset
  NO_COLOR:             unset
  TERM:                 "xterm-256color"

Rome Configuration:
  Status:               unset

Workspace:
  Open Documents:       0

Discovering running Rome servers...

Running Rome Server: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

β„Ή The client isn't connected to any server but rage discovered this running Rome server.

Server:
  Version:              11.0.0
  Name:                 rome_lsp
  CPU Architecture:     x86_64
  OS:                   macos

Workspace:
  Open Documents:       0

Other Active Server Workspaces:

Workspace:
  Open Documents:       0
  Client Name:          Visual Studio Code
  Client Version:       1.75.1

Workspace:
  Open Documents:       2
  Client Name:          Visual Studio Code
  Client Version:       1.75.1

Workspace:
  Open Documents:       3
  Client Name:          Visual Studio Code
  Client Version:       1.76.0

Rome Server Log:

⚠ Please review the content of the log file before sharing it publicly as it may contain sensitive information:
  * Path names that may reveal your name, a project name, or the name of your employer.
  * Source code

β”œβ”€β”rome_lsp::server::initialize{params=InitializeParams { process_id: None, root_path: None, root_uri: None, initialization_options: None, capabilities: ClientCapabilities { workspace: None, text_document: None, window: None, general: None, experimental: None }, trace: None, workspace_folders: None, client_info: Some(ClientInfo { name: "rome_service", version: Some("11.0.0") }), locale: None }}
β”‚ β”œβ”€0ms INFO rome_lsp::server Starting Rome Language Server...
β”œβ”€β”˜
β”œβ”€β”rome_lsp::server::rome/rage{params=RageParams}
β”œβ”€β”˜
β”œβ”€286738966ms ERROR tower_lsp::transport failed to encode message: failed to encode response: Socket is not connected (os error 57)

What happened?

  1. we are using Storybook for Angular
  2. copied h2.stories.ts from src/app/shared/h2 to src/app/shared/voucher-active
  3. renamed file h2.stories.ts to voucher-active.stories.ts
  4. replaced H2Component with VoucherActiveBoxComponent at export default { component:
  5. copied VoucherActiveBoxComponent into clipboard
  6. pasted content of clipboard to replace H2Component in const Template: Story<H2>
  7. pasted content of clipboard to replace H2Component in (args: H2Component)
  8. VS Code Error Request textDocument/rangeFormatting failed. Source: Rome (Extension)

Console error:

[cli-stdout] data 68
[cli-stderr] end
[cli] exit 0
[cli-stderr] close
[cli-stdout] end
Connecting to "/var/folders/kd/__0vzmb92fd1f2_k_kxvyrmc0000gn/T/rome-socket-11.0.0" ...
[cli] close 0
[cli-stdout] close
[Info  - 09:12:16] Server initialized with PID: 16404
[Error - 09:12:20] Request textDocument/rangeFormatting failed.
  Message: panicked at 'byte index 321 is out of bounds of `

const Template: Story<VoucherActiveBoxComponent> = (args: VoucherActiveBoxComponent) => ({
  props: args,
  template: `
    <app-h2>
      {{ content }}
    </app-h2>
  `,
});`', crates/rome_formatter/src/source_map.rs:509:20
Backtrace: disabled backtrace
  Code: -32603 
PanicError { info: "panicked at 'byte index 321 is out of bounds of `\n\nconst Template: Story<VoucherActiveBoxComponent> = (args: VoucherActiveBoxComponent) => ({\n  props: args,\n  template: `\n    <app-h2>\n      {{ content }}\n    </app-h2>\n  `,\n});`', crates/rome_formatter/src/source_map.rs:509:20", backtrace: Some(<disabled>) }

The error is reproducible in VS Code. This error appears in many places but this is the most prominent one.

Unfortunately it's not reproducible in the playground

Expected result

Formatting on paste should work as expected, the error should not appear.

Code of Conduct

denbezrukov commented 1 year ago

Could you please update the issue template with the info coming from rome rage?

floisloading commented 1 year ago

The output of rome rage is at the top of the issue, or what do you mean?

denbezrukov commented 1 year ago

https://github.com/rome/tools/pull/4241 should fix the problem. Could you please try to reproduce on the new version? Feel free to reopen if it still reproduces

floisloading commented 1 year ago

Maybe a silly question, but where can I get the latest version? πŸ€” NPM is still at version 11.0.0 and npm i rome@next installs 0.10 or so.

Conaclos commented 1 year ago

@floisloading

npm i rome@nightly
floisloading commented 1 year ago

Works πŸ‘ thanks! πŸ™