chickensoft-games / LogicBlocks

Human-friendly, hierarchical state machines for games and apps in C#.
https://www.nuget.org/packages/Chickensoft.LogicBlocks
MIT License
152 stars 6 forks source link

Un-commented `Debugger.Launch()` call in the generator leads to VS 2022 wanting to start its JIT-compiler #15

Closed bemayr closed 9 months ago

bemayr commented 9 months ago

First of All πŸ₯³

LogicBlocks is such a nice HFSM implementation! I've been in the space of Statecharts and C# and your class-based syntax as well as the way to handle bindings are really neat! And the documentation is superb!

Bug 🐞 (a really small one)

Now to the one thing I recently discovered, I am currently in the process of using LogicBlocks to manage Websocket connections. I'm using VS 2022 and discovered that it wants to launch a JIT compiler at startup as well as on a full rebuild. It took me a bit of time to figure out that the problem arises from the LogicBlocks.Generator plug-in, because Visual Studio is incapable of debugging itself in this aspect. Dismissing the dialog lets one easily continue working on the project, but it gets a bit tedious that the dialog appears every time the source generator is run.

image

Potential Solution πŸ‘€

I then started to dig into the Generator a bit (I've also been developing generators over the last couple of months quite a bit and you got some really useful ideas/solutions regarding generator/analyzer debugging in there πŸ’―). Might the following code be a small release mistake? In the sense that you simply forgot to remove the newline between the comment and the Debugger.Launch() call, so that the debugger gets launched everytime? I wonder why and if this works using a VSCode or Rider setup, or whether it is some other misconfiguration on my side...

https://github.com/chickensoft-games/LogicBlocks/blob/2ba212bf482668275ac2a1d4a7eeb1b0d67c96ce/Chickensoft.LogicBlocks.Generator/src/LogicBlocksGenerator.cs#L29-L34

definitelyokay commented 9 months ago

LogicBlocks is such a nice HFSM implementation! I've been in the space of Statecharts and C# and your class-based syntax as well as the way to handle bindings are really neat! And the documentation is superb!

@bemayr Thank you so much, that really means a lot!

Might the following code be a small release mistake?

That is indeed a huge mistake, and one that has been bothering me too πŸ˜† I wondered why I had started seeing that happen a lot more...

I develop primarily on macOS with Visual Studio Code. It does not prompt to hook into a debugger, even with that code. I would switch to my Windows PC to debug the source generator if I got stuck while working on it. Hence why that statement slipped through haha.

Unrelated, but since you are the right audience:

As you can tell, the logic blocks generator was very much an "experimental" project β€” I needed this for my game project, after all, and didn't want to spend forever creating a more robust generator (I spent many months on another generator project and I was a little burnt out by the time I got around to finishing this).

That being said, if you have ideas on making the generator more sound, I'm totally open to them. There will always be cases where you can return next states that it can't detect the exact types of, but there could probably be a number of improvements made so that situations like that would be far less common. In all fairness, the generator needs a complete overhaul. So if you ever feel like you want to redo it, by all means please do ;)

definitelyokay commented 9 months ago

Fixed in #16

bemayr commented 9 months ago

Thanks so much for already publishing a fixed version! I'm gonna update today and enjoy the awesomeness of visualizable code 😍


I am seriously impressed that you manage to develop a source generator while having to switch to a different PC for debugging, it feels like I am spending so much time in the debugger trying to find all the nasty edge cases...


Unrelated, but since you are the right audience:

I am so glad you ask, because it is not too easy to find the right audience for source generators/analyzers!

I was a little burnt out by the time I got around to finishing this

What a pity to hear this, but I can fully relate to that, for me it is this kind of wave-form oscillating between loving developing them and completely being sick of it, because of how they have to be developed.

Re: Generator Rewrite

Thanks for the explanation regarding where the necessity for the Generator comes from and why you approached it that way! I started innerspacetrainings/Statecharts.NET around 4 years ago with the intention of translating XState to C# for using it in Unity (you could visualize Statecharts at runtime by utilizing XState's visualizer in the browser), but things happened and the company decided against adopting Statecharts, so I moved on and now I am core member at StateML where we try to create this language-independent Statechart dialect that can be cross-compiled to various languages and Bindings (as defined in LogicBlocks) are created in the host language. I am creating the C# adapter and went the other way round, by generating C# code based on StateML sources. BUT, I think LogicBlocks and StateML have so many things in common and both are built in a modular way, that they might be able to use each others tooling (or at least part of it).

So I am still figuring out a proper (non-burning-out and sustainable) way to approach source generators, once I get along with this, I will definitely look at the LogicBlocks generator again! πŸ’― Apart from reading other people's generators I recently met Anton Risberg AlakΓΌla who is working on lu-cs-sde/codeprober, a tool that allows you to inspect compiler output in a way I have never seen before. We already talked about pairing up to create a Roslyn adapter for codeprober.

I will keep you updated! (prob. via Discord, because of this not being an issue anymore 😊)

definitelyokay commented 9 months ago

@bemayr by all means, feel free to reach out on Discord! I love talking about state management.

StateML looks great β€” as a bonus, if you all can figure out how to solve the "my code changed and now my source-of-truth spec is out of date" problem (the old two way synchronization problem!) you will have done something great for the world. Although that might be just a little out of scope, but one can dream πŸ˜†

Codeprober also looks really fascinating, thank you for sharing!