Skip to content

Commit

Permalink
Ensure the syntax tree has the right options.
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Dec 19, 2016
1 parent e59176f commit 3592f53
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,20 @@ where outSymbol.Equals(symbol)
currentLocalDeclarator,
currentLocalDeclarator.WithInitializer(null));

var rootWithoutInitializerTree = root.SyntaxTree.WithRootAndOptions(
rootWithoutInitializer, root.SyntaxTree.Options);

// Fork the compilation so we can do this analysis.
var newCompilation = semanticModel.Compilation.ReplaceSyntaxTree(
root.SyntaxTree, rootWithoutInitializer.SyntaxTree);
var newSemanticModel = newCompilation.GetSemanticModel(rootWithoutInitializer.SyntaxTree);
root.SyntaxTree, rootWithoutInitializerTree);
var newSemanticModel = newCompilation.GetSemanticModel(rootWithoutInitializerTree);

// NOTE: there is no current compiler API to determine if a variable is definitely
// assigned or not. So, for now, we just get diagnostics for this block and see if
// we get any definite assigment errors where we have a reference to the symbol. If
// so, then we don't offer the fix.

rootWithoutInitializer = (CompilationUnitSyntax)rootWithoutInitializerTree.GetRoot(cancellationToken);
var currentBlock = rootWithoutInitializer.GetCurrentNode(enclosingBlock);
var diagnostics = newSemanticModel.GetDiagnostics(currentBlock.Span, cancellationToken);

Expand Down

0 comments on commit 3592f53

Please sign in to comment.