Skip to content

Commit 6e3cbec

Browse files
committed
fix hover text
1 parent 29f635c commit 6e3cbec

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

crates/emmylua_code_analysis/src/compilation/analyzer/doc/type_def_tags.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ fn add_description_for_type_decl(
7474
) {
7575
let mut description_text = String::new();
7676

77-
let comment = analyzer.comment.clone();
78-
if let Some(description) = comment.get_description() {
79-
let description = preprocess_description(&description.get_description_text(), None);
80-
if !description.is_empty() {
81-
description_text.push_str(&description);
82-
}
83-
}
77+
// let comment = analyzer.comment.clone();
78+
// if let Some(description) = comment.get_description() {
79+
// let description = preprocess_description(&description.get_description_text(), None);
80+
// if !description.is_empty() {
81+
// description_text.push_str(&description);
82+
// }
83+
// }
8484

8585
for description in descriptions {
8686
let description = preprocess_description(&description.get_description_text(), None);

crates/emmylua_ls/src/handlers/test/hover_function_test.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod tests {
1818
local <??>delete4 = delete3
1919
"#,
2020
VirtualHoverResult {
21-
value: "\n```lua\nlocal function delete(a: number)\n -> a: number\n\n```\n\n---\n\n@*param* `a` — 参数a\n\n\n\n@*return* `a` — 返回值a\n\n\n".to_string(),
21+
value: "```lua\nlocal function delete(a: number)\n -> a: number\n\n```\n\n---\n\n@*param* `a` — 参数a\n\n\n\n@*return* `a` — 返回值a".to_string(),
2222
},
2323
));
2424

@@ -38,7 +38,7 @@ mod tests {
3838
}
3939
"#,
4040
VirtualHoverResult {
41-
value: "\n```lua\nlocal function delete(a: number)\n -> a: number\n\n```\n\n---\n\n删除\n\n@*param* `a` — 参数a\n\n\n\n@*return* `a` — 返回值a\n\n\n".to_string(),
41+
value: "```lua\nlocal function delete(a: number)\n -> a: number\n\n```\n\n---\n\n删除\n\n@*param* `a` — 参数a\n\n\n\n@*return* `a` — 返回值a".to_string(),
4242
},
4343
));
4444

