Example scenario:
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
Placing the cursor over context.Document and pressing Ctrl+. should yield a code fix like
var document = context.Document;
// <first location where context.Document is referenced in the method>
...
var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
@jamesqo This feature exists. You just need to select "context.Document" and say "introduce variable for all occurrences ..."
Open design question if this should be offered just based on the caret position without a selection. Maybe only for dotted name chains...
@CyrusNajmabadi +1 for no selection needed. When you say dotted name chains, are you counting methods? I think methods calls/indexers should be allowed in the chain as well.
When you say dotted name chains, are you counting methods? I think methods calls/indexers should be allowed in the chain as well.
Yup. agreed. What i don't want to do is have something like f$$oo + bar expand out to that entire expression. For that, you'd need a selection.
Most helpful comment
Open design question if this should be offered just based on the caret position without a selection. Maybe only for dotted name chains...