Skip to content

Commit 802f957

Browse files
committed
Fix issue with world stubs
Signed-off-by: James Sturtevant <[email protected]>
1 parent 532c2df commit 802f957

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

crates/csharp/src/lib.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,22 @@ impl WorldGenerator for CSharp {
441441
files.push(&format!("{name}.cs"), indent(&src).as_bytes());
442442

443443
let generate_stub =
444-
|name: String, files: &mut Files, fragments: &Vec<InterfaceFragment>| {
444+
|name: String, files: &mut Files, stubs: Stubs| {
445445
let stub_file_name = format!("{name}Impl");
446446
let interface_name = CSharp::get_class_name_from_qualified_name(name.clone());
447447
let stub_class_name = format!("{interface_name}Impl");
448448

449+
let (fragments, fully_qaulified_namespace) = match stubs {
450+
Stubs::World(fragments) => {
451+
let fully_qaulified_namespace = format!("{namespace}");
452+
(fragments, fully_qaulified_namespace)
453+
},
454+
Stubs::Interface(fragments) => {
455+
let fully_qaulified_namespace = format!("{namespace}.{name}");
456+
(fragments, fully_qaulified_namespace)
457+
},
458+
};
459+
449460
let body = fragments
450461
.iter()
451462
.map(|f| f.stub.deref())
@@ -456,7 +467,7 @@ impl WorldGenerator for CSharp {
456467
"// Generated by `wit-bindgen` {version}. DO NOT EDIT!
457468
{CSHARP_IMPORTS}
458469
459-
namespace {namespace}.{name};
470+
namespace {fully_qaulified_namespace};
460471
461472
public partial class {stub_class_name} : {interface_name} {{
462473
{body}
@@ -467,10 +478,9 @@ impl WorldGenerator for CSharp {
467478
files.push(&format!("{stub_file_name}.cs"), indent(&body).as_bytes());
468479
};
469480

470-
// TODO: is the world Impl class useful?
471-
// if self.opts.generate_stub {
472-
// generate_stub(format!("{name}"), files);
473-
// }
481+
if self.opts.generate_stub {
482+
generate_stub(format!("{name}World"), files, Stubs::World(&self.world_fragments));
483+
}
474484

475485
files.push(
476486
&format!("{snake}_component_type.o",),
@@ -529,7 +539,7 @@ impl WorldGenerator for CSharp {
529539
files.push(&format!("{name}Interop.cs"), indent(&body).as_bytes());
530540

531541
if interface_type_and_fragments.is_export && self.opts.generate_stub {
532-
generate_stub(format!("{name}"), files, fragments);
542+
generate_stub(format!("{name}"), files, Stubs::Interface(fragments));
533543
}
534544
}
535545
}
@@ -1259,6 +1269,11 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
12591269
}
12601270
}
12611271

1272+
enum Stubs<'a> {
1273+
World(&'a Vec<InterfaceFragment>),
1274+
Interface(&'a Vec<InterfaceFragment>)
1275+
}
1276+
12621277
struct Block {
12631278
_body: String,
12641279
_results: Vec<String>,

crates/csharp/tests/codegen.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ macro_rules! codegen_test {
5252
"result-empty",
5353
"ret-areas",
5454
"return-resource-from-export",
55-
"same-names2",
5655
"same-names5",
5756
"simple-functions",
5857
"simple-http",
5958
"simple-lists",
6059
"small-anonymous",
61-
"smoke-default",
6260
"strings",
6361
"unused-import",
6462
"use-across-interfaces",

0 commit comments

Comments
 (0)