[Bug] LSP hover shows raw Markdown when the server answers with a MarkedString
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 85/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
rust/crates/lsp-client/src/client/results.rs の hover_contents から始めてください。parse_hover から到達します。報告者の diff と 4 つのユニットテストが想定される形状(単純な文字列、{language, value}、MarkupContent、配列)を示しています。変更の前後に rust/ で cargo test -p lsp-client を実行し、その後 Lithe Desktop で gleam lsp を使い、ポップアップに表示されるフェンスではなくハイライトされた Gleam ブロックが描画されることを確認してください。これらのユニットテストが通り、desktop/internal/workbench/pluginsemantics_hover.go でホバーの Markdown が二重にフェンスされなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Platform / 平台
macOS
Area / 模块
Language support / 语言服务
Lithe version / Lithe 版本
0.8.15 (desktop-v0.8.15, Core 4880022); Core main 529be33 has the same code
Priority / 优先级
P2 / 后续考虑:目前不着急,可安排到后续版本
OS and architecture / 操作系统与架构
macOS, arm64
Environment / 环境信息
Gleam 1.19.1 (gleam lsp) through a declarative language-server plugin
Steps to reproduce / 复现步骤
-
Use a language server that answers
textDocument/hoverwith a bare string, for example
gleam lsp. Its answer for a documented function is:{"contents": "```gleam\nfn(Int, Int) -> Int\n```\n Adds two numbers and says so.\n", "range": {"start": {"line": 6, "character": 2}, "end": {"line": 6, "character": 5}}} -
Hover over a call of that function in Lithe Desktop.
Expected behavior / 预期行为
The popup renders Markdown: the signature as a highlighted Gleam code block, the documentation
as text below it. The LSP specification defines MarkedString as Markdown when it is a string,
and as a code block in language when it is {language, value}
(https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#markedString).
Actual behavior / 实际行为
The popup shows the source text, fences included (```gleam is visible), unhighlighted
and wrapped mid-word.
Cause: hover_contents in rust/crates/lsp-client/src/client/results.rs returns
isMarkdown: false for Value::String, so the desktop's hoverMarkdown
(desktop/internal/workbench/pluginsemantics_hover.go) wraps the Markdown in a plain fence. A
{language, value} object takes the kind branch, also gets false, and loses its language.
Suggested fix (tested locally on desktop-v0.8.15 with Core 4880022; the lsp-client tests
pass, and the hover renders correctly with gleam lsp):
fn hover_contents(value: &Value) -> Option<(String, bool)> {
match value {
- Value::String(text) => Some((text.clone(), false)),
+ Value::String(text) => Some((text.clone(), true)),
Value::Object(object) => {
if let Some(value) = object.get("value").and_then(Value::as_str) {
+ if let Some(language) = object.get("language").and_then(Value::as_str) {
+ let longest = value
+ .split(|c| c != '`')
+ .map(str::len)
+ .max()
+ .unwrap_or(0);
+ let fence = "`".repeat(longest.max(2) + 1);
+ return Some((
+ format!("{fence}{language}\n{}\n{fence}", value.trim_end_matches('\n')),
+ true,
+ ));
+ }
let is_markdown = object
Unit tests for the four shapes (bare string, {language, value}, MarkupContent plaintext and
markdown, array) are in the patch below.
diff --git a/rust/crates/lsp-client/src/client/results.rs b/rust/crates/lsp-client/src/client/results.rs
index 63ecf22..1ef44f4 100644
--- a/rust/crates/lsp-client/src/client/results.rs
+++ b/rust/crates/lsp-client/src/client/results.rs
@@ -180,11 +180,26 @@ fn parse_hover(result: &Value) -> Option<Value> {
}))
}
+// A bare string is a MarkedString, which the LSP specification defines as Markdown; an object
+// with a language is a MarkedString code block, rendered as a fence in that language; an object
+// with a kind is MarkupContent, Markdown only when its kind says so.
fn hover_contents(value: &Value) -> Option<(String, bool)> {
match value {
- Value::String(text) => Some((text.clone(), false)),
+ Value::String(text) => Some((text.clone(), true)),
Value::Object(object) => {
if let Some(value) = object.get("value").and_then(Value::as_str) {
+ if let Some(language) = object.get("language").and_then(Value::as_str) {
+ let longest = value
+ .split(|c| c != '`')
+ .map(str::len)
+ .max()
+ .unwrap_or(0);
+ let fence = "`".repeat(longest.max(2) + 1);
+ return Some((
+ format!("{fence}{language}\n{}\n{fence}", value.trim_end_matches('\n')),
+ true,
+ ));
+ }
let is_markdown = object
.get("kind")
.and_then(Value::as_str)
@@ -1014,3 +1029,44 @@ fn parse_lsp_position_value(value: &Value) -> Option<Value> {
.unwrap_or(0)
}))
}
+
+#[cfg(test)]
+mod hover_contents_tests {
+ use super::*;
+
+ #[test]
+ fn bare_string_is_markdown() {
+ let text = "```gleam\nfn(Int) -> Int\n```\n Adds.\n";
+ assert_eq!(hover_contents(&json!(text)), Some((text.to_string(), true)));
+ }
+
+ #[test]
+ fn marked_string_code_block_becomes_a_fence() {
+ let value = json!({ "language": "erlang", "value": "add(A, B) -> A + B.\n" });
+ assert_eq!(
+ hover_contents(&value),
+ Some(("```erlang\nadd(A, B) -> A + B.\n```".to_string(), true))
+ );
+ }
+
+ #[test]
+ fn markup_content_follows_its_kind() {
+ assert_eq!(
+ hover_contents(&json!({ "kind": "plaintext", "value": "a *b*" })),
+ Some(("a *b*".to_string(), false))
+ );
+ assert_eq!(
+ hover_contents(&json!({ "kind": "markdown", "value": "a *b*" })),
+ Some(("a *b*".to_string(), true))
+ );
+ }
+
+ #[test]
+ fn array_joins_its_parts_as_markdown() {
+ let value = json!([{ "language": "gleam", "value": "fn() -> Nil" }, "Docs."]);
+ assert_eq!(
+ hover_contents(&value),
+ Some(("```gleam\nfn() -> Nil\n```\n\nDocs.".to_string(), true))
+ );
+ }
+}
```
### Logs or diagnostic output / 日志或诊断输出
```shell
none needed; the cause is in the code above.
```
### Screenshots or recordings / 截图或录屏
before:
<img width="652" height="403" alt="image" src="https://github.com/user-attachments/assets/99cc2e1f-53fd-45d4-9997-afa5280fd63c" />
after:
<img width="572" height="330" alt="image" src="https://github.com/user-attachments/assets/0a8efa8a-d944-450a-8634-b471e3fb4909" />
### Checklist / 提交前检查
- [x] I searched existing issues for duplicates. / 我已搜索现有 Issue,确认没有重复报告。
- [x] I removed secrets and personal data from the report. / 我已从报告中移除敏感信息和个人数据。
- 主要言語
- TypeScript
- スター
- 1.8k
- フォーク
- 151
- 平均マージ
- 4時間 4分
- マージ済み PR(30日)
- 558
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
1lck/Lithe-IDEA のほかの issue
-
refactor review: high
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
1lck/Lithe-IDEA#2376 ·
メンテナーはふだん 1 日以内に返信
-
area:ui enhancement P2 platform:cross-platform refactor review: high
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
1lck/Lithe-IDEA#2365 ·
メンテナーはふだん 1 日以内に返信
-
review: high
難易度 4/5 3〜5日 初心者へのやさしさ 28/100
1lck/Lithe-IDEA#2381 ·
メンテナーはふだん 1 日以内に返信
-
review: high
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
1lck/Lithe-IDEA#2380 ·
メンテナーはふだん 1 日以内に返信
-
review: high
難易度 3/5 1〜2日 初心者へのやさしさ 50/100
1lck/Lithe-IDEA#2379 ·
メンテナーはふだん 1 日以内に返信
1lck/Lithe-IDEA の issue をすべて見る
似ている issue
-
chore
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
drydocs/meridian#1503 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
bug extension mcp
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
primer/primitives#1426 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
danielmiessler/LifeOS#2941 ·
メンテナーはふだん 4 日以内に返信
-
Sign-in-only setup dialog describes API-key verification対応中かも @roboclaw-bot が今日担当しました。 オープンclawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
openclaw/openclaw#204323 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信