@@ -61,7 +61,7 @@ mod tests {
6161
}
6262
"#,
6363
VirtualHoverResult {
64-
value: "\n```lua\nlocal function delete(a: number)\n -> a: number\n\n```\n\n---\n\n@*param* `a` — 参数a\n\n\n\n@*return* `a` — 返回值a\n\n\n".to_string(),
64+
value: "```lua\nlocal function delete(a: number)\n -> a: number\n\n```\n\n---\n\n@*param* `a` — 参数a\n\n\n\n@*return* `a` — 返回值a".to_string(),
6565
},
6666
));
6767
}
@@ -97,7 +97,7 @@ mod tests {
9797
local <??>local_b = local_a
9898
"#,
9999
VirtualHoverResult {
100-
value: "\n```lua\n(method) Game:add(key: string, value: string)\n -> ret: number\n\n```\n\n---\n\n说明\n\n@*param* `key` — 参数key\n\n@*param* `value` — 参数value\n\n\n\n@*return* `ret` — 返回值\n\n\n" .to_string(),
100+
value: "```lua\n(method) Game:add(key: string, value: string)\n -> ret: number\n\n```\n\n---\n\n说明\n\n@*param* `key` — 参数key\n\n@*param* `value` — 参数value\n\n\n\n@*return* `ret` — 返回值".to_string(),
101101
},
102102
));
103103
}
@@ -122,7 +122,7 @@ mod tests {
122122
local <??>event = test3.event
123123
"#,
124124
VirtualHoverResult {
125-
value: "\n```lua\n(method) Test3:event(event: \"B\", key: string)\n```\n\n&nbsp;&nbsp;in class `Hover.Test3`\n\n---\n\n---\n\n```lua\n(method) Test3:event(event: \"A\", key: string)\n```\n".to_string(),
125+
value: "```lua\n(method) Test3:event(event: \"B\", key: string)\n```\n\n&nbsp;&nbsp;in class `Hover.Test3`\n\n---\n\n---\n\n```lua\n(method) Test3:event(event: \"A\", key: string)\n```".to_string(),
126126
},
127127
));
128128
}
@@ -160,7 +160,7 @@ mod tests {
160160
---@field event fun(self: self, event: "游戏-http返回"): Trigger
161161
"#,
162162
VirtualHoverResult {
163-
value: "\n```lua\n(method) GameA:event(event_type: EventTypeA, ...: any)\n -> Trigger\n\n```\n\n---\n\n注册引擎事件\n\n---\n\n```lua\n(method) GameA:event(event: \"游戏-初始化\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-追帧完成\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-逻辑不同步\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-地形预设加载完成\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-结束\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-暂停\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-恢复\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-昼夜变化\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"区域-进入\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"区域-离开\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-http返回\") -> Trigger\n```\n".to_string(),
163+
value: "```lua\n(method) GameA:event(event_type: EventTypeA, ...: any)\n -> Trigger\n\n```\n\n---\n\n注册引擎事件\n\n---\n\n```lua\n(method) GameA:event(event: \"游戏-初始化\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-追帧完成\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-逻辑不同步\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-地形预设加载完成\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-结束\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-暂停\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-恢复\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-昼夜变化\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"区域-进入\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"区域-离开\") -> Trigger\n```\n\n```lua\n(method) GameA:event(event: \"游戏-http返回\") -> Trigger\n```".to_string(),
164164
},
165165
));
166166
}
@@ -179,7 +179,7 @@ mod tests {
179179
end
180180
"#,
181181
VirtualHoverResult {
182-
value: "\n```lua\nfunction ClosureTest.e(a: string, b: number)\n```\n\n---\n\n---\n\n```lua\n(field) ClosureTest.e(a: string, b: number)\n```\n".to_string(),
182+
value: "```lua\nfunction ClosureTest.e(a: string, b: number)\n```\n\n---\n\n---\n\n```lua\n(field) ClosureTest.e(a: string, b: number)\n```".to_string(),
183183
},
184184
));
185185
}
@@ -200,7 +200,7 @@ mod tests {
200200
}
201201
"#,
202202
VirtualHoverResult {
203-
value: "\n```lua\n(method) T:func()\n```\n\n---\n\n注释注释\n".to_string(),
203+
value: "```lua\n(method) T:func()\n```\n\n---\n\n注释注释".to_string(),
204204
},
205205
));
206206
}
@@ -219,7 +219,7 @@ mod tests {
219219
}
220220
"#,
221221
VirtualHoverResult {
222-
value: "\n```lua\n(field) a: string = \"a\"\n```\n\n---\n\n注释注释a\n".to_string(),
222+
value: "```lua\n(field) a: string = \"a\"\n```\n\n---\n\n注释注释a".to_string(),
223223
},
224224
));
225225
}
@@ -239,8 +239,7 @@ mod tests {
239239
}
240240
"#,
241241
VirtualHoverResult {
242-
value: "\n```lua\n(field) T.func(self: string)\n```\n\n---\n\n注释注释\n"
243-
.to_string(),
242+
value: "```lua\n(field) T.func(self: string)\n```\n\n---\n\n注释注释".to_string(),
244243
},
245244
));
246245
}
@@ -261,7 +260,7 @@ mod tests {
261260
}
262261
"#,
263262
VirtualHoverResult {
264-
value: "\n```lua\n(field) T.func(a: (string|number))\n```\n\n---\n\n注释1\n\n注释2\n\n---\n\n```lua\n(field) T.func(a: string)\n```\n\n```lua\n(field) T.func(a: number)\n```\n"
263+
value: "```lua\n(field) T.func(a: (string|number))\n```\n\n---\n\n注释1\n\n注释2\n\n---\n\n```lua\n(field) T.func(a: string)\n```\n\n```lua\n(field) T.func(a: number)\n```"
265264
.to_string(),
266265
},
267266
));
@@ -285,7 +284,7 @@ mod tests {
285284
t.fu<??>nc(1)
286285
"#,
287286
VirtualHoverResult {
288-
value: "\n```lua\n(field) T.func(a: number)\n```\n\n---\n\n注释2\n".to_string(),
287+
value: "```lua\n(field) T.func(a: number)\n```\n\n---\n\n注释2".to_string(),
289288
},
290289
));
291290
}
@@ -307,7 +306,7 @@ mod tests {
307306
local ab<??>c = t.func
308307
"#,
309308
VirtualHoverResult {
310-
value: "\n```lua\n(field) T.func(a: number)\n```\n\n---\n\n注释2\n\n注释1\n\n---\n\n```lua\n(field) T.func(a: string)\n```\n".to_string(),
309+
value: "```lua\n(field) T.func(a: number)\n```\n\n---\n\n注释2\n\n注释1\n\n---\n\n```lua\n(field) T.func(a: string)\n```".to_string(),
311310
},
312311
));
313312
}

