astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.14k stars 55 forks source link

Ruff in VSCode repteadly crashing on hover: The Ruff language server exited with a panic #644

Open aflip opened 4 days ago

aflip commented 4 days ago

I am working in vscode on a .ipynb notebook, and everytime my cursor hovers over any code, i get the ruff panic message as above

example of the code it crashed over

def search_and_lookup(query_vector, top_k=10):
    # Perform the search
    results = ngt_corpus_index.search(query_vector, top_k)

    # Look up the document information for each result
    enriched_results = []    
    for ngt_index, distance in results:
        # Find the corresponding document and chunk
        cumulative_count = 0
        for doc in lookup_table:
            if ngt_index < cumulative_count + doc['num_chunks']:
                chunk_id = ngt_index - cumulative_count
                enriched_results.append({
                    'ngt_index': ngt_index,
                    'distance': distance,
                    'document_id': doc['document_id'],
                    'chunk_id': chunk_id
                })
                break
            cumulative_count += doc['num_chunks']

    return enriched_results

settins.json

Ruff.log is here: It's the same message repeated.

2024-11-23 22:45:07.465 [info] Name: Ruff
2024-11-23 22:45:07.465 [info] Module: ruff
2024-11-23 22:45:07.465 [info] Python extension loading
2024-11-23 22:45:07.465 [info] Waiting for interpreter from python extension.
2024-11-23 22:45:07.465 [info] Python extension loaded
2024-11-23 22:45:07.465 [info] Using interpreter: /bin/python
2024-11-23 22:45:07.465 [info] Using bundled executable: /home/XX/.vscode-oss/extensions/charliermarsh.ruff-2024.56.0-linux-x64/bundled/libs/bin/ruff
2024-11-23 22:45:07.465 [info] Found Ruff 0.8.0 at /home/XX/.vscode-oss/extensions/charliermarsh.ruff-2024.56.0-linux-x64/bundled/libs/bin/ruff
2024-11-23 22:45:07.465 [info] Server run command: /home/XX/.vscode-oss/extensions/charliermarsh.ruff-2024.56.0-linux-x64/bundled/libs/bin/ruff server
2024-11-23 22:45:07.465 [info] Server: Start requested.
2024-11-23 23:37:34.744 [info] panicked at crates/ruff_server/src/server/api/requests/hover.rs:36:10:
hover should only be called on text documents or notebook cells

2024-11-23 23:37:34.807 [info]    0: 
2024-11-23 23:37:34.807 [info] ruff_server::server::Server::run::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::option::expect_failed
   7: <ruff_server::server::api::requests::hover::Hover as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::backtrace::__rust_begin_short_backtrace
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
  12: std::sys::pal::unix::thread::Thread::new::thread_start
  13: start_thread
             at ./nptl/pthread_create.c:447:8
  14: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

2024-11-23 23:37:35.122 [info] panicked at crates/ruff_server/src/server/api/requests/hover.rs:36:10:
hover should only be called on text documents or notebook cells
   0: ruff_server::server::Server::run::
