Bug 494139 - LSP hover text has backslashes before certain characters.
Summary: LSP hover text has backslashes before certain characters.
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: general (other bugs)
Version First Reported In: 24.08.1
Platform: Kubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-10-04 22:29 UTC by Alex Lowe
Modified: 2025-07-26 15:13 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Kate, showing backspaces before a bunch of special characters (31.60 KB, image/png)
2024-10-04 22:29 UTC, Alex Lowe
Details
Emacs not showing these backslashes (76.40 KB, image/png)
2024-10-10 12:59 UTC, Alex Lowe
Details
Pycharm not showing these backslashes (14.49 KB, image/png)
2024-10-10 12:59 UTC, Alex Lowe
Details
vscode not showing slashes (30.28 KB, image/png)
2024-10-10 13:00 UTC, Alex Lowe
Details
Visual Studio Code not showing backslashes (48.68 KB, image/png)
2024-10-10 13:05 UTC, Alex Lowe
Details
yaml server hover on master (44.08 KB, image/png)
2024-10-11 06:46 UTC, Waqar Ahmed
Details
Kate nightly AppImage (9477) showing raw values (61.76 KB, image/png)
2025-05-22 16:52 UTC, Alex Lowe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Lowe 2024-10-04 22:29:52 UTC
Created attachment 174435 [details]
Kate, showing backspaces before a bunch of special characters