crates/emmylua_ls/src/handlers/test/hover_test.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ mod tests {
1313
---@field c boolean
1414
"#,
1515
VirtualHoverResult {
16-
value: "\n```lua\n(class) A {\n a: number,\n b: string,\n c: boolean,\n}\n```\n".to_string(),
16+
value:
17+
"```lua\n(class) A {\n a: number,\n b: string,\n c: boolean,\n}\n```"
18+
.to_string(),
1719
},
1820
));
1921
}
@@ -35,7 +37,7 @@ mod tests {
3537
m1.<??>x = {}
3638
"#,
3739
VirtualHoverResult {
38-
value: "\n```lua\n(field) x: integer = 1\n```\n".to_string(),
40+
value: "```lua\n(field) x: integer = 1\n```".to_string(),
3941
},
4042
));
4143

@@ -58,7 +60,7 @@ mod tests {
5860
end
5961
"#,
6062
VirtualHoverResult {
61-
value: "\n```lua\n(field) right: Node\n```\n".to_string(),
63+
value: "```lua\n(field) right: Node\n```".to_string(),
6264
},
6365
));
6466

@@ -80,7 +82,7 @@ mod tests {
8082
end
8183
"#,
8284
VirtualHoverResult {
83-
value: "\n```lua\nlocal node: Node1 {\n x: number,\n}\n```\n".to_string(),
85+
value: "```lua\nlocal node: Node1 {\n x: number,\n}\n```".to_string(),
8486
},
8587
));
8688
}
@@ -99,7 +101,7 @@ mod tests {
99101
local d = a.<??>a
100102
"#,
101103
VirtualHoverResult {
102-
value: "\n```lua\n(field) a: number?\n```\n".to_string(),
104+
value: "```lua\n(field) a: number?\n```".to_string(),
103105
},
104106
));
105107
}
@@ -114,7 +116,7 @@ mod tests {
114116
end
115117
"#,
116118
VirtualHoverResult {
117-
value: "\n```lua\nlocal function f(a, b)\n```\n".to_string(),
119+
value: "```lua\nlocal function f(a, b)\n```".to_string(),
118120
},
119121
));
120122
}
@@ -133,7 +135,7 @@ mod tests {
133135
data.pu<??>lse
134136
"#,
135137
VirtualHoverResult {
136-
value: "\n```lua\n(field) pulse: number?\n```\n\n&nbsp;&nbsp;in class `Buff.AddData`\n\n---\n\n心跳周期\n".to_string(),
138+
value: "```lua\n(field) pulse: number?\n```\n\n&nbsp;&nbsp;in class `Buff.AddData`\n\n---\n\n心跳周期".to_string(),
137139
},
138140
));
139141
}
@@ -154,7 +156,7 @@ mod tests {
154156
end
155157
"#,
156158
VirtualHoverResult {
157-
value: "\n```lua\n(field) _cfg: number\n```\n".to_string(),
159+
value: "```lua\n(field) _cfg: number\n```".to_string(),
158160
},
159161
));
160162

@@ -176,7 +178,7 @@ mod tests {
176178
end
177179
"#,
178180
VirtualHoverResult {
179-
value: "\n```lua\n(field) _cfg: number\n```\n".to_string(),
181+
value: "```lua\n(field) _cfg: number\n```".to_string(),
180182
},
181183
));
182184
}
@@ -195,4 +197,19 @@ mod tests {
195197
},
196198
));
197199
}
200+
201+
#[test]
202+
fn test_class_desc() {
203+
let mut ws = ProviderVirtualWorkspace::new();
204+
assert!(ws.check_hover(
205+
r#"
206+
---A1
207+
---@class AB<??>C
208+
---A2
209+
"#,
210+
VirtualHoverResult {
211+
value: "```lua\n(class) ABC\n```\n\n---\n\nA1".to_string(),
212+
},
213+
));
214+
}
198215
}

0 commit comments

Comments
 (0)