-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
@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)? |
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 my code: """
测试comment
一些测试内容
"""
import click
@click.group()
def interface():
pass
@interface.command()
def test():
click.echo("hello")
if __name__ == "__main__":
interface() |
Thanks! I've a couple of questions:
|
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 ruff/crates/ruff_server/src/edit/range.rs Lines 64 to 70 in b0731ef
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? |
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. |
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.movI 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? |
error.webmThis issue seems to occur randomly, and I'm not quite sure if it's related to my nvim configuration or the system. Most of the time when problems occur, I automatically select the first code suggestion rather than manually choosing the first one.
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
}
}
|
UTF-16. I think Neovim's LSP client only support UTF-16 as per their client capabilities. |
@HusuSama Can you provide detailed logs? I've mentioned the change in your config to enable debug logs at #13674 (comment). |
This data might be quite extensive; is it okay if I send it to you in a file? @dhruvmanila |
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);
}
} |
I'm very happy to be able to assist you, and I hope to use the fixed version as soon as possible. 😄 |
When I use Click, errors occur. I'm not sure if it's because of my Chinese comments or the decorators.
log:
code:
The text was updated successfully, but these errors were encountered: