Skip to content

Commit 3408f39

Browse files
committed
fix #499
1 parent 13c1101 commit 3408f39

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed

crates/emmylua_ls/src/handlers/completion/providers/table_field_provider.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use lsp_types::{CompletionItem, InsertTextFormat, InsertTextMode};
66
use rowan::NodeOrToken;
77

88
use crate::handlers::completion::{
9-
add_completions::{check_visibility, get_detail, is_deprecated, CallDisplay},
9+
add_completions::{check_visibility, is_deprecated},
1010
completion_builder::CompletionBuilder,
1111
completion_data::CompletionData,
1212
};
@@ -232,7 +232,7 @@ fn add_field_value_completion(
232232
) -> Option<()> {
233233
let real_type = get_real_type(&builder.semantic_model.get_db(), &member_info.typ)?;
234234
if real_type.is_function() {
235-
let label_detail = get_detail(builder, real_type, CallDisplay::None);
235+
let label_detail = get_function_detail(builder, real_type);
236236
let item = CompletionItem {
237237
label: "fun".to_string(),
238238
label_details: Some(lsp_types::CompletionItemLabelDetails {
@@ -254,3 +254,32 @@ fn add_field_value_completion(
254254

255255
None
256256
}
257+
258+
fn get_function_detail(builder: &CompletionBuilder, typ: &LuaType) -> Option<String> {
259+
match typ {
260+
LuaType::Signature(signature_id) => {
261+
let signature = builder
262+
.semantic_model
263+
.get_db()
264+
.get_signature_index()
265+
.get(&signature_id)?;
266+
267+
let params_str = signature
268+
.get_type_params()
269+
.iter()
270+
.map(|param| param.0.clone())
271+
.collect::<Vec<_>>();
272+
273+
Some(format!("({})", params_str.join(", ")))
274+
}
275+
LuaType::DocFunction(f) => {
276+
let params_str = f
277+
.get_params()
278+
.iter()
279+
.map(|param| param.0.clone())
280+
.collect::<Vec<_>>();
281+
Some(format!("({})", params_str.join(", ")))
282+
}
283+
_ => None,
284+
}
285+
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,4 +707,26 @@ mod tests {
707707
CompletionTriggerKind::INVOKED,
708708
));
709709
}
710+
711+
#[test]
712+
fn test_issue_499() {
713+
let mut ws = ProviderVirtualWorkspace::new();
714+
assert!(ws.check_completion_with_kind(
715+
r#"
716+
---@class T
717+
---@field func fun(a:string): string
718+
719+
---@type T
720+
local t = {
721+
func = <??>
722+
}
723+
"#,
724+
vec![VirtualCompletionItem {
725+
label: "fun".to_string(),
726+
kind: CompletionItemKind::SNIPPET,
727+
label_detail: Some("(a)".to_string()),
728+
},],
729+
CompletionTriggerKind::INVOKED,
730+
));
731+
}
710732
}

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -311,27 +311,4 @@ mod tests {
311311
},
312312
));
313313
}
314-
315-
// #[test]
316-
// fn test_origin_decl_1() {
317-
// let mut ws = ProviderVirtualWorkspace::new();
318-
// assert!(ws.check_hover(
319-
// r#"
320-
// ---@class T
321-
// ---@field func fun(a:string) 注释1
322-
// ---@field func fun(a:number) 注释2
323-
324-
// ---@type T
325-
// local t = {
326-
// func = function(a)
327-
// end
328-
// }
329-
// local abc = t.func
330-
// a<??>bc(1)
331-
// "#,
332-
// VirtualHoverResult {
333-
// value: "\n```lua\n(field) T.func(a: number)\n```\n\n---\n\n注释2\n".to_string(),
334-
// },
335-
// ));
336-
// }
337314
}

0 commit comments

Comments
 (0)