Skip to content

Commit 06651c4

Browse files
committed
Some adjustments to the experiential details
1 parent d5b7b1f commit 06651c4

5 files changed

Lines changed: 59 additions & 8 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn add_field_key_completion(
9898
};
9999
let typ = member_info.typ;
100100

101-
let (label, insert_text) = {
101+
let (label, insert_text, insert_text_format) = {
102102
let is_nullable = if typ.is_nullable() { "?" } else { "" };
103103
if in_env(builder, &name, &typ).is_some() {
104104
(
@@ -107,7 +107,8 @@ fn add_field_key_completion(
107107
name = name,
108108
nullable = is_nullable,
109109
),
110-
format!("{name} = {name},", name = name,),
110+
format!("{name} = ${{1:{name}}},", name = name),
111+
Some(InsertTextFormat::SNIPPET),
111112
)
112113
} else {
113114
// 函数类型不补空格, 留空格让用户触发字符补全
@@ -120,6 +121,7 @@ fn add_field_key_completion(
120121
space = space
121122
),
122123
format!("{name} ={space}", name = name, space = space),
124+
None,
123125
)
124126
}
125127
};
@@ -146,6 +148,7 @@ fn add_field_key_completion(
146148
data,
147149
deprecated,
148150
insert_text: Some(insert_text),
151+
insert_text_format,
149152
..Default::default()
150153
};
151154

crates/emmylua_ls/src/handlers/definition/goto_function.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,20 @@ fn get_call_function(
7070
if let Some(func) = func {
7171
let call_expr_args_count = call_expr.get_args_count();
7272
if let Some(mut call_expr_args_count) = call_expr_args_count {
73-
let func_params_count = func.get_params().len();
73+
let mut func_params_count = func.get_params().len();
7474
if !func.is_colon_define() && call_expr.is_colon_call() {
7575
// 不是冒号定义的函数, 但是是冒号调用
7676
call_expr_args_count += 1;
7777
}
78+
// 如果参数有可空参数, 则需要减去
79+
for (_, param_type) in func.get_params().iter() {
80+
if let Some(param_type) = param_type {
81+
if param_type.is_optional() {
82+
func_params_count -= 1;
83+
}
84+
}
85+
}
86+
7887
if call_expr_args_count == func_params_count {
7988
return Some(func);
8089
}

crates/emmylua_ls/src/handlers/inlay_hint/build_inlay_hint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ fn build_local_name_hint(
334334

335335
// 目前没时间完善结合 ast 的类型过滤, 所以只允许一些类型显示
336336
match typ {
337-
LuaType::Def(_) | LuaType::Ref(_) => {}
337+
LuaType::Ref(_) => {}
338338
_ => {
339339
return Some(());
340340
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,43 @@ mod tests {
173173
}
174174
}
175175
}
176+
177+
#[test]
178+
fn test_goto_return_field_2() {
179+
let mut ws = ProviderVirtualWorkspace::new_with_init_std_lib();
180+
ws.def_file(
181+
"test.lua",
182+
r#"
183+
---@export
184+
---@class Export
185+
local export = {}
186+
---@generic T
187+
---@param name `T`|T
188+
---@param tbl? table
189+
---@return T
190+
local function new(name, tbl)
191+
end
192+
193+
export.new = new
194+
return export
195+
"#,
196+
);
197+
let result = ws
198+
.check_definition(
199+
r#"
200+
local new = require("test").new
201+
new<??>("A")
202+
"#,
203+
)
204+
.unwrap();
205+
match result {
206+
GotoDefinitionResponse::Array(locations) => {
207+
assert_eq!(locations.len(), 1);
208+
assert_eq!(locations[0].range.start.line, 8);
209+
}
210+
_ => {
211+
panic!("expect scalar");
212+
}
213+
}
214+
}
176215
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ mod tests {
108108
"#,
109109
)
110110
.unwrap();
111-
assert!(result.len() == 4);
111+
assert!(result.len() == 3);
112112
}
113113

114114
#[test]
@@ -123,7 +123,7 @@ mod tests {
123123
"#,
124124
)
125125
.unwrap();
126-
assert!(result.len() == 1);
126+
assert!(result.len() == 0);
127127
}
128128

129129
#[test]
@@ -148,9 +148,9 @@ mod tests {
148148
"#,
149149
)
150150
.unwrap();
151-
assert!(result.len() == 2);
151+
assert!(result.len() == 1);
152152

153-
let location = match &result.get(1).unwrap().label {
153+
let location = match &result.get(0).unwrap().label {
154154
InlayHintLabel::LabelParts(parts) => parts.first().unwrap().location.as_ref().unwrap(),
155155
InlayHintLabel::String(_) => panic!(),
156156
};

0 commit comments

Comments
 (0)