SUMMARY
The hover text from language servers contains backspaces before many special characters, including: .`!#*(){}[]\

STEPS TO REPRODUCE
1. Configure the YAML LSP to enable hover and receive from the schema store:
{
    "servers": {
        "yaml": {
            "command": ["yaml-language-server", "--stdio"],
            "url": "https://github.com/redhat-developer/yaml-language-server",
            "highlightingModeRegex": "^YAML$",
            "settings": {
                "yaml": {
                    "hover": true,
                    "schemaStore": {
                        "enable": true
                    }
                }
            }
        }
    }
}

2. Create a "rockcraft.yaml" file with the following contents:
name: my-name
title: blah
summary: thing
description: description
base: ubuntu@24.04
platforms:
  amd64:
parts: {}

3. Hover over the "name" field

OBSERVED RESULT
Hover text contains several backslashes. For example, the first paragraph reads as: "Valid names for rocks\. It matches the accepted values for pebble layer files:"

EXPECTED RESULT
Hover text does not contain these backslashes. The first paragraph should read: "Valid names for rocks. It matches the accepted values for pebble layer files:"
Compare to Visual Studio Code with the Red Hat YAML LSP extension installed.


SOFTWARE/OS VERSIONS
Operating System: Kubuntu 24.10
KDE Plasma Version: 6.1.5
KDE Frameworks Version: 6.6.0
Qt Version: 6.6.2
Kernel Version: 6.11.0-8-generic (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 7840U w/ Radeon 780M Graphics
Memory: 60.6 GiB of RAM
Graphics Processor: AMD Radeon 780M

ADDITIONAL INFORMATION
The schema for rockcraft.yaml can be found at: https://raw.githubusercontent.com/canonical/rockcraft/main/schema/rockcraft.json

The actual value that comes out of the server at this point, according to lsp-devtools, is:

{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "contents": [
      "Project Name\n\nValid names for rocks\\. It matches the accepted values for pebble layer files:\n\n\\- must start with a lowercase letter \\[a\\-z\\]\n\n\\- must contain only lowercase letters \\[a\\-z\\], numbers \\[0\\-9\\] or hyphens\n\n\\- must not end with a hyphen, and must not contain two or more consecutive hyphens\n"
    ],
    "range": {
      "start": {
        "line": 0,
        "character": 0
      },
      "end": {
        "line": 0,
        "character": 4
      }
    }
  }
}
Comment 1 Waqar Ahmed 2024-10-08 07:42:04 UTC
I wonder if its the server's fault or our fault. If the server escapes markdown characters by putting backslashes, thats how they will appear...
Comment 2 Alex Lowe 2024-10-10 12:59:08 UTC
Created attachment 174623 [details]
Emacs not showing these backslashes
Comment 3 Alex Lowe 2024-10-10 12:59:25 UTC
Created attachment 174624 [details]
Pycharm not showing these backslashes
Comment 4 Alex Lowe 2024-10-10 13:00:22 UTC
Created attachment 174625 [details]
vscode not showing slashes
Comment 5 Alex Lowe 2024-10-10 13:05:24 UTC
Created attachment 174629 [details]
Visual Studio Code not showing backslashes
Comment 6 Alex Lowe 2024-10-10 13:34:29 UTC
(In reply to Waqar Ahmed from comment #1)
> I wonder if its the server's fault or our fault. If the server escapes
> markdown characters by putting backslashes, thats how they will appear...

I was initially working to create a report on the YAML language server, but I noticed that kate was also behaving this way with the vscode JSON language server. VSCode doesn't show this same behaviour though, either in JSON or in YAML.

I asked some coworkers to compare with their text editors and got the following:

- Emacs appears to behave mostly-correctly, but ignores the backslashes that are undoing the "markdownification" of bullet points and then treats those hyphens as bullet points
- PyCharm eats the newlines, but doesn't include the slashes (Incorrect because a double-newline in Markdown should be treated as a newline in the resulting formatted document)
- VSCode behaves what appears to be "most correctly" from a user perspective, as the contents field is correctly turned into a string (converting "\n" in the raw JSON to a newline character and unescaping "\\" to a single "\"), and then that string is treated as Markdown (including unescaping characters - see: https://www.markdownguide.org/basic-syntax/#characters-you-can-escape)

Looking further, the current protocol specification shows the "contents" field to be one of three types (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover). In this case, it's a plain string, which is one of the two forms of the MarkedString type (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#markedString). While this is a deprecated type, the relevance here is that the MarkedString is a union type either of a plain string which needs to be rendered in (presumably GitHub dialect) Markdown or an object that provides both the language and the value.
Comment 7 Alex Lowe 2024-10-10 13:46:45 UTC
While researching the last comment I found that someone had reported this in the YAML language server: https://github.com/redhat-developer/yaml-language-server/issues/837

I made a comment there because the research displayed in my last comment makes me think that it is behaving correctly, but I wanted to cross-link the bugs in both directions.
Comment 8 Waqar Ahmed 2024-10-11 06:46:58 UTC
Created attachment 174670 [details]
yaml server hover on master

This is how it looks like on latest master. I think this got fixed with the recent changes to hover code. Can you try the latest master? We have app-images available I think
Comment 9 Waqar Ahmed 2024-10-11 06:51:50 UTC
Please feel free to reopen if it isn't resolved
Comment 10 Alex Lowe 2025-05-22 16:52:56 UTC
Created attachment 181656 [details]
Kate nightly AppImage (9477) showing raw values

This is still broken for me with multiple versions of the YAML language server
Comment 11 Alex Lowe 2025-05-22 17:17:43 UTC
The current state with various versions of yaml-language-server (https://github.com/redhat-developer/yaml-language-server/) installed directly from the repository, using the latest nightly AppImage of kate (9477):

0.16.0: Issue as originally reported (language server is usable, but output is weird)
0.19.0: Same
0.23.0: Language server crash due to ResponseError in workspace/configuration
1.1.1: Same issue as 0.23.0
1.10.0: Receive error in workspace/configuration and then no hover text.
1.18.0 (latest stable version): Same as 1.10.0
main branch (commit 6424ff6f6e673b912ffa1a891ec75afba5f4f233): Same as 1.10.0

Error message from 1.10.0:

[13:11:59  LSP Client Log] Started server yaml@/home/lengau: /home/lengau/.local/bin/yaml-language-server --stdio
[13:11:59  LSP Server Log] yaml@/home/lengau
[Error] Error: workspace/configuration
    at handleResponse (/home/lengau/Projects/yaml-language-server/node_modules/vscode-jsonrpc/lib/common/connection.js:477:48)
    at processMessageQueue (/home/lengau/Projects/yaml-language-server/node_modules/vscode-jsonrpc/lib/common/connection.js:292:17)
    at Immediate.<anonymous> (/home/lengau/Projects/yaml-language-server/node_modules/vscode-jsonrpc/lib/common/connection.js:276:13)
    at process.processImmediate (node:internal/timers:483:21)
[13:11:59  LSP Server Log] yaml@/home/lengau
[Error] Error: workspace/configuration
    at handleResponse (/home/lengau/Projects/yaml-language-server/node_modules/vscode-jsonrpc/lib/common/connection.js:477:48)
    at processMessageQueue (/home/lengau/Projects/yaml-language-server/node_modules/vscode-jsonrpc/lib/common/connection.js:292:17)
    at Immediate.<anonymous> (/home/lengau/Projects/yaml-language-server/node_modules/vscode-jsonrpc/lib/common/connection.js:276:13)
    at process.processImmediate (node:internal/timers:483:21)
Comment 12 Bug Janitor Service 2025-07-20 19:54:10 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1822
Comment 13 Christoph Cullmann 2025-07-20 19:54:29 UTC
Could you try my request for the default to markdown for hover?
Comment 14 Christoph Cullmann 2025-07-26 15:05:26 UTC
Git commit cac48eb62878bcfde22077ffaecc1b9fc13b7743 by Christoph Cullmann.
Committed on 26/07/2025 at 14:53.
Pushed by cullmann into branch 'master'.

default is markdown for hover strings

see:

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#markedString

M  +7    -5    addons/lspclient/lspclientserver.cpp

https://invent.kde.org/utilities/kate/-/commit/cac48eb62878bcfde22077ffaecc1b9fc13b7743
Comment 15 Christoph Cullmann 2025-07-26 15:13:24 UTC
Git commit 00f6233f47c5a55f5d765ecf3d099caf988669c4 by Christoph Cullmann.
Committed on 26/07/2025 at 15:13.
Pushed by cullmann into branch 'release/25.08'.

default is markdown for hover strings

see:

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#markedString


(cherry picked from commit cac48eb62878bcfde22077ffaecc1b9fc13b7743)

Co-authored-by: Christoph Cullmann <christoph@cullmann.dev>

M  +7    -5    addons/lspclient/lspclientserver.cpp

https://invent.kde.org/utilities/kate/-/commit/00f6233f47c5a55f5d765ecf3d099caf988669c4