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

Panic Error in Python with Pyright/Pylsp & Ruff #10689

Open
thebraingen opened this issue May 5, 2024 · 5 comments
Open

Panic Error in Python with Pyright/Pylsp & Ruff #10689

thebraingen opened this issue May 5, 2024 · 5 comments
Labels
A-language-server Area: Language server client C-bug Category: This is a bug

Comments

@thebraingen
Copy link

Summary

Had the same error happen using Pylsp.
Here is my languages.toml for python:

# PYTHON
[[language]]
name = "python"
language-servers = [ "ruff-lsp", "pyright" ]
auto-format = true

[language-server.pyright.config.python.analysis]
typeCheckingMode = "basic"

[language-server.ruff-lsp]
command = "ruff-lsp"

[language-server.ruff-lsp.config.settings]
args = ["--ignore", "E501"]

[language.formatter]
command = "ruff"
args = ["format", "-"]
MOV.to.MP4.conversion.mp4

Reproduction Steps

I tried this:

  1. hx main.py
  2. Use any function
  3. Try to read the documentation inline (without using <space>-K), coming back & forth ~3 times

I expected this to happen:

  • Be able to continue/read without a crash
    Instead, this happened:
  • Crashes (does not happen if I am using Rust, only has happened to me with Python)

Helix log

RUST_BACKTRACE=1 ``` hx . thread 'main' panicked at 'Attempt to slice past end of RopeSlice: slice end 202, RopeSlice length 201', /Users/brain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ropey-1.6.1/src/slice.rs:656:9 stack backtrace: 0: _rust_begin_unwind 1: core::panicking::panic_fmt 2: ropey::slice::RopeSlice::slice 3: helix_lsp::util::generate_transaction_from_completion_edit 4: helix_term::ui::completion::Completion::new::{{closure}}::item_to_transaction 5: helix_term::ui::completion::Completion::new::{{closure}} 6: as helix_term::compositor::Component>::handle_event 7: as helix_term::compositor::Component>::handle_event 8: ::handle_event 9: helix_term::compositor::Compositor::handle_event 10: helix_term::application::Application::run::{{closure}} 11: tokio::runtime::park::CachedParkThread::block_on 12: tokio::runtime::context::runtime::enter_runtime 13: tokio::runtime::runtime::Runtime::block_on 14: hx::main note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.```
~/.cache/helix/helix.log ``` 2024-05-05T15:12:06.671 helix_lsp::transport [ERROR] ruff-lsp err <- "Ignoring notification for unknown method \"workspace/didChangeConfiguration\"\n" 2024-05-05T15:12:12.560 helix_lsp::transport [ERROR] ruff-lsp err <- "Ignoring notification for unknown method \"workspace/didChangeConfiguration\"\n" 2024-05-05T15:12:47.351 helix_lsp::transport [ERROR] ruff-lsp err <- "Ignoring notification for unknown method \"workspace/didChangeConfiguration\"\n" 2024-05-05T15:13:17.618 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(14)), original request likely timed out 2024-05-05T15:13:46.147 helix_lsp::transport [ERROR] ruff-lsp err: <- StreamClosed 2024-05-05T15:13:46.147 helix_lsp [ERROR] client was already removed 2024-05-05T15:13:46.149 helix_lsp::transport [ERROR] pyright err: <- StreamClosed 2024-05-05T15:13:46.149 helix_lsp [ERROR] client was already removed 2024-05-05T15:13:46.364 helix_lsp::transport [ERROR] ruff-lsp err <- "Ignoring notification for unknown method \"workspace/didChangeConfiguration\"\n" 2024-05-05T15:14:59.807 helix_lsp::transport [ERROR] ruff-lsp err <- "Ignoring notification for unknown method \"workspace/didChangeConfiguration\"\n" 2024-05-05T15:15:08.013 helix_lsp::util [WARN] LSP position Position { line: 13, character: 0 } out of range assuming EOF ```

Platform

macOS

Terminal Emulator

Warp

Installation Method

source

Helix Version

helix 24.3 (cfca308)

@thebraingen thebraingen added the C-bug Category: This is a bug label May 5, 2024
@thebraingen thebraingen changed the title Panic Error with Pyright & Ruff Panic Error in Python with Pyright/Pylsp & Ruff May 5, 2024
@the-mikedavis the-mikedavis added the A-language-server Area: Language server client label May 6, 2024
@the-mikedavis
Copy link
Member

Looking at the backtrace I believe one of the language servers is sending us a range for the completion item that is beyond the end of the document and we need to handle that case when turning completion items into transactions.

@thebraingen
Copy link
Author

thebraingen commented May 8, 2024

Looking at the backtrace I believe one of the language servers is sending us a range for the completion item that is beyond the end of the document and we need to handle that case when turning completion items into transactions.

Yes.
Python is relatively unusable with helix using the main branch. Can't use any language server without it being unstable.
Had to go back to 2cadec0

@thebraingen
Copy link
Author

For some reason, it is fixed and working as-expected if instead of doing :

 fn find_completion_range(text: RopeSlice, replace_mode: bool, cursor: usize) -> (usize, usize) {
        let start = cursor
            - text
                .chars_at(cursor)
                .reversed()
                .take_while(|ch| chars::char_is_word(*ch))
                .count();
        let mut end = cursor;
        if replace_mode {
            end += text
                .chars_at(cursor)
                .skip(1)
                .take_while(|ch| chars::char_is_word(*ch))
                .count()
                + 1;
        }
        (start, end)
    }

as was changed in #10279
We take out the + 1 and leave it as-is.

 fn find_completion_range(text: RopeSlice, replace_mode: bool, cursor: usize) -> (usize, usize) {
        let start = cursor
            - text
                .chars_at(cursor)
                .reversed()
                .take_while(|ch| chars::char_is_word(*ch))
                .count();
        let mut end = cursor;
        if replace_mode {
            end += text
                .chars_at(cursor)
                .skip(1)
                .take_while(|ch| chars::char_is_word(*ch))
                .count();
        }
        (start, end)
    }

I have tested extensively using JS/TS, Rust & Python. This fixes the main issue that was happening before.
Note, however, that I previously had only experienced the crashes using Python.


There still is an ongoing issue where in Python the next-line gets concatenated to the current line and the next-line's first element (-1) gets replaced if doing an autocomplete, only when using Python. See video:

Screen.Recording.2024-05-15.at.2.32.32.PM.mov
  • as you can see it doesn't replace a but it does replace print excluding the t

Might be worth investigating. I'm playing around with the codebase but I have just now started to get a little bit more familiar with it. @the-mikedavis

@kirawi
Copy link
Member

kirawi commented May 19, 2024

There still is an ongoing issue where in Python the next-line gets concatenated to the current line and the next-line's first element (-1) gets replaced if doing an autocomplete, only when using Python.

Was this when you ran master?

@thebraingen
Copy link
Author

There still is an ongoing issue where in Python the next-line gets concatenated to the current line and the next-line's first element (-1) gets replaced if doing an autocomplete, only when using Python.

Was this when you ran master?

Yes, on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

3 participants