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

Fix crashing on window/showMessageRequest #794

Closed
wants to merge 1 commit into from

Conversation

igor-ramazanov
Copy link
Contributor

It's been crashing for me with the state.next returning quoted numbers like "3" which then unsuccessfully parsed as toml::Value.

It's been crashing for me with the `state.next` returning quoted numbers
like `"3"` which then unsuccessfully parsed as `toml::Value`.
Box::new(MessageRequestResponse {
message_request_id: jsonrpc_core::Id::deserialize(id).unwrap(),
message_request_id: id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks and sorry about that; we're missing a lot of test coverage.
Fortunately it's easy to test this manually with metals on an empty *.scala file.
I'll push a slightly different fix since this one might not work if the server treats id: "123" differently from id: 123.

Something else I noticed is that I see a glitch when multiple messages are sent; it looks like

LSP: info from server metals: ⚠️ Compiled t_f4dd477a3a (0.12s)      🔔1 t/test.scala 1:4  1 sel - client0@[foo]
LSP: info from server metals: ⚠️ Compiled t_f4dd477a3a (0.12s)      🔔1 t/test.scala 1:4  1 sel - client0@[foo]

but when I hold shift and copy those two lines, the text is actually joined in one line, and the trailing ]

LSP: info from server metals: ⚠️ Compiled t_f4dd477a3a (0.12s)      🔔1 t/test.scala 1:4  1 sel - client0@[fooLSP: info from server metals: ⚠️ Compiled t_f4dd477a3a (0.12s)                                                                                      ⌛🔔1 t/test.scala 1:4  1 sel - client0@[foo

it looks like Kakoune and my terminal disagree on the width of 🔔 or ⚠️ (probably the latter since that seems to includes a variation selector).
I'll look into it..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Contributor Author

@igor-ramazanov igor-ramazanov Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something else I noticed is that I see a glitch when multiple messages are sent; it looks like

Hm, yeah, I remember I had the same problem in the past which I fixed by changing this line to statusBarProvider = "log-message" (docs).

However, recently I've changed it back to statusBarProvider = "show-message" and have no issues anymore.

I suspect, it's a bug with an old metals version. Mine is the latest 1.4.0 and I can not reproduce it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a well-known type of bug: the terminal and Kakoune disagree on the width of ⚠️.
In my case, the terminal (foot, which has a custom implementation of wcwidth() says it's width 2 and Kakoune (which uses the glibc one) thinks it's width 1.

FWIW this is how I tested the glibc version:

#define _XOPEN_SOURCE
#include <locale.h>
#include <stdio.h>
#include <wchar.h>

int main() {
  setlocale(LC_ALL, "");
#define TEST(s) wprintf(s " %d\n", wcswidth(s, wcslen(s)))
  TEST(L"🔎");
  TEST(L"💡");
  TEST(L"");
  TEST(L""); // 1
  TEST(L"⚠️"); // 1 but should be 2
}

Unfortunately I keep getting network timeouts on the glibc bug tracker.

See also this comment for example.
This situation is pretty unfortunate, not sure when it will get fixed. In kakoune-lsp we generally work around this by falling back to ascii chars if the system wcwidth is confirmed to be wrong.

Hm, yeah, I remember I had the same problem in the past which I fixed by changing this line to statusBarProvider = "log-message" (docs).

Nice, that sounds like the thing to do as default, until we can expect this issue to be fixed in the user's libc.
Alternatively we could apply our expected_width_or_fallback trick but that requires a Unicode database (today we just use it for 3 hard-code characters).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported glibc bug as https://sourceware.org/bugzilla/show_bug.cgi?id=32322 though I wonder if it's better to use a separate library for that

@krobelus krobelus closed this in ce7077c Oct 30, 2024
@igor-ramazanov igor-ramazanov deleted the fix-show-message-request branch October 30, 2024 07:50
krobelus added a commit that referenced this pull request Nov 1, 2024
…idth

As reported in [^1], we have configured Scala Metals to use Unicode
symbols for window/showMessage which are displayed in the status line.
Kakoune does not yet know that emoji are width 2, which causes visual
glitches.

Unfortunately fixing Kakoune is not completely trivial because they
don't use wcswidth() but only wcwidth(); this means that we'd need to
adjust the code to lookahead by one codepoint to detect any VARIATION
SELECTOR-16.

Until we fix this, let's switch back to the defaults, e.g. no emoji.

Alternatively, we could use logMessage to move away from the status
line into the debug buffer but that has the same problem, it's just
less visible.

[^1]: #794 (comment)
krobelus added a commit that referenced this pull request Nov 2, 2024
…idth

As reported in [^1], we have configured Scala Metals to use Unicode
symbols for window/showMessage which are displayed in the status line.
Kakoune does not yet know that emoji are width 2, which causes visual
glitches.

Unfortunately fixing Kakoune is not completely trivial because they
don't use wcswidth() but only wcwidth(); this means that we'd need to
adjust the code to lookahead by one codepoint to detect any VARIATION
SELECTOR-16.

Until we fix this, let's switch back to the defaults, e.g. no emoji.

Alternatively, we could use logMessage to move away from the status
line into the debug buffer but that has the same problem, it's just
less visible.

[^1]: #794 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants