Skip to content

Commit 30d16f4

Browse files
committed
fix hover doc function
1 parent 51c1753 commit 30d16f4

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

crates/emmylua_ls/src/handlers/hover/function_humanize.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,13 @@ fn hover_doc_function_type(
259259
} else {
260260
func_name.to_string()
261261
};
262-
263262
let params = lua_func
264263
.get_params()
265264
.iter()
266265
.enumerate()
267266
.map(|(index, param)| {
268267
let name = param.0.clone();
269-
if index == 0 && is_method {
268+
if index == 0 && is_method && !lua_func.is_colon_define() {
270269
"".to_string()
271270
} else if let Some(ty) = &param.1 {
272271
format!("{}: {}", name, humanize_type(db, ty, RenderLevel::Normal))

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,35 @@ mod tests {
394394
},
395395
));
396396
}
397+
398+
#[test]
399+
fn test_generic_function() {
400+
let mut ws = ProviderVirtualWorkspace::new();
401+
ws.def_file(
402+
"test.lua",
403+
r#"
404+
---@class Observable<T>
405+
local Observable
406+
407+
---@generic R
408+
---@param selector fun(value: T, index?: integer): R
409+
function Observable:select(selector)
410+
end
411+
412+
---@type Observable<integer>
413+
source = {}
414+
415+
"#,
416+
);
417+
assert!(ws.check_hover(
418+
r#"
419+
source:sel<??>ect(function(value)
420+
return value
421+
end)
422+
"#,
423+
VirtualHoverResult {
424+
value: "```lua\n(method) Observable:select(selector: fun(value: integer, index: integer?) -> R)\n```".to_string(),
425+
},
426+
));
427+
}
397428
}

0 commit comments

Comments
 (0)