Rewriting AST before it ever gets to the analysis stage.

10 views
Skip to first unread message

Chris Eelmaa

unread,
Aug 19, 2016, 12:01:27 PM8/19/16
to resharper-plugins
Hello everyone,

I'd like to explore if this is possible, if yes, how would I go about it?

The request:

I'd like to be able to write an analyzer that can provide a proxy value for a certain expression and trigger a re-parsing of the document. 

The motivation:

Our code is littered with ABTests that can be either in a deployed or active state with a control and variant group. 
Determining a test's state is done through a database lookup.
For the tests that are deployed with the control group, any statement of the following form will evaluate to false:

if(ExperimentService.IsInVariant(ABTest.Test1))
{
}

I'm trying to provide tooling to make this easier to deal with at develop time by greying it out in this scenario. 
As it is, this is fairly limited and not robust because I basically have to play parser myself. 

What if the actual code is

if(!ExperimentService.IsInVariant(ABTest.Test1))

or

if(ExperimentService.IsInVariant(ABTest.Test1) || true)

A possible approach I could see provided is by allowing us to write analyzers that are fired once and rewrite the tree before the actual IDE parsing happens (or, well, just parse it a second time).
These should only fire once and allow us to replace a certain expression with another. This would allow me to swap all of these experiment calls for true and false literals.
As a result, these sections could benefit from all the other IDE features such as code greying for unreachable code but also more intricate ones like a variable that will never have a different value

Obviously this is just an example and I'm not sure how feasible it is. Any suggestions for a proper feature or something that already exists are more than welcome.

Matt Ellis

unread,
Aug 24, 2016, 4:35:37 AM8/24/16
to resharper-plugins
Reply all
Reply to author
Forward
0 new messages