Skip to content

Commit f5e1050

Browse files
committed
display documentation for intersection type completion
1 parent 3c4e376 commit f5e1050

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

crates/emmylua_code_analysis/src/semantic/member/find_members.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ fn find_intersection_members(
407407
member_set.insert(key.clone());
408408

409409
result.push(LuaMemberInfo {
410-
property_owner_id: None,
410+
property_owner_id: member.property_owner_id.clone(),
411411
key: key.clone(),
412412
typ: typ.clone(),
413413
feature: None,

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod tests {
2727
detail:
2828
"local function test(event: string, callback: fun(trg: string, data: number)) -> number (+2 overloads)"
2929
.to_string(),
30+
documentation: None,
3031
},
3132
));
3233
Ok(())
@@ -46,6 +47,7 @@ mod tests {
4647
"#,
4748
VirtualCompletionResolveItem {
4849
detail: "(field) Test2.event(event: \"游戏-初始化\") (+1 overloads)".to_string(),
50+
documentation: None,
4951
},
5052
));
5153
Ok(())
@@ -66,6 +68,7 @@ mod tests {
6668
"#,
6769
VirtualCompletionResolveItem {
6870
detail: "(field) T.func(self: string)".to_string(),
71+
documentation: Some("\n注释注释".to_string()),
6972
},
7073
));
7174
Ok(())
@@ -86,6 +89,36 @@ mod tests {
8689
"#,
8790
VirtualCompletionResolveItem {
8891
detail: "(method) T:func()".to_string(),
92+
documentation: Some("\n注释注释".to_string()),
93+
},
94+
));
95+
Ok(())
96+
}
97+
98+
#[gtest]
99+
fn test_intersection() -> Result<()> {
100+
let mut ws = ProviderVirtualWorkspace::new();
101+
ws.def(
102+
r#"
103+
---@class Matchers
104+
---@field toBe fun(self: Assertion, expected: any) -- 测试
105+
106+
---@class Inverse<T>
107+
---@field not_ T
108+
109+
---@class Assertion<T>: Matchers<T>
110+
"#,
111+
);
112+
check!(ws.check_completion_resolve(
113+
r#"
114+
115+
---@type Assertion<any>
116+
local expect
117+
expect:<??>
118+
"#,
119+
VirtualCompletionResolveItem {
120+
detail: "(method) Matchers:toBe(expected: any)".to_string(),
121+
documentation: Some("\n测试".to_string()),
89122
},
90123
));
91124
Ok(())

crates/emmylua_ls/src/handlers/test_lib/mod.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use googletest::prelude::*;
33
use itertools::Itertools;
44
use lsp_types::{
55
CodeActionOrCommand, CompletionItem, CompletionItemKind, CompletionResponse,
6-
CompletionTriggerKind, GotoDefinitionResponse, Hover, HoverContents, InlayHintLabel, Location,
7-
MarkupContent, Position, SemanticTokenModifier, SemanticTokenType, SemanticTokensResult,
8-
SignatureHelpContext, SignatureHelpTriggerKind, SignatureInformation, TextEdit,
6+
CompletionTriggerKind, Documentation, GotoDefinitionResponse, Hover, HoverContents,
7+
InlayHintLabel, Location, MarkupContent, Position, SemanticTokenModifier, SemanticTokenType,
8+
SemanticTokensResult, SignatureHelpContext, SignatureHelpTriggerKind, SignatureInformation,
9+
TextEdit,
910
};
1011
use std::collections::HashSet;
1112
use std::{ops::Deref, sync::Arc};
@@ -72,6 +73,7 @@ impl Default for VirtualCompletionItem {
7273
#[derive(Debug)]
7374
pub struct VirtualCompletionResolveItem {
7475
pub detail: String,
76+
pub documentation: Option<String>,
7577
}
7678

7779
#[derive(Debug)]
@@ -279,7 +281,18 @@ impl ProviderVirtualWorkspace {
279281
.or_fail()?;
280282
let item = completion_resolve(&self.analysis, param.clone(), ClientId::VSCode);
281283
let item_detail = item.detail.ok_or("item detail is empty").or_fail()?;
282-
verify_eq!(item_detail, expected.detail)
284+
verify_eq!(item_detail, expected.detail)?;
285+
match (item.documentation.as_ref(), expected.documentation.as_ref()) {
286+
(None, None) => Ok(()),
287+
(Some(doc), Some(expected_doc)) => match doc {
288+
Documentation::String(s) => verify_eq!(s, expected_doc),
289+
Documentation::MarkupContent(MarkupContent { value, .. }) => {
290+
verify_eq!(value, expected_doc)
291+
}
292+
},
293+
(Some(_), None) => fail!("unexpected documentation in completion resolve result"),
294+
(None, Some(_)) => fail!("expected documentation missing in completion resolve result"),
295+
}
283296
}
284297

285298
pub fn check_implementation(

0 commit comments

Comments
 (0)