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

Server doesn't sync cell content if copy-pasted directly #12201

Closed
matrs opened this issue Jul 3, 2024 · 5 comments · Fixed by #12203
Closed

Server doesn't sync cell content if copy-pasted directly #12201

matrs opened this issue Jul 3, 2024 · 5 comments · Fixed by #12203
Assignees
Labels
bug Something isn't working server Related to the LSP server

Comments

@matrs
Copy link

matrs commented Jul 3, 2024

I've been using the ruff server the last days without problems (for linting and formatting), and suddenly this message appeared in vscode:

The Ruff language server exited with a panic. See the logs for more details.

I'm not aware of doing any different when it happened, just editing code, notebooks and scripts (ruff is configured to recognize .ipynb too).
I'm using ruff 0.5.0 , vscode 1.90.2 and extension ruff-2024.30. My Linux is 6.6.32-1-MANJARO.

2024-07-02 16:06:46.430 [info] Server: Start requested.
2024-07-02 16:07:23.830 [info] Name: Ruff
2024-07-02 16:07:23.830 [info] Module: ruff
2024-07-02 16:07:23.830 [info] Python extension loading
2024-07-02 16:07:23.830 [info] Waiting for interpreter from python extension.
2024-07-02 16:07:23.830 [info] Python extension loaded
2024-07-02 16:07:23.830 [info] Server run command: ~/.vscode/extensions/charliermarsh.ruff-2024.30.0-linux-x64/bundled/tool/ruff_server.py server --preview
2024-07-02 16:07:23.830 [info] Server: Start requested.
2024-07-03 12:20:55.252 [info] panicked at crates/ruff_source_file/src/line_index.rs:176:13:
index out of bounds: the len is 1 but the index is 2

2024-07-03 12:20:55.253 [info]    0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>

2024-07-03 12:22:55.296 [info] panicked at crates/ruff_source_file/src/line_index.rs:176:13:
index out of bounds: the len is 1 but the index is 2
   0: <unknown>
   1: <unknown>
   2: <unknown>
   
2024-07-03 12:22:55.297 [info] 3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>

Then I tried to restart the server from the command palette, which worked after the second time:

2024-07-03 12:31:16.160 [info] Server: Stop requested
2024-07-03 12:31:16.178 [info] Server run command: /home/mibu/miniconda3/envs/scrapped/bin/python /home/mibu/.vscode/extensions/charliermarsh.ruff-2024.30.0-linux-x64/bundled/tool/ruff_server.py server --preview
2024-07-03 12:31:16.180 [info] Server: Start requested.
2024-07-03 12:31:16.211 [info] panicked at /home/conda/feedstock_root/build_artifacts/ruff_1719517977307/_build_env/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jod-thread-0.1.2/src/lib.rs:21:21:
called `Result::unwrap()` on an `Err` value: Any { .. }
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>

panicked at /home/conda/feedstock_root/build_artifacts/ruff_1719517977307/_build_env/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jod-thread-0.1.2/src/lib.rs:33:22:
called `Result::unwrap()` on an `Err` value: Any { .. }
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: __libc_start_main
  18: <unknown>


2024-07-03 12:31:47.637 [info] Server: Stop requested
2024-07-03 12:31:47.657 [info] Server run command: /home/mibu/miniconda3/envs/scrapped/bin/python /home/mibu/.vscode/extensions/charliermarsh.ruff-2024.30.0-linux-x64/bundled/tool/ruff_server.py server --preview
2024-07-03 12:31:47.658 [info] Server: Start requested.
@dhruvmanila
Copy link
Member

That's unfortunate. Are you able to reproduce this reliably? If so, will you be able to share the source code on which this panic occurs? Is it occurring in Python file or Jupyter Notebook or either? I suspect it might be occurring in the offset_to_source_location function (

fn offset_to_source_location(
offset: TextSize,
text: &str,
index: &LineIndex,
encoding: PositionEncoding,
) -> SourceLocation {
) although not sure.

@MichaReiser MichaReiser added the server Related to the LSP server label Jul 4, 2024
@matrs
Copy link
Author

matrs commented Jul 4, 2024

i cannot reproduce it consistently, but sometimes, when i copy (c) and paste a cell (v ) with a ruff warning it it, this happens immediately . What is consistent, it that when I copy a cell that have a ruff warning in it (e.g: line too long), this warning isn't present in the copied cell, and i think this may be related to this error. From a fresh start of the server, this copied cell does have the same warning as the source cell, but it never has it if i don't restart the notebook/
ruff server.

@matrs
Copy link
Author

matrs commented Jul 4, 2024

So, i think this may be reproducible. If ones copies this text into a new cell in a new notebook, then copy that cell (copy the whole cell with c, not only copy the text), the new pasted cell won't have the ruff warning in it, and once one hover over that line (or maybe other lines of the copied cell), the server crushes.

qidxs = [9926, 8184, 12563, 6998]
for brand, stores_vcomps_d in all_brand_stores_vcomps.items():
    for store, vcomps_dict in stores_vcomps_d.items():
        for qidx, vcomps in vcomps_dict.items():
            if qidx in qidxs:
                print(f"{brand=}, {store=}, {qidx=}")
                plot_vcomps_dict(vcomps_dict, qidx, embs_all, w_h=(2, 3)) # long line so ruff complains

so when i do the same copy-paste cell with a cell like this , crushes:

var = 33
var2 = 55
long_string = 'ASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDA'

but with a cell like this , it doesn't seem to crush:

long_string = 'ASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDAASADAADDA'

@dhruvmanila
Copy link
Member

Thank you for providing the details. I can reproduce this.

@dhruvmanila dhruvmanila added the bug Something isn't working label Jul 5, 2024
@dhruvmanila
Copy link
Member

Ok, I think I found the root cause. It's definitely a bug. Thank you for raising this issue!

@dhruvmanila dhruvmanila self-assigned this Jul 5, 2024
@dhruvmanila dhruvmanila changed the title The Ruff language server exited with a panic Server doesn't sync cell content if copy-pasted directly Jul 5, 2024
@dhruvmanila dhruvmanila transferred this issue from astral-sh/ruff-vscode Jul 5, 2024
@dhruvmanila dhruvmanila added this to the Ruff Server: Stable milestone Jul 5, 2024
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