From 51481d9230e15b99fe0a73bbd35001a15c96e007 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 29 May 2015 14:27:05 +0200 Subject: [PATCH] fix some bugs in the ILSpy debugger integration --- .../Debugger/Debugger.Core/PdbSymbolSource.cs | 2 +- .../ILSpyAddIn/DecompiledViewContent.cs | 38 ++++++++++++++++++- .../DisplayBindings/ILSpyAddIn/ILSpyParser.cs | 3 +- .../ILSpyAddIn/ILSpySymbolSource.cs | 3 +- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs b/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs index 945242fbe3..56c1f78431 100644 --- a/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs +++ b/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs @@ -256,7 +256,7 @@ namespace Debugger var s = seqPoints[i]; if (s.ContainsLocation(line, column)) return s; - if (s.StartLine > line) + if (s.StartLine > line || (s.StartLine == line && s.StartColumn > column)) return s; } return null; diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/DecompiledViewContent.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/DecompiledViewContent.cs index ad9818dcf3..e31cc7b045 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/DecompiledViewContent.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/DecompiledViewContent.cs @@ -27,6 +27,7 @@ using ICSharpCode.AvalonEdit.AddIn; using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.Core; using ICSharpCode.Decompiler; +using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.ILSpyAddIn; using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.TypeSystem; @@ -39,12 +40,13 @@ namespace ICSharpCode.ILSpyAddIn /// /// Hosts a decompiled type. /// - class DecompiledViewContent : AbstractViewContentWithoutFile + class DecompiledViewContent : AbstractViewContentWithoutFile, IPositionable { /// /// Entity to jump to once decompilation has finished. /// string jumpToEntityIdStringWhenDecompilationFinished; + int jumpToLineWhenDecompilationFinished, jumpToColumnWhenDecompilationFinished; bool decompilationFinished; @@ -72,6 +74,9 @@ namespace ICSharpCode.ILSpyAddIn this.codeEditor.FileName = this.DecompiledTypeName.ToFileName(); this.codeEditor.ActiveTextEditor.IsReadOnly = true; this.codeEditor.ActiveTextEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#"); + + this.Services.RemoveService(typeof(IPositionable)); + this.Services.AddService(typeof(IPositionable), this); } #endregion @@ -169,7 +174,10 @@ namespace ICSharpCode.ILSpyAddIn codeEditor.Document.UndoStack.ClearAll(); this.decompilationFinished = true; - JumpToEntity(this.jumpToEntityIdStringWhenDecompilationFinished); + if (!string.IsNullOrEmpty(jumpToEntityIdStringWhenDecompilationFinished)) + JumpToEntity(this.jumpToEntityIdStringWhenDecompilationFinished); + else + JumpTo(jumpToLineWhenDecompilationFinished, jumpToColumnWhenDecompilationFinished); // update UI //UpdateIconMargin(); @@ -228,5 +236,31 @@ namespace ICSharpCode.ILSpyAddIn } #endregion + + #region IPositionable implementation + + public void JumpTo(int line, int column) + { + if (decompilationFinished) { + codeEditor.ActiveTextEditorAdapter.JumpTo(line, column); + } else { + jumpToLineWhenDecompilationFinished = line; + jumpToColumnWhenDecompilationFinished = column; + } + } + + public int Line { + get { + return codeEditor.ActiveTextEditor.TextArea.Caret.Line; + } + } + + public int Column { + get { + return codeEditor.ActiveTextEditor.TextArea.Caret.Column; + } + } + + #endregion } } diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs index de246b0a27..525186f71e 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs @@ -31,6 +31,7 @@ using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Dom.ClassBrowser; +using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor.Search; using ICSharpCode.SharpDevelop.Parser; using ICSharpCode.SharpDevelop.Project; @@ -48,7 +49,7 @@ namespace ICSharpCode.ILSpyAddIn return fileName != null && fileName.StartsWith("ilspy://", StringComparison.OrdinalIgnoreCase); } - readonly static ITextSource EmptyFileContent = new StringTextSource(""); + readonly ITextSource EmptyFileContent = new StringTextSource("", new OnDiskTextSourceVersion(DateTime.MinValue)); public ITextSource GetFileContent(FileName fileName) { diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs index 24a89a5cb8..03133d7d5d 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs @@ -29,7 +29,8 @@ namespace ICSharpCode.ILSpyAddIn var typeName = DecompiledTypeReference.FromTypeDefinition(method.DeclaringTypeDefinition); if (typeName == null) return null; SD.Log.DebugFormatted("GetSymbols for: {0}", typeName.ToFileName()); - return SD.ParserService.ParseFile(typeName.ToFileName()) as ILSpyUnresolvedFile; + // full parse info required to make ParserService caching possible... + return SD.ParserService.Parse(typeName.ToFileName()).UnresolvedFile as ILSpyUnresolvedFile; } public Debugger.SequencePoint GetSequencePoint(IMethod method, int iloffset)