Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 63298a2

Browse files
fix #399: NotImplementedException when updating watch pad in decompiled code
1 parent 11662db commit 63298a2

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Collections.Generic;
2121
using System.Linq;
2222
using System.Reflection;
23+
using System.Text;
2324
using System.Threading;
2425
using ICSharpCode.Core;
2526
using ICSharpCode.NRefactory;
@@ -82,7 +83,32 @@ public ICodeContext ResolveContext(ParseInformation parseInfo, TextLocation loca
8283

8384
public ResolveResult ResolveSnippet(ParseInformation parseInfo, TextLocation location, string codeSnippet, ICompilation compilation, CancellationToken cancellationToken)
8485
{
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();
86112
}
87113

88114
public void FindLocalReferences(ParseInformation parseInfo, ITextSource fileContent, IVariable variable, ICompilation compilation, Action<SearchResultMatch> callback, CancellationToken cancellationToken)

src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertMissingTokensDecorator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public override void EndNode(AstNode node)
6161
public override void WriteToken(Role role, string token)
6262
{
6363
CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role);
64+
t.Role = role;
6465
EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement;
6566
if (node == null)
6667
currentList.Add(t);

0 commit comments

Comments
 (0)