Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Server panics when code contains CJK characters #13674

Closed
HusuSama opened this issue Oct 8, 2024 · 15 comments · Fixed by #14010
Closed

Server panics when code contains CJK characters #13674

HusuSama opened this issue Oct 8, 2024 · 15 comments · Fixed by #14010
Labels
bug Something isn't working server Related to the LSP server

Comments

@HusuSama
Copy link

HusuSama commented Oct 8, 2024

When I use Click, errors occur. I'm not sure if it's because of my Chinese comments or the decorators.

log:
图片

code:
图片

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

@HusuSama Sorry, somehow I missed this. Can you provide the code content as text instead of an image? I can copy paste that and try to reproduce it. Additionally, can you provide the Ruff config if it's being used here (both server settings and Ruff configuration)?

@dhruvmanila dhruvmanila changed the title When I use click, it causes a panic. Server panics when code contains CJK characters Oct 25, 2024
@HusuSama
Copy link
Author

HusuSama commented Oct 28, 2024

Thank you for noticing the issue I raised. I haven't made any additional configurations for Ruff, and I'm using the AstroNvim configuration. Here is the configuration content: AstroNvim's Ruff Configuration.

I can't fully pinpoint this issue; it seems to be random. It tends to occur more frequently when I add Chinese comments at the top, and the usage is very unstable. I'm also not quite sure if it's an issue with my Neovim configuration. By the way, I use Tab for code completion.

my code:

"""
测试comment
一些测试内容
"""

import click


@click.group()
def interface():
    pass


@interface.command()
def test():
    click.echo("hello")


if __name__ == "__main__":
    interface()

@dhruvmanila
Copy link
Member

Thanks! I've a couple of questions:

  1. Can you describe the scenario which produces the panic? It could be like something you clicked, requested the server for something (like hover request), while typing etc.
  2. What's the Ruff version that is being used here?
  3. Can you provide debug logs for the server? I'm not sure how to set the config for AstroNvim but for lsp-config you can refer to the end of this section in the docs.

@dhruvmanila dhruvmanila added needs-mre Needs more information for reproduction and removed bug Something isn't working labels Oct 28, 2024
@HusuSama
Copy link
Author

  1. I suspect that the issue might be related to my code completion settings. When I use TAB to automatically select the first code suggestion, this error occurs. However, if I first move the cursor and then use TAB to select, the error does not appear.
    图片
    图片

  2. ruff version
    图片

  3. I only have the LSP error log

[START][2024-10-29 09:10:40] LSP logging initiated
[ERROR][2024-10-29 09:10:40] ...lsp/handlers.lua:623    "Notification workspace/didChangeConfiguration defines parameters by name but received parameters by position"
[ERROR][2024-10-29 09:10:40] ...lsp/handlers.lua:623    "Notification workspace/didChangeConfiguration defines 1 params but received 0 arguments"
[ERROR][2024-10-29 09:11:05] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        'panicked at crates/ruff_server/src/edit/range.rs:68:71:\nbyte index 96 is out of bounds of `"""\n测试comment\n一些测试内容\n"""\nimport click\n\n@click.group()\ndef interface():\n    pas\n`\n'
[ERROR][2024-10-29 09:11:05] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   "
[ERROR][2024-10-29 09:11:05] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "0: ruff_server::server::Server::run::{{closure}}\n   1: std::panicking::rust_panic_with_hook\n   2: std::panicking::begin_panic_handler::{{closure}}\n   3: std::sys::backtrace::__rust_end_short_backtrace\n   4: rust_begin_unwind\n   5: core::panicking::panic_fmt\n   6: core"
[ERROR][2024-10-29 09:11:05] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "::str::slice_error_fail_rt\n   7: core::str::slice_error_fail\n   8: <lsp_types::Range as ruff_server::edit::range::RangeExt>::to_text_range\n   9: ruff_server::edit::text_document::TextDocument::apply_changes\n  10: ruff_server::session::index::Index::update_text_document\n  11: <ruff_server::server::api::notifications::did_change::DidChange as ruff_server::server::api::traits::SyncNotificationHandler>::run\n  12: core::ops::function::FnOnce::call_once{{vtable.shim}}\n  13: std::sys::backtrace::__rust_begin_short_backtrace\n  14: core::ops::function::FnOnce::call_once{{vtable.shim}}\n  15: std::sys::pal::unix::thread::Thread::new::thread_start\n  16: <unknown>\n  17: <unknown>\n\n"
[ERROR][2024-10-29 09:11:05] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jod-thread-0.1.2/src/lib.rs:33:22:\ncalled `Result::unwrap()` on an `Err` value: Any { .. }\n"
[ERROR][2024-10-29 09:11:05] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   0: "
[ERROR][2024-10-29 09:11:05] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "ruff_server::server::Server::run::{{closure}}\n   1: std::panicking::rust_panic_with_hook\n   2: std::panicking::begin_panic_handler::{{closure}}\n   3: std::sys::backtrace::__rust_end_short_backtrace\n   4: rust_begin_unwind\n   5: core::panicking::panic_fmt\n   6: core::result::unwrap_failed\n   7: ruff_server::server::Server::run\n "
[ERROR][2024-10-29 09:11:05] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  8: ruff::run\n   9: ruff::main\n  10: std::sys::backtrace::__rust_begin_short_backtrace\n  11: std::rt::lang_start::{{closure}}\n  12: std::rt::lang_start_internal\n  13: main\n  14: <unknown>\n  15: __libc_start_main\n  16: <unknown>\n\n"

@HusuSama
Copy link
Author

HusuSama commented Oct 29, 2024

Do I need to make the following settings?
图片

The log content after I made the settings.

[START][2024-10-29 09:39:45] LSP logging initiated
[ERROR][2024-10-29 09:39:45] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   0.000021229s  INFO main ruff_server::server: No workspace settings found for file:///home/husu/PythonProjects/ZhiWei/ZcloudInterface, using default settings\n   0.004739909s DEBUG ThreadId(04) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/.ruff_cache\n   0.004769454s DEBUG ThreadId(04) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/.git\n   0.004944608s DEBUG ThreadId(09) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/.venv\n   0.004984051s DEBUG ThreadId(10) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/.pytest_cache\n   0.006152245s  INFO main ruff_server::session::index: Registering workspace: /home/husu/PythonProjects/ZhiWei/ZcloudInterface\n   0.006695351s  WARN ruff:main ruff_server::server: LSP client does not support dynamic capability registration - automatic configuration reloading will not be available.\n"
[ERROR][2024-10-29 09:39:45] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   0.020612467s DEBUG ruff:worker:0 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:46] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   0.557364854s DEBUG ruff:worker:1 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:49] ...lsp/handlers.lua:623    "Notification workspace/didChangeConfiguration defines parameters by name but received parameters by position"
[ERROR][2024-10-29 09:39:49] ...lsp/handlers.lua:623    "Notification workspace/didChangeConfiguration defines 1 params but received 0 arguments"
[ERROR][2024-10-29 09:39:50] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   4.661554269s DEBUG ruff:worker:3 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:50] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   4.866011638s DEBUG ruff:worker:4 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:50] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   5.086144569s DEBUG ruff:worker:5 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:50] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   5.260883897s DEBUG ruff:worker:6 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:50] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   5.341480461s DEBUG ruff:worker:7 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:51] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   5.449400862s DEBUG ruff:worker:8 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:51] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   5.623161907s DEBUG ruff:worker:9 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:52] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   6.918943214s DEBUG ruff:worker:10 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:52] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   7.064222808s DEBUG ruff:worker:11 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:53] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   7.716647234s DEBUG ruff:worker:12 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:53] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   7.717617050s DEBUG ruff:worker:15 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:54] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   8.628225531s DEBUG ruff:worker:13 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:54] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   8.896196725s DEBUG  ruff:worker:0 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:55] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   9.505942274s DEBUG  ruff:worker:1 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:55] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   9.787189927s DEBUG  ruff:worker:2 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:55] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "   9.919957468s DEBUG  ruff:worker:3 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:55] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  10.109705453s DEBUG  ruff:worker:4 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:55] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  10.191422562s DEBUG  ruff:worker:5 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:56] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  10.990491409s DEBUG  ruff:worker:6 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:56] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  11.281379026s DEBUG  ruff:worker:7 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:57] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  11.556823721s DEBUG  ruff:worker:8 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:57] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  11.667960930s DEBUG  ruff:worker:9 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:58] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  13.394465046s DEBUG ruff:worker:10 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:59] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  14.027106711s DEBUG ruff:worker:11 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:39:59] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  14.312729748s DEBUG ruff:worker:12 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:40:00] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  14.535848280s DEBUG ruff:worker:15 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:40:00] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  14.655770138s DEBUG ruff:worker:14 ruff_server::resolve: Included path via `include`: /home/husu/PythonProjects/ZhiWei/ZcloudInterface/test.py\n"
[ERROR][2024-10-29 09:40:00] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        '  15.379339018s ERROR      ruff:main ruff_server::server: panicked at crates/ruff_server/src/edit/range.rs:68:71:\nbyte index 68 is out of bounds of `"""\n测试comment\n一些测试内容\n"""\nimport click\n\n@click.go\n`\n   0: ruff_server::server::Server::run::{{closure}}\n   1: std::panicking::rust_panic_with_hook\n   2: std::panicking::begin_panic_handler::{{closure}}\n   3: std::sys::backtrace::__rust_end_short_backtrace\n   4: rust_begin_unwind\n   5: core::panicking::panic_fmt\n   6: core::str::slice_error_fail_rt\n   7: core::str::slice_error_fail\n   8: <lsp_types::Range as ruff_server::edit::range::RangeExt>::to_text_range\n   9: ruff_server::edit::text_document::TextDocument::apply_changes\n  10: ruff_server::session::index::Index::update_text_document\n  11: <ruff_server::server::api::notifications::did_change::DidChange as ruff_server::server::api::traits::SyncNotificationHandler>::run\n  12: core::ops::function::FnOnce::call_once{{vtable.shim}}\n  13: std::sys::backtrace::__rust_begin_short_backtrace\n  14: core::ops::function::FnOnce::call_once{{vtable.shim}}\n  15: std::sys::pal::unix::thread::Thread::new::thread_start\n  16: <unknown>\n  17: <unknown>\n\npanicked at crates/ruff_server/src/edit/range.rs:68:71:\nbyte index 68 is out of bounds of `"""\n测试comment\n一些测试内容\n"""\nimport click\n\n@click.go\n`\n   0: ruff_server::server::Server::run::{{closure}}\n   1: std::panicking::rust_panic_with_hook\n   2: std::panicking::begin_panic_handler::{{closure}}\n   3: std::sys::backtrace::__rust_end_short_backtrace\n   4: rust_begin_unwind\n   5: core::panicking::panic_fmt\n   6: core::str::slice_error_fail_rt\n   7: core::str::slice_error_fail\n   8: <lsp_types::Range as ruff_server::edit::range::RangeExt>::to_text_range\n   9: ruff_server::edit::text_document::TextDocument::apply_changes\n  10: ruff_server::session::index::Index::update_text_document\n  11: <ruff_server::server::api::notifications::did_change::DidChange as ruff_server::server::api::traits::SyncNotificationHandler>::run\n  12: core::ops::function::FnOnce::call_once{{vtable.shim}}\n  13: std::sys::backtrace::__rust_begin_short_backtrace\n  14: core::ops::function::FnOnce::call_once{{vtable.shim}}\n  15: std::sys::pal::unix::thread::Thread::new::thread_start\n  16: <unknown>\n  17: <unknown>\n\n'
[ERROR][2024-10-29 09:40:00] .../vim/lsp/rpc.lua:770    "rpc"   "/home/husu/.local/share/nvim/mason/bin/ruff"   "stderr"        "  15.384631891s ERROR           main ruff_server::server: panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jod-thread-0.1.2/src/lib.rs:33:22:\ncalled `Result::unwrap()` on an `Err` value: Any { .. }\n   0: ruff_server::server::Server::run::{{closure}}\n   1: std::panicking::rust_panic_with_hook\n   2: std::panicking::begin_panic_handler::{{closure}}\n   3: std::sys::backtrace::__rust_end_short_backtrace\n   4: rust_begin_unwind\n   5: core::panicking::panic_fmt\n   6: core::result::unwrap_failed\n   7: ruff_server::server::Server::run\n   8: ruff::run\n   9: ruff::main\n  10: std::sys::backtrace::__rust_begin_short_backtrace\n  11: std::rt::lang_start::{{closure}}\n  12: std::rt::lang_start_internal\n  13: main\n  14: <unknown>\n  15: __libc_start_main\n  16: <unknown>\n\npanicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jod-thread-0.1.2/src/lib.rs:33:22:\ncalled `Result::unwrap()` on an `Err` value: Any { .. }\n   0: ruff_server::server::Server::run::{{closure}}\n   1: std::panicking::rust_panic_with_hook\n   2: std::panicking::begin_panic_handler::{{closure}}\n   3: std::sys::backtrace::__rust_end_short_backtrace\n   4: rust_begin_unwind\n   5: core::panicking::panic_fmt\n   6: core::result::unwrap_failed\n   7: ruff_server::server::Server::run\n   8: ruff::run\n   9: ruff::main\n  10: std::sys::backtrace::__rust_begin_short_backtrace\n  11: std::rt::lang_start::{{closure}}\n  12: std::rt::lang_start_internal\n  13: main\n  14: <unknown>\n  15: __libc_start_main\n  16: <unknown>\n\n"

@MichaReiser
Copy link
Member

Thanks for the additional logs.

Looking at the stack trace, I suspect that the panic happens here because it's the only place where we slice into the string in to_text_range:

// UTF16 encodes characters either as one or two 16 bit words.
// The position in `range` is the 16-bit word offset from the start of the line (and not the character offset)
// UTF-16 with a text that may use variable-length characters.
(
utf8_column_offset(self.start.character, &text[start_line]),
utf8_column_offset(self.end.character, &text[end_line]),
)

It would suggest that the line-ranges are incorrect but it's unclear to me how it comes to this. The LSP messages would be helpful for debugging. @dhruvmanila could you share the instructions on how to get the LSP messages in neovim?

@dhruvmanila
Copy link
Member

could you share the instructions on how to get the LSP messages in neovim?

Yeah, you'd need to add the following lines in your Neovim config and then restart Neovim:

vim.lsp.set_log_level("debug")
-- This is mainly to make sure the messages are logged in a pretty way
require('vim.lsp.log').set_format_func(vim.inspect)

This will then log the request - response messages between the server and the client.

@dhruvmanila
Copy link
Member

I tried reproducing it using the provided source code and trying to perform the same set of actions as close as possible but unable to get the panic:

Screen.Recording.2024-10-29.at.7.41.00.PM.mov

I think having detailed logs involving the request - response messages would be very useful.

@MichaReiser
Copy link
Member

I think having detailed logs involving the request - response messages would be very useful.

What positional encoding does your neovim setup use? Is it UTF8 or UTF16?

@HusuSama
Copy link
Author

HusuSama commented Oct 30, 2024

error.webm

This issue seems to occur randomly, and I'm not quite sure if it's related to my nvim configuration or the system.

os:
图片

Most of the time when problems occur, I automatically select the first code suggestion rather than manually choosing the first one.

nvim-cmp config:

return {
  {
    "hrsh7th/nvim-cmp",
    opts = function(_, opts)
      local cmp = require("cmp")
      local utils = require("astrocore")
      local lspkind = require("lspkind")
      opts.sources = cmp.config.sources {
        {
          name = "nvim_lsp",
          priority = 1000,
          entry_filter = function(entry, ctx)
            return require("cmp.types").lsp.CompletionItemKind[entry:get_kind()] ~= "Text"
          end
        },
        { name = "luasnip", priority = 750 },
        { name = "path",    priority = 250 },
        { name = "codeium" }
      }
      return utils.extend_tbl(opts, {
        formatting = {
          -- fields = {"abbr", "kind", "menu"},
          format = lspkind.cmp_format({
            -- mode = "symbol",
            mode = "symbol_text",
            -- mode = "text_symbol",
            minwidth = 60,
            maxwidth = 80,
            ellipsis_char = "..."
          })
        },
        mapping = {
          ["<Up>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Select },
          ["<Down>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Select },
          ["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
          ["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
          ["<C-k>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
          ["<C-j>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
          ["<C-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
          ["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
          ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
          ["<C-y>"] = cmp.config.disable,
          -- ["<C-z>"] = cmp.mapping { i = cmp.mapping.abort(), c = cmp.mapping.close() },
          ["<C-e>"] = cmp.mapping { i = cmp.mapping.abort(), c = cmp.mapping.close() },
          ["<CR>"] = cmp.mapping.confirm { select = false },
          ["<Tab>"] = cmp.mapping.confirm { select = true },
        },
        sorting = {
          comparators = {
            cmp.config.compare.offset,
            cmp.config.compare.exact,
            cmp.config.compare.score,
            cmp.config.compare.recently_used,
            function(entry1, entry2)
              local _, entry1_under = entry1.completion_item.label:find "^_+"
              local _, entry2_under = entry2.completion_item.label:find "^_+"
              entry1_under = entry1_under or 0
              entry2_under = entry2_under or 0
              if entry1_under > entry2_under then
                return false
              elseif entry1_under < entry2_under then
                return true
              end
            end,
            -- 提升关键字的优先级
            function(entry1, entry2)
              local kind1 = entry1.completion_item.kind
              local kind2 = entry2.completion_item.kind
              kind1 = kind1 or 0
              kind2 = kind2 or 0
              if kind1 ~= kind2 then
                if require("cmp.types").lsp.CompletionItemKind[kind1] == "Keyword" then
                  -- if kind1 == 14 then
                  return true
                elseif require("cmp.types").lsp.CompletionItemKind[kind1] == "Snippet" then
                  return false
                else
                  return false
                end
              end
            end,
            cmp.config.compare.kind,
            cmp.config.compare.sort_text,
            cmp.config.compare.length,
            cmp.config.compare.order,
          },
        },
      })
    end
  }
}

@dhruvmanila

@dhruvmanila
Copy link
Member

What positional encoding does your neovim setup use? Is it UTF8 or UTF16?

UTF-16. I think Neovim's LSP client only support UTF-16 as per their client capabilities.

@dhruvmanila
Copy link
Member

@HusuSama Can you provide detailed logs? I've mentioned the change in your config to enable debug logs at #13674 (comment).

@HusuSama
Copy link
Author

HusuSama commented Oct 30, 2024

This data might be quite extensive; is it okay if I send it to you in a file? @dhruvmanila
lsp.log

@MichaReiser
Copy link
Member

Thanks. The logs are very useful. I've been able to reproduce the bug with the following unit test:

mod tests {
    use crate::edit::DocumentVersion;
    use crate::{PositionEncoding, TextDocument};
    use lsp_types::{Position, TextDocumentContentChangeEvent};

    #[test]
    fn regression() {
        let mut document = TextDocument::new(
            r#""""
测试comment
一些测试内容
"""
import click


@click.group()
def interface():
    pas
"#
            .to_string(),
            0,
        );

        document.apply_changes(
            vec![
                TextDocumentContentChangeEvent {
                    range: Some(lsp_types::Range::new(
                        Position::new(9, 7),
                        Position::new(9, 7),
                    )),
                    range_length: Some(0),
                    text: "s".to_string(),
                },
                TextDocumentContentChangeEvent {
                    range: Some(lsp_types::Range::new(
                        Position::new(9, 7),
                        Position::new(9, 8),
                    )),
                    range_length: Some(1),
                    text: "".to_string(),
                },
                TextDocumentContentChangeEvent {
                    range: Some(lsp_types::Range::new(
                        Position::new(9, 7),
                        Position::new(9, 7),
                    )),
                    range_length: Some(0),
                    text: "s".to_string(),
                },
            ],
            1,
            PositionEncoding::UTF16,
        );

        dbg!(document);
    }
}

@MichaReiser MichaReiser added bug Something isn't working and removed needs-mre Needs more information for reproduction labels Oct 31, 2024
@HusuSama
Copy link
Author

HusuSama commented Oct 31, 2024

I'm very happy to be able to assist you, and I hope to use the fixed version as soon as possible. 😄

# for free to join this conversation on GitHub. Already have an account? # 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