Created
April 29, 2014 17:55
-
-
Save mkrueger/11407479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ResolveResult ResolveSnippet(ParseInformation parseInfo, TextLocation location, string codeSnippet, ICompilation compilation, CancellationToken cancellationToken) | |
{ | |
var csParseInfo = parseInfo as CSharpFullParseInformation; | |
if (csParseInfo == null) | |
throw new ArgumentException("Parse info does not have SyntaxTree"); | |
CSharpAstResolver contextResolver = new CSharpAstResolver(compilation, csParseInfo.SyntaxTree, csParseInfo.UnresolvedFile); | |
var node = csParseInfo.SyntaxTree.GetNodeAt(location); | |
CSharpResolver context; | |
if (node != null) | |
context = contextResolver.GetResolverStateAfter(node, cancellationToken); | |
else | |
context = new CSharpResolver(compilation); | |
CSharpParser parser = new CSharpParser(); | |
var expr = parser.ParseExpression(codeSnippet); | |
if (parser.HasErrors) | |
return new ErrorResolveResult(SpecialType.UnknownType, PrintErrorsAsString(parser.Errors), TextLocation.Empty); | |
CSharpAstResolver snippetResolver = new CSharpAstResolver(context, expr); | |
return snippetResolver.Resolve(expr, cancellationToken); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment