SiteContents not being persisted to the generator?
absolutejam opened this issue · comments
Describe the bug
First off, sorry if this isn't the correct place for this. I have a strong feeling it's more PICNIC than an actual bug, but perhaps shedding a bit of light on this might be valuable for anyone in the same position. I also tried casting my hook into the Slack, but didn't get any bites.
I've restructured the basic example a little and was just toying with Fornax generally, but I'm finding that whatever I put in to my SiteContents
within my loaders is not then available in my generators. I'm not sure if I'm missing something super basic, but I was hoping I could get a little bit of guidance. If it's something that perhaps needs clearing up in the docs for clueless people like me, I'm happy to help with that.
I've tried a number of dfferent types, and I've also been able to confirm that the record goes in to the DI container (as I can get it back out within the loader), but once I come to the generator stage, I can't seem to retrieve them. I know it's something obvious I'm missing...
I've created a dump of the repo I was working on here here.
To Reproduce
Steps to reproduce the behaviour:
- Clone the example
fornax watch
- Observe the exception that the
Site
record couldn't be pulled from the DI container, despite being added in thegloballoader.fsx
Environment (please complete the following information):
- OS: macOS Mojave
- Ionide version:
- VSCode version: 1.50.0
- dotnet SDK version:
- mono / .Net Framework version: 5.0 RC1
----------EDIT----------
I see, looks like I was wrong.
FTR the error I was getting on fornax watch
is:
`An unexpected error happend:
System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation.
--->
System.Exception: Could not get FSI_0016.Types+Site
at FSI_0016.Helpers.SiteContents.GetValue[t](SiteContents X1)
at FSI_0016.Post.generate(SiteContents ctx, String projectRoot, String page)
--- End of inner exception stack trace ---.`
Sorry, I'm not sure why I didn't include the stack trace originally 🤦
Is it possible to add break points to Fornax, or would I have to clone, build and run it like that?
Ok, this is tricky. Basically, as far as I understand, the issue is a result of including types.fsx
file multiple times - it's included in every loader and every generator (through includes.fsx
file). Every time you include types.fsx
file new Site
record type is defined and as a result, those are actually different types (if you'd inspect all that through reflection you'd notice the fully qualified names of types are different).
The solution to that is to include types.fsx
file normally only once (just in globalloader.fsx
for example), and for all other files it needs to be added in #if !FORNAX
section - this will "power" editor tooling but won't be actually evaluated in underlying F# Interactive session that Fornax creates.
Thanks for looking at this @Krzysztof-Cieslak!
I'll have a look at doing that and see where I get with it. Now I understand the use of the #if !FORNAX
directive too, awesome.