laburnum 1.17.0

An LSP framework for building language servers and compilers, powered by an incremental query tree with content-addressed storage, task-based dataflow, and parallel queries.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
// Copyright Two Neutron Stars Incorporated and contributors
// SPDX-License-Identifier: BlueOak-1.0.0

use {
  crate::{
    connect::ipc::Connection,
    database,
    fs::FS,
    protocol::otel::exporter::setup_telemetry,
  },
  opentelemetry::trace::FutureExt,
};

otel::tracer!(lsp_test);

#[cfg(feature = "test")]
pub fn traced_test<P, T>(
  test_name: &str,
  files: &[(&str, &str)],
  server: T,
  test_block: impl AsyncFn(
    &crate::connect::lsp::LspClient,
    &mut ferrotype::Ferrotype,
  ) -> std::result::Result<
    (),
    std::boxed::Box<dyn std::error::Error + 'static>,
  >,
  error_expectation: (bool, Option<&str>),
  snapshot: &mut ferrotype::Ferrotype,
) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error + 'static>>
where
  P: database::storage::Partitions,
  T: crate::protocol::lsp::LanguageServer<P>,
{
  let telemetry = setup_telemetry()?;

  {
    smol::block_on(traced_test_code(
      test_name,
      files,
      None,
      server,
      snapshot,
      test_block,
      error_expectation,
      false,
    ))?;
  }

  if let Err(err) = telemetry.tracer_provider.force_flush() {
    otel::error!(
      "telemetry_error",
      format!("Failed to flush telemetry: {:?}", err)
    );
  }
  drop(telemetry);

  Ok(())
}

#[cfg(feature = "test")]
pub fn traced_test_with_fs<P, T>(
  test_name: &str,
  fs: FS,
  server: T,
  test_block: impl AsyncFn(
    &crate::connect::lsp::LspClient,
    &mut ferrotype::Ferrotype,
  ) -> std::result::Result<
    (),
    std::boxed::Box<dyn std::error::Error + 'static>,
  >,
  error_expectation: (bool, Option<&str>),
  snapshot: &mut ferrotype::Ferrotype,
  skip_fs_snapshot: bool,
) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error + 'static>>
where
  P: database::storage::Partitions,
  T: crate::protocol::lsp::LanguageServer<P>,
{
  let telemetry = setup_telemetry()?;

  {
    smol::block_on(traced_test_code(
      test_name,
      &[],
      Some(fs),
      server,
      snapshot,
      test_block,
      error_expectation,
      skip_fs_snapshot,
    ))?;
  }

  if let Err(err) = telemetry.tracer_provider.force_flush() {
    otel::error!(
      "telemetry_error",
      format!("Failed to flush telemetry: {:?}", err)
    );
  }
  drop(telemetry);

  Ok(())
}

#[allow(clippy::too_many_arguments)]
async fn traced_test_code<P, T>(
  test_name: &str,
  files: &[(&str, &str)],
  pre_built_fs: Option<FS>,
  server: T,
  snapshot: &mut ferrotype::Ferrotype,
  test_block: impl AsyncFn(
    &crate::connect::lsp::LspClient,
    &mut ferrotype::Ferrotype,
  ) -> std::result::Result<
    (),
    std::boxed::Box<dyn std::error::Error + 'static>,
  >,
  error_expectation: (bool, Option<&str>),
  skip_fs_snapshot: bool,
) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error + 'static>>
where
  P: database::storage::Partitions,
  T: crate::protocol::lsp::LanguageServer<P>,
{
  use smol::future::FutureExt as _;

  let (expects_error, expected_message): (bool, Option<&str>) =
    error_expectation;

  let panic_err = None;

  otel::span!(
    @LSP_TEST_TRACER,
    format!("lsp_test.{test_name}"),
    "test.name" = test_name.to_string(),
    "test.file.count" = files.len() as i64,
    in |_cx| {
  let workspace_path =
    crate::Uri::parse(&format!("file://test/{}/", test_name))
      .map_err(|e| Box::new(e) as Box<dyn std::error::Error + 'static>)?;

  let fs = if let Some(fs) = pre_built_fs {
    fs
  } else {
    let fs = crate::fs::MemoryFileSystem::new();

    let setup_result: std::result::Result<(), std::boxed::Box<dyn std::error::Error + 'static>> = otel::span!(
      @LSP_TEST_TRACER,
      "lsp_test.setup_files",
      "file.count" = files.len() as i64,
      in |_cx| {
          for (file, content) in files {
            let file_path = workspace_path.join(file)
              .ok_or_else(|| format!("invalid file path: {}", file))?;
            fs.write_str(&file_path, content)
              .map_err(|e| format!("failed to write file {}: {}", file, e))?;

            otel::event!("Wrote test file", "file" = file.to_string(), "content_len" = content.len() as i64);
          }

          otel::event!("Test files written", "file_count" = files.len() as i64);
          Ok(())
      }
    );
    setup_result?;

    fs
  };

  if !skip_fs_snapshot {
    fs.add_tree_to_snapshot("Before", snapshot);
  }

  // Clone fs so we can snapshot it after
  let fs_for_snapshot = fs.clone();
  let (server_conn, client_conn) = Connection::memory();

  let server = crate::Laburnum::<P, T>::new(server)
    .filesystem(fs)
    .build_server(server_conn);

  otel::span!(
    @LSP_TEST_TRACER,
    "lsp_test.client_lifecycle",
    in |cx|{

    let workspace_folders = Some(vec![crate::protocol::lsp::WorkspaceFolder {
      uri: workspace_path.clone(),
      name: "Workspace".to_string(),
    }]);

    let client = { crate::connect::lsp::LspClient::new_test(client_conn) };

    let init_result: std::result::Result<(), std::boxed::Box<dyn std::error::Error + 'static>> = otel::span!(
      @LSP_TEST_TRACER,
      "lsp_test.client.initialize",
      in |cx| {
        client
          .start(crate::protocol::lsp::InitializeParams {
            process_id: None,
            initialization_options: None,
            capabilities: Default::default(),
            trace: None,
            workspace_folders: workspace_folders.clone(),
            client_info: Some(crate::protocol::lsp::ClientInfo {
              name: "Laburnum Test Macro".to_string(),
              version: Some("test".to_string()),
            }),
            locale: None,
            work_done_progress_params:
              crate::protocol::lsp::WorkDoneProgressParams {
                work_done_token: None,
              },
            ..Default::default()
          })
          .with_context(cx)
          .await
          .map_err(|e| format!("Failed to start: {}", e))?;

        if !client.is_initialized() {
          return Err("Client should be initialized".into());
        }

        otel::event!("Client initialized successfully");
        Ok(())
      });
    init_result?;


      otel::span!(
      @LSP_TEST_TRACER,
      "lsp_test.test_block",
      in |cx|{
        let test_result =  std::panic::AssertUnwindSafe(test_block(&client, snapshot))
            .catch_unwind().with_context(cx)
            .await;


        if let Err(panic_payload) = test_result {
          let panic_message = if let Some(s) = panic_payload.downcast_ref::<&str>()
          {
            s.to_string()
          } else if let Some(s) = panic_payload.downcast_ref::<String>() {
            s.clone()
          } else {
            "Unknown panic".to_string()
          };

          eprintln!("panic {}",panic_message);

          otel::exception!(
            "panic",panic_message
          );

          std::panic::resume_unwind(panic_payload);
        } else {
          otel::event!("Test block completed successfully");
        }
    });


    if expects_error {
      async {
        otel::event!("Validating error expectations");

        let diagnostics = client.get_received_diagnostics();
        let total_diagnostics: usize =
          diagnostics.iter().map(|d| d.diagnostics.len()).sum();

        otel::event!(
          "Received diagnostics",
          "diagnostic_count" = total_diagnostics as i64,
        );

        if let Some(msg) = expected_message {
          otel::event!("Checking for specific error message", "expected_message" = msg.to_string());

          let has_matching_diagnostic = diagnostics.iter().any(|d| {
            d.diagnostics
              .iter()
              .any(|diag| diag.message.to_string().contains(msg))
          });
          let all_messages: Vec<String> = diagnostics
            .iter()
            .flat_map(|d| {
              d.diagnostics.iter().map(|diag| diag.message.to_string())
            })
            .collect();

          if has_matching_diagnostic {
            otel::event!(
              "Found expected error message",
              "expected_message" = msg.to_string(),
            );
          } else {
            otel::error!(
              "validation_error",
              format!("Expected error message '{}' not found. Got: {:?}", msg, all_messages)
            );
          }

          assert!(
            has_matching_diagnostic,
            "Expected diagnostic containing '{}', but got: {:?}",
            msg, all_messages
          );
        } else {
          let has_any_diagnostic =
            diagnostics.iter().any(|d| !d.diagnostics.is_empty());

          if has_any_diagnostic {
            otel::event!("Found expected diagnostics");
          } else {
            otel::error!("validation_error", "Expected diagnostics but found none");
          }

          assert!(
            has_any_diagnostic,
            "Expected at least one diagnostic, but got none"
          );
        }
      }
      .with_context(cx)
      .await;
    }

    {
      otel::span!(
        @LSP_TEST_TRACER,
        "lsp_test.client.shutdown",
        in |cx| {
          otel::event!("Shutting down client");
          client.stop_test(snapshot).with_context(cx).await.ok();
          otel::event!("Client shutdown complete");
        }
      );
    }
  });

  {
    otel::span!(
      @LSP_TEST_TRACER,
      "lsp_test.server.close"
    );

    otel::event!("Closing server");
    if let Err(err) = server.close() {
      otel::error!("server_error", format!("Failed to close server: {:?}", err));
    }
    otel::event!("Server closed");
  }

  if !skip_fs_snapshot {
    fs_for_snapshot.add_tree_to_snapshot("After", snapshot);
  }

  otel::event!(
    "Test completed successfully",
    "test_name" = test_name.to_string(),
  );

  match panic_err {
    Some(err) if !expects_error => Err(err),
    _ => {
      Ok(())
    }
  }

  })
}

/// LSP test macro for creating language server protocol tests.
///
/// This macro provides a convenient way to test LSP implementations with
/// automatic setup, teardown, telemetry, and snapshot testing via ferrotype.
///
/// # Basic Usage
///
/// ```ignore
/// lsp_test!(<StorageType, LanguageServerType>{
///   test_name({
///     "file.ext" => "file contents",
///     "other.ext" => "other contents",
///   }) => |client| {
///     // Test body - use client to interact with LSP
///   }
/// })
/// ```
///
/// # File Sources
///
/// ## Inline Files
/// Define test files directly in the macro with `"filename" => "content"`
/// syntax: ```ignore
/// test_name({
///   "main.nrs" => r#"fn hello() { print("world"); }"#,
///   "lib.nrs" => "fn add(a, b) { a + b }",
/// }) => |client| { /* ... */ }
/// ```
/// 
/// ## Folder-based Files
/// Load files from a folder on disk using `folder("path")` syntax.
/// The path is relative to the crate's `Cargo.toml` directory
/// (`CARGO_MANIFEST_DIR`): ```ignore
/// test_name(folder("tests/fixtures/my_test/")) => |client| { /* ... */ }
/// ```
/// When using folder mode, the filesystem is NOT included in snapshots.
///
/// # Attributes
///
/// ## `#[ignore = "reason"]`
/// Skip the test with a reason:
/// ```ignore
/// #[ignore = "not yet implemented"]
/// test_name({ /* ... */ }) => |client| { /* ... */ }
/// ```
///
/// ## `#[error]`
/// Expect at least one diagnostic to be received:
/// ```ignore
/// #[error]
/// test_parse_error({
///   "bad.nrs" => "invalid syntax {{{{",
/// }) => |client| { /* ... */ }
/// ```
///
/// ## `#[error("message")]`
/// Expect a diagnostic containing a specific message:
/// ```ignore
/// #[error("undefined variable")]
/// test_undefined_var({
///   "main.nrs" => "fn foo() { unknown_var }",
/// }) => |client| { /* ... */ }
/// ```
///
/// # Snapshot Access
///
/// Optionally capture the snapshot for custom assertions:
/// ```ignore
/// test_name({ /* ... */ }) => |client, snapshot| {
///   // snapshot is &mut ferrotype::Ferrotype
///   snapshot.add("Custom", "value");
/// }
/// ```
///
/// # Multiple Tests
///
/// Define multiple tests in a single macro invocation:
/// ```ignore
/// lsp_test!(<Storage, Server>{
///   test_one({ "a.nrs" => "..." }) => |client| { /* ... */ },
///   test_two({ "b.nrs" => "..." }) => |client| { /* ... */ },
///   #[error]
///   test_three({ "c.nrs" => "..." }) => |client| { /* ... */ },
/// })
/// ```
#[macro_export]
macro_rules! lsp_test {
  // Entry point - start munching
  (
    <$storage_ty:ty, $language_server_ty:tt>{
      $($rest:tt)*
    }
  ) => {
    $crate::lsp_test!(@munch <$storage_ty, $language_server_ty> $($rest)*);
  };

  // Munch: #[ignore = "reason"] variant
  (@munch <$storage_ty:ty, $language_server_ty:tt>
    #[ignore = $reason:literal]
    $test_name:ident({
      $($file:literal => $content:expr),* $(,)?
    }) => |$client:ident $(, $snapshot:ident)?| $body:block
    $(, $($rest:tt)*)?
  ) => {
    $crate::lsp_test!(@impl_ignore <$storage_ty, $language_server_ty>
      $test_name({$($file => $content),*}) => |$client $(, $snapshot)?| $body
      ; ignore_reason = $reason
    );
    $($crate::lsp_test!(@munch <$storage_ty, $language_server_ty> $($rest)*);)?
  };

  // Munch: #[error("message")] variant
  (@munch <$storage_ty:ty, $language_server_ty:tt>
    #[error($expected_error:literal)]
    $test_name:ident({
      $($file:literal => $content:expr),* $(,)?
    }) => |$client:ident $(, $snapshot:ident)?| $body:block
    $(, $($rest:tt)*)?
  ) => {
    $crate::lsp_test!(@impl <$storage_ty, $language_server_ty>
      $test_name({$($file => $content),*}) => |$client $(, $snapshot)?| $body
      ; error_expectation = (true, Some($expected_error))
    );
    $($crate::lsp_test!(@munch <$storage_ty, $language_server_ty> $($rest)*);)?
  };

  // Munch: #[error] variant (no message)
  (@munch <$storage_ty:ty, $language_server_ty:tt>
    #[error]
    $test_name:ident({
      $($file:literal => $content:expr),* $(,)?
    }) => |$client:ident $(, $snapshot:ident)?| $body:block
    $(, $($rest:tt)*)?
  ) => {
    $crate::lsp_test!(@impl <$storage_ty, $language_server_ty>
      $test_name({$($file => $content),*}) => |$client $(, $snapshot)?| $body
      ; error_expectation = (true, None::<&str>)
    );
    $($crate::lsp_test!(@munch <$storage_ty, $language_server_ty> $($rest)*);)?
  };

  // Munch: no error attribute
  (@munch <$storage_ty:ty, $language_server_ty:tt>
    $test_name:ident({
      $($file:literal => $content:expr),* $(,)?
    }) => |$client:ident $(, $snapshot:ident)?| $body:block
    $(, $($rest:tt)*)?
  ) => {
    $crate::lsp_test!(@impl <$storage_ty, $language_server_ty>
      $test_name({$($file => $content),*}) => |$client $(, $snapshot)?| $body
      ; error_expectation = (false, None::<&str>)
    );
    $($crate::lsp_test!(@munch <$storage_ty, $language_server_ty> $($rest)*);)?
  };

  // Munch: folder variant with #[ignore = "reason"]
  (@munch <$storage_ty:ty, $language_server_ty:tt>
    #[ignore = $reason:literal]
    $test_name:ident(folder($folder_path:literal)) => |$client:ident $(, $snapshot:ident)?| $body:block
    $(, $($rest:tt)*)?
  ) => {
    $crate::lsp_test!(@impl_folder_ignore <$storage_ty, $language_server_ty>
      $test_name(folder($folder_path)) => |$client $(, $snapshot)?| $body
      ; ignore_reason = $reason
    );
    $($crate::lsp_test!(@munch <$storage_ty, $language_server_ty> $($rest)*);)?
  };

  // Munch: folder variant with #[error("message")]
  (@munch <$storage_ty:ty, $language_server_ty:tt>
    #[error($expected_error:literal)]
    $test_name:ident(folder($folder_path:literal)) => |$client:ident $(, $snapshot:ident)?| $body:block
    $(, $($rest:tt)*)?
  ) => {
    $crate::lsp_test!(@impl_folder <$storage_ty, $language_server_ty>
      $test_name(folder($folder_path)) => |$client $(, $snapshot)?| $body
      ; error_expectation = (true, Some($expected_error))
    );
    $($crate::lsp_test!(@munch <$storage_ty, $language_server_ty> $($rest)*);)?
  };

  // Munch: folder variant with #[error]
  (@munch <$storage_ty:ty, $language_server_ty:tt>
    #[error]
    $test_name:ident(folder($folder_path:literal)) => |$client:ident $(, $snapshot:ident)?| $body:block
    $(, $($rest:tt)*)?
  ) => {
    $crate::lsp_test!(@impl_folder <$storage_ty, $language_server_ty>
      $test_name(folder($folder_path)) => |$client $(, $snapshot)?| $body
      ; error_expectation = (true, None::<&str>)
    );
    $($crate::lsp_test!(@munch <$storage_ty, $language_server_ty> $($rest)*);)?
  };

  // Munch: folder variant without attributes
  (@munch <$storage_ty:ty, $language_server_ty:tt>
    $test_name:ident(folder($folder_path:literal)) => |$client:ident $(, $snapshot:ident)?| $body:block
    $(, $($rest:tt)*)?
  ) => {
    $crate::lsp_test!(@impl_folder <$storage_ty, $language_server_ty>
      $test_name(folder($folder_path)) => |$client $(, $snapshot)?| $body
      ; error_expectation = (false, None::<&str>)
    );
    $($crate::lsp_test!(@munch <$storage_ty, $language_server_ty> $($rest)*);)?
  };

  // Munch: base case - empty
  (@munch <$storage_ty:ty, $language_server_ty:tt>) => {};

  // Single implementation for all cases
  // @impl_ignore: generate a #[test] #[ignore] function
  (@impl_ignore <$storage_ty:ty, $language_server_ty:tt>
    $test_name:ident({
      $($file:literal => $content:expr),* $(,)?
    }) => |$client:ident $(, $snapshot_binding:ident)?| $body:block
    ; ignore_reason = $reason:literal
  ) => {
    paste::paste!{
        #[test]
        #[ignore = $reason]
        fn [<$test_name>]() -> std::result::Result<(), std::boxed::Box<(dyn std::error::Error + 'static)>> {
        let mut snapshot = ferrotype::Ferrotype::new();

        $crate::test::traced_test(
          stringify!($test_name),
          &[$(($file, $content)),*],
            $language_server_ty {},
            async |client, snapshot| {

              let $client = &client;

            $(let $snapshot_binding = snapshot;)?

            $body

            Ok(())
            },
            (false, None::<&str>),
            &mut snapshot
        )?;

        ferrotype::assert!(snapshot);

        Ok(())
      }
    }
  };

  (@impl <$storage_ty:ty, $language_server_ty:tt>
    $test_name:ident({
      $($file:literal => $content:expr),* $(,)?
    }) => |$client:ident $(, $snapshot_binding:ident)?| $body:block
    ; error_expectation = $error_expectation:expr
  ) => {
    paste::paste!{
        // #[macro_rules_attribute::apply(smol_macros::test!)]
        #[test]
        fn [<$test_name>]() -> std::result::Result<(), std::boxed::Box<(dyn std::error::Error + 'static)>> {
        let mut snapshot = ferrotype::Ferrotype::new();


        $crate::test::traced_test(
          stringify!($test_name),
          &[$(($file, $content)),*],
            $language_server_ty {},
            async |client, snapshot| {

              let $client = &client;

            $(let $snapshot_binding = snapshot;)?

            $body

            Ok(())
            },
            $error_expectation,
            &mut snapshot
        )?;

        ferrotype::assert!(snapshot);

        Ok(())
      }
    }
  };

  // Folder implementation with #[ignore]
  (@impl_folder_ignore <$storage_ty:ty, $language_server_ty:tt>
    $test_name:ident(folder($folder_path:literal)) => |$client:ident $(, $snapshot_binding:ident)?| $body:block
    ; ignore_reason = $reason:literal
  ) => {
    paste::paste!{
        #[test]
        #[ignore = $reason]
        fn [<$test_name>]() -> std::result::Result<(), std::boxed::Box<(dyn std::error::Error + 'static)>> {
        let mut snapshot = ferrotype::Ferrotype::new();

        let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
        let folder_path = manifest_dir.join($folder_path);

        let workspace_uri = $crate::Uri::parse(&format!("file://test/{}/", stringify!($test_name)))
          .expect("valid workspace uri");

        let fs = $crate::fs::MemoryFileSystem::from_folder(&folder_path, workspace_uri)
          .expect(&format!("failed to load folder: {}", folder_path.display()));

        $crate::test::traced_test_with_fs::<$storage_ty, _>(
          stringify!($test_name),
          fs,
          $language_server_ty {},
          async |client, snapshot| {
            let $client = &client;
            $(let $snapshot_binding = snapshot;)?
            $body
            Ok(())
          },
          (false, None::<&str>),
          &mut snapshot,
          true,
        )?;

        ferrotype::assert!(snapshot);

        Ok(())
      }
    }
  };

  // Folder implementation (no ignore)
  (@impl_folder <$storage_ty:ty, $language_server_ty:tt>
    $test_name:ident(folder($folder_path:literal)) => |$client:ident $(, $snapshot_binding:ident)?| $body:block
    ; error_expectation = $error_expectation:expr
  ) => {
    paste::paste!{
        #[test]
        fn [<$test_name>]() -> std::result::Result<(), std::boxed::Box<(dyn std::error::Error + 'static)>> {
        let mut snapshot = ferrotype::Ferrotype::new();

        let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
        let folder_path = manifest_dir.join($folder_path);

        let workspace_uri = $crate::Uri::parse(&format!("file://test/{}/", stringify!($test_name)))
          .expect("valid workspace uri");

        let fs = $crate::fs::MemoryFileSystem::from_folder(&folder_path, workspace_uri)
          .expect(&format!("failed to load folder: {}", folder_path.display()));

        $crate::test::traced_test_with_fs::<$storage_ty, _>(
          stringify!($test_name),
          fs,
          $language_server_ty {},
          async |client, snapshot| {
            let $client = &client;
            $(let $snapshot_binding = snapshot;)?
            $body
            Ok(())
          },
          $error_expectation,
          &mut snapshot,
          true,
        )?;

        ferrotype::assert!(snapshot);

        Ok(())
      }
    }
  };
}