|
20 | 20 | using System.Collections.Generic; |
21 | 21 | using System.Linq; |
22 | 22 | using System.Reflection; |
| 23 | +using System.Text; |
23 | 24 | using System.Threading; |
24 | 25 | using ICSharpCode.Core; |
25 | 26 | using ICSharpCode.NRefactory; |
@@ -82,7 +83,32 @@ public ICodeContext ResolveContext(ParseInformation parseInfo, TextLocation loca |
82 | 83 |
|
83 | 84 | public ResolveResult ResolveSnippet(ParseInformation parseInfo, TextLocation location, string codeSnippet, ICompilation compilation, CancellationToken cancellationToken) |
84 | 85 | { |
85 | | - return null; |
| 86 | + var decompiledParseInfo = parseInfo as ILSpyFullParseInformation; |
| 87 | + if (decompiledParseInfo == null) |
| 88 | + throw new ArgumentException("ParseInfo does not have SyntaxTree"); |
| 89 | + CSharpAstResolver contextResolver = new CSharpAstResolver(compilation, decompiledParseInfo.SyntaxTree, null); |
| 90 | + var node = decompiledParseInfo.SyntaxTree.GetNodeAt(location); |
| 91 | + CSharpResolver context; |
| 92 | + if (node != null) |
| 93 | + context = contextResolver.GetResolverStateAfter(node, cancellationToken); |
| 94 | + else |
| 95 | + context = new CSharpResolver(compilation); |
| 96 | + CSharpParser parser = new CSharpParser(); |
| 97 | + var expr = parser.ParseExpression(codeSnippet); |
| 98 | + if (parser.HasErrors) |
| 99 | + return new ErrorResolveResult(SpecialType.UnknownType, PrintErrorsAsString(parser.Errors), TextLocation.Empty); |
| 100 | + CSharpAstResolver snippetResolver = new CSharpAstResolver(context, expr); |
| 101 | + return snippetResolver.Resolve(expr, cancellationToken); |
| 102 | + } |
| 103 | + |
| 104 | + string PrintErrorsAsString(IEnumerable<Error> errors) |
| 105 | + { |
| 106 | + StringBuilder builder = new StringBuilder(); |
| 107 | + |
| 108 | + foreach (var error in errors) |
| 109 | + builder.AppendLine(error.Message); |
| 110 | + |
| 111 | + return builder.ToString(); |
86 | 112 | } |
87 | 113 |
|
88 | 114 | public void FindLocalReferences(ParseInformation parseInfo, ITextSource fileContent, IVariable variable, ICompilation compilation, Action<SearchResultMatch> callback, CancellationToken cancellationToken) |
|
0 commit comments