Skip to content

Commit e1a17ad

Browse files
committed
Add tests for Markdown/RST in comments
1 parent b0c3771 commit e1a17ad

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ fn add_by_prefix(
157157

158158
// Modules.
159159
add_modules(builder, &prefix, None);
160-
dbg!(&seen_types);
161160
complete_types_by_prefix(builder, &prefix, Some(&seen_types));
162161
}
163162

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

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[cfg(test)]
22
mod tests {
33
use crate::handlers::test_lib::{ProviderVirtualWorkspace, VirtualLocation, check};
4+
use emmylua_code_analysis::{DocSyntax, Emmyrc};
45
use googletest::prelude::*;
56

67
type Expected = VirtualLocation;
@@ -193,11 +194,12 @@ mod tests {
193194
local test = t.test
194195
te<??>st()
195196
"#,
196-
vec![Expected {
197+
vec![VirtualLocation {
197198
file: "test.lua".to_string(),
198199
line: 1
199200
}]
200201
));
202+
201203
Ok(())
202204
}
203205

@@ -328,4 +330,104 @@ mod tests {
328330
));
329331
Ok(())
330332
}
333+
334+
#[gtest]
335+
fn test_doc_resolve() -> Result<()> {
336+
let mut ws = ProviderVirtualWorkspace::new();
337+
338+
let mut emmyrc = Emmyrc::default();
339+
emmyrc.doc.syntax = DocSyntax::Myst;
340+
ws.analysis.update_config(emmyrc.into());
341+
342+
ws.def_file(
343+
"a.lua",
344+
r#"
345+
--- @class X
346+
--- @field a string
347+
348+
--- @class ns.Y
349+
--- @field b string
350+
"#,
351+
);
352+
353+
check!(ws.check_definition(
354+
r#"
355+
--- {lua:obj}`X<??>`
356+
"#,
357+
vec![Expected {
358+
file: "a.lua".to_string(),
359+
line: 1
360+
}]
361+
));
362+
363+
check!(ws.check_definition(
364+
r#"
365+
--- {lua:obj}`X<??>.a`
366+
"#,
367+
vec![Expected {
368+
file: "a.lua".to_string(),
369+
line: 1
370+
}]
371+
));
372+
373+
check!(ws.check_definition(
374+
r#"
375+
--- {lua:obj}`X.a<??>`
376+
"#,
377+
vec![Expected {
378+
file: "a.lua".to_string(),
379+
line: 2
380+
}]
381+
));
382+
383+
check!(ws.check_definition(
384+
r#"
385+
--- @using ns
386+
387+
--- {lua:obj}`X<??>`
388+
"#,
389+
vec![Expected {
390+
file: "a.lua".to_string(),
391+
line: 1
392+
}]
393+
));
394+
395+
check!(ws.check_definition(
396+
r#"
397+
--- @using ns
398+
399+
--- {lua:obj}`Y<??>`
400+
"#,
401+
vec![Expected {
402+
file: "a.lua".to_string(),
403+
line: 4
404+
}]
405+
));
406+
407+
check!(ws.check_definition(
408+
r#"
409+
--- @using ns
410+
411+
--- {lua:obj}`ns.Y<??>`
412+
"#,
413+
vec![Expected {
414+
file: "a.lua".to_string(),
415+
line: 4
416+
}]
417+
));
418+
419+
check!(ws.check_definition(
420+
r#"
421+
--- {lua:obj}`c<??>`
422+
--- @class Z
423+
--- @field c string
424+
"#,
425+
vec![Expected {
426+
file: "".to_string(),
427+
line: 3
428+
}]
429+
));
430+
431+
Ok(())
432+
}
331433
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl ProviderVirtualWorkspace {
214214
pub fn check_completion_with_kind(
215215
&mut self,
216216
block_str: &str,
217-
expected: Vec<VirtualCompletionItem>,
217+
mut expected: Vec<VirtualCompletionItem>,
218218
trigger_kind: CompletionTriggerKind,
219219
) -> Result<()> {
220220
let (content, position) = Self::handle_file_content(block_str)?;
@@ -229,11 +229,14 @@ impl ProviderVirtualWorkspace {
229229
.ok_or("failed to get completion")
230230
.or_fail()?;
231231
// 对比
232-
let items = match result {
232+
let mut items = match result {
233233
CompletionResponse::Array(items) => items,
234234
CompletionResponse::List(list) => list.items,
235235
};
236236

237+
items.sort_by_key(|item| item.label.clone());
238+
expected.sort_by_key(|item| item.label.clone());
239+
237240
fn get_item_detail(i: &CompletionItem) -> Option<&String> {
238241
i.label_details.as_ref().and_then(|d| d.detail.as_ref())
239242
}

0 commit comments

Comments
 (0)