@@ -7,15 +7,35 @@ use expect_test::{expect, Expect};
7
7
8
8
use super :: { get_completions, CompletionItem } ;
9
9
use crate :: test_utils:: {
10
- compile_notebook_with_fake_stdlib_and_markers, compile_with_fake_stdlib ,
11
- get_source_and_marker_offsets ,
10
+ compile_notebook_with_fake_stdlib_and_markers, compile_project_with_fake_stdlib_and_markers ,
11
+ compile_with_fake_stdlib_and_markers ,
12
12
} ;
13
13
use indoc:: indoc;
14
14
15
15
fn check ( source_with_cursor : & str , completions_to_check : & [ & str ] , expect : & Expect ) {
16
- let ( source, cursor_offset, _) = get_source_and_marker_offsets ( source_with_cursor) ;
17
- let compilation = compile_with_fake_stdlib ( "<source>" , & source) ;
18
- let actual_completions = get_completions ( & compilation, "<source>" , cursor_offset[ 0 ] ) ;
16
+ let ( compilation, cursor_offset, _) = compile_with_fake_stdlib_and_markers ( source_with_cursor) ;
17
+ let actual_completions = get_completions ( & compilation, "<source>" , cursor_offset) ;
18
+ let checked_completions: Vec < Option < & CompletionItem > > = completions_to_check
19
+ . iter ( )
20
+ . map ( |comp| {
21
+ actual_completions
22
+ . items
23
+ . iter ( )
24
+ . find ( |item| item. label == * * comp)
25
+ } )
26
+ . collect ( ) ;
27
+
28
+ expect. assert_debug_eq ( & checked_completions) ;
29
+ }
30
+
31
+ fn check_project (
32
+ sources_with_markers : & [ ( & str , & str ) ] ,
33
+ completions_to_check : & [ & str ] ,
34
+ expect : & Expect ,
35
+ ) {
36
+ let ( compilation, cursor_uri, cursor_offset, _) =
37
+ compile_project_with_fake_stdlib_and_markers ( sources_with_markers) ;
38
+ let actual_completions = get_completions ( & compilation, & cursor_uri, cursor_offset) ;
19
39
let checked_completions: Vec < Option < & CompletionItem > > = completions_to_check
20
40
. iter ( )
21
41
. map ( |comp| {
@@ -241,6 +261,52 @@ fn in_block_from_other_namespace() {
241
261
) ;
242
262
}
243
263
264
+ #[ test]
265
+ fn auto_open_multiple_files ( ) {
266
+ check_project (
267
+ & [
268
+ (
269
+ "foo.qs" ,
270
+ indoc ! { r#"namespace Foo { operation FooOperation() : Unit {} }
271
+ "# } ,
272
+ ) ,
273
+ (
274
+ "bar.qs" ,
275
+ indoc ! { r#"namespace Bar { operation BarOperation() : Unit { ↘ } }
276
+ "# } ,
277
+ ) ,
278
+ ] ,
279
+ & [ "FooOperation" ] ,
280
+ & expect ! [ [ r#"
281
+ [
282
+ Some(
283
+ CompletionItem {
284
+ label: "FooOperation",
285
+ kind: Function,
286
+ sort_text: Some(
287
+ "0500FooOperation",
288
+ ),
289
+ detail: Some(
290
+ "operation FooOperation() : Unit",
291
+ ),
292
+ additional_text_edits: Some(
293
+ [
294
+ (
295
+ Span {
296
+ start: 16,
297
+ end: 16,
298
+ },
299
+ "open Foo;\n ",
300
+ ),
301
+ ],
302
+ ),
303
+ },
304
+ ),
305
+ ]
306
+ "# ] ] ,
307
+ ) ;
308
+ }
309
+
244
310
#[ ignore = "nested callables are not currently supported for completions" ]
245
311
#[ test]
246
312
fn in_block_nested_op ( ) {
0 commit comments