2024-11-23 23:37:35.122 [info] {{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::option::expect_failed
   7: <ruff_server::server::api::requests::hover::Hover as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::backtrace::__rust_begin_short_backtrace
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
  12: std::sys::pal::unix::thread::Thread::new::thread_start
  13: start_thread
             at ./nptl/pthread_create.c:447:8
  14: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

2024-11-23 23:37:35.316 [info] panicked at crates/ruff_server/src/server/api/requests/hover.rs:36:10:
hover should only be called on text documents or notebook cells
   0: ruff_server::server::Server::run::{{closure}}
   1: std::panicking::rust_panic_with_hook
2024-11-23 23:37:35.316 [info] 
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::option::expect_failed
   7: <ruff_server::server::api::requests::hover::Hover as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::backtrace::__rust_begin_short_backtrace
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
  12: std::sys::pal::unix::thread::Thread::new::thread_start
  13: start_thread
             at ./nptl/pthread_create.c:447:8
  14: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

2024-11-23 23:37:37.547 [info] panicked at crates/ruff_server/src/server/api/requests/hover.rs:36:10:
hover should only be called on text documents or notebook cells
   0: ruff_server::server::Server::run::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4
2024-11-23 23:37:37.547 [info] : rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::option::expect_failed
   7: <ruff_server::server::api::requests::hover::Hover as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::backtrace::__rust_begin_short_backtrace
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
  12: std::sys::pal::unix::thread::Thread::new::thread_start
  13: start_thread
             at ./nptl/pthread_create.c:447:8
  14: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

2024-11-23 23:39:09.761 [info] panicked at crates/ruff_server/src/server/api/requests/hover.rs:36:10:
hover should only be called on text documents or notebook cells

2024-11-23 23:39:09.762 [info]    0: ruff_server::server::Server::run::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::option::expect_failed
   7: <ruff_server::server::api::requests::hover::Hover as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::backtrace::__rust_begin_short_backtrace
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
  12: std::sys::pal::unix::thread::Thread::new::
2024-11-23 23:39:09.762 [info] thread_start
  13: start_thread
             at ./nptl/pthread_create.c:447:8
  14: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

2024-11-23 23:39:12.228 [info] panicked at crates/ruff_server/src/server/api/requests/hover.rs:36:10:
hover should only be called on text documents or notebook cells
   0: ruff_server::server::Server::run::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt

2024-11-23 23:39:12.229 [info]  6: core::option::expect_failed
   7: <ruff_server::server::api::requests::hover::Hover as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::backtrace::__rust_begin_short_backtrace
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
  12: std::sys::pal::unix::thread::Thread::new::thread_start
  13: start_thread
             at ./nptl/pthread_create.c:447:8
  14: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

2024-11-23 23:41:15.697 [info] panicked at crates/ruff_server/src/server/api/requests/hover.rs:36:10:
hover should only be called on text documents or notebook cells

2024-11-23 23:41:15.698 [info]    0: ruff_server::server::Server::run::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::option::expect_failed
   7: <ruff_server::server::api::requests::hover::Hover as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::backtrace::__rust_begin_short_backtrace
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
  12: std::sys::pal::unix::thread::Thread::new::thread_start
  13: start_thread
             at ./nptl/pthread_create.c:447:8
  14: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

2024-11-23 23:42:34.445 [info] panicked at crates/ruff_server/src/server/api/requests/hover.rs:36:10:
hover should only be called on text documents or notebook cells

2024-11-23 23:42:34.445 [info]    0: ruff_server::server::Server::run::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::option::expect_failed
   7: <ruff_server::server::api::requests::hover::Hover as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::backtrace::__rust_begin_short_backtrace
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
  12: std::sys::pal::unix::thread::Thread::new::thread_start
  13: start_thread
             at ./nptl/pthread_create.c:447:8
  14: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

2024-11-23 23:41:15.697 [info] panicked at crates/ruff_server/src/server/api/requests/hover.rs:36:10:
hover should only be called on text documents or notebook cells

2024-11-23 23:41:15.698 [info]    0: ruff_server::server::Server::run::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::option::expect_failed
   7: <ruff_server::server::api::requests::hover::Hover as ruff_server::server::api::traits::BackgroundDocumentRequestHandler>::run_with_snapshot
   8: core::ops::function::FnOnce::call_once{{vtable.shim}}
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: std::sys::backtrace::__rust_begin_short_backtrace
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
  12: std::sys::pal::unix::thread::Thread::new::thread_start
  13: start_thread
             at ./nptl/pthread_create.c:447:8
  14: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
aflip commented 4 days ago

I changed the source of ruff from bundled to environment and now it's not crashing. I don't get it.

MichaReiser commented 4 days ago

This sounds similar to https://github.com/astral-sh/ruff-vscode/issues/607

I changed the source of ruff from bundled to environment and now it's not crashing. I don't get it.

Oh, that's interesting. What ruff version do you use locally (non bundled)?

Do you have a notebook that you could share that we can use for reproduction?

MichaReiser commented 4 days ago

I just tried creating a notebook with the code above and I can't get Ruff to crash when hovering. Can you tell me a bit more about your setup? What extensions are you using? What VS code version are you using? Can you share a video where you hover over a name and Ruff crashes. I wonder what I do wrong that I'm unable to reproduce.

aflip commented 3 days ago

I am unable to reproduce the bug myself. it was present all day yesterday, despite various usual interventions like restarting code, the system etc.It stopped when I switched to useenv, but it's still using the bundled ruff. Found Ruff 0.8.0 at /home/XXX/.vscode-oss/extensions/charliermarsh.ruff-2024.56.0-linux-x64/bundled/libs/bin/ruff and i am usually running the notebook from a mamba environment that doesn't have ruff so internally, nothing has changed. this is the notebook i was running https://github.com/pinecone-io/examples/blob/master/learn/generation/better-rag/02a-alt-chunking-methods.ipynb

should i mark this closed since i cant reproduce it?

MichaReiser commented 3 days ago

I don't mind keeping the issue open for a little longer. Maybe you'll be able to reproduce the bug in the coming days. I do think there's a bug in Ruff or VS Code (or in combination with some other extension), but we just have never been able to reproduce it, which makes it hard to fix.

dhruvmanila commented 3 days ago

Thanks for the issue.

As per the panic message, it should only occur when a hover request is being made by the client for the entire notebook instead of a single text document (Python file) or a notebook cell. But, the method through which is panics (DocumentQuery::as_single_document) could also return None if there's a bug in adding the cell index (NotebookDocument.cell_index field) or if the NotebookCell itself doesn't exists in the vector (NotebookDocument.cells field). If we can figure out which one is the actual cause of this issue, that can be very helpful.

I think we can update the return type of as_single_document from Option to Result in which we can capture what the source of the error is.