#[Rider] marking methods as expensive/unrecommended

1 messages · Page 1 of 1 (latest)

lucid herald
#

Rider users, question: is there a way to specify custom warnings for my code and/or mark methods as expensive?

Like, if I type Animator.Play("attack") Rider would suggest me to cache the hash of the state name as a static read-only variable and use that instead. Can I do something similar with my own class?

And even more advanced: is it possible to mark Unity own api stuff that way? Say, if I recommend using a TimeTrack object over modifying Time.timeScale, can I show that in the IDE?

haughty flint
#

You can write your own Roslyn analyzers to provide diagnostics and even code actions. The diagnostics you see on "empty Unity message" and "optional chaining on Unity.Object" are done by analyzers.

lucid herald
#

I see, I will look into it

ruby iron
#

If you add the ReSharper hint above the method declaration (either manually or through the Frequently called code vision hint), all callsites of that method will tell you about it being expensive. And for that TimeTrack object over Time.timeScale thing, yeah, I think a Roslyn analyzer will be the only way.

haughty flint
#

Yeah and keep in mind that ReSharper hint is IDE specific, it won't work for people using other IDEs, and there's also no way to enforce it during build. A proper diagnostic emitted by analyzer will show up no matter the IDE and also show up in Unity console if you set it to warning, and you can set it to error to fail the build.