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

Commit d184f32

Browse files
authored
Merge pull request #9429 from mono/jstedfast-debugger-sourcelink-in-nosourceview
[Debugger] Move the Download-via-SourceLink prompt into the NoSourceV…
2 parents 6a92a4f + f71636b commit d184f32

File tree

3 files changed

+256
-135
lines changed

3 files changed

+256
-135
lines changed

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/DebuggingService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
//
2727
//
2828

29+
/*
30+
* Some places we should be doing some error handling we used to toss
31+
* exceptions, now we error out silently, this needs a real solution.
32+
*/
33+
2934
using System;
3035
using System.Xml;
3136
using System.Linq;
@@ -39,17 +44,17 @@
3944

4045
using Mono.Debugging.Client;
4146

42-
using Microsoft.VisualStudio.Text;
4347
using Microsoft.CodeAnalysis.Text;
48+
using Microsoft.VisualStudio.Text;
4449

4550
using MonoDevelop.Ide;
4651
using MonoDevelop.Core;
4752
using MonoDevelop.Ide.Gui;
4853
using MonoDevelop.Projects;
4954
using MonoDevelop.Components;
5055
using MonoDevelop.Core.Execution;
51-
using MonoDevelop.Ide.TextEditing;
5256
using MonoDevelop.Ide.Gui.Content;
57+
using MonoDevelop.Ide.TextEditing;
5358
using MonoDevelop.Debugger.Viewers;
5459
using MonoDevelop.Core.Instrumentation;
5560

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/Initializer.cs

Lines changed: 29 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@
2626
//
2727

2828
using System;
29-
using MonoDevelop.Ide.Gui;
30-
using MonoDevelop.Components.Commands;
31-
using Mono.Debugging.Client;
32-
using MonoDevelop.Ide.Commands;
33-
using MonoDevelop.Core;
34-
using MonoDevelop.Ide;
3529
using System.IO;
30+
using System.Threading.Tasks;
31+
32+
using Mono.Debugging.Client;
3633

37-
using Xwt;
34+
using MonoDevelop.Ide;
35+
using MonoDevelop.Core;
36+
using MonoDevelop.Ide.Gui;
3837
using MonoDevelop.Core.Web;
38+
using MonoDevelop.Ide.Commands;
39+
using MonoDevelop.Components.Commands;
3940

4041
namespace MonoDevelop.Debugger
4142
{
@@ -68,41 +69,40 @@ void OnStackChanged (object s, EventArgs a)
6869

6970
async void OnFrameChanged (object s, EventArgs a)
7071
{
71-
if (changingFrame) {
72+
if (changingFrame)
7273
return;
73-
}
74+
75+
changingFrame = true;
76+
7477
try {
75-
changingFrame = true;
7678
if (disassemblyDoc != null && DebuggingService.IsFeatureSupported (DebuggerFeatures.Disassembly))
7779
disassemblyView.Update ();
7880

7981
var frame = DebuggingService.CurrentFrame;
80-
if (frame == null) {
82+
if (frame == null)
8183
return;
82-
}
8384

85+
var debuggerOptions = DebuggingService.GetUserOptions ();
8486
FilePath file = frame.SourceLocation.FileName;
85-
8687
int line = frame.SourceLocation.Line;
88+
8789
if (line != -1) {
8890
if (!file.IsNullOrEmpty && File.Exists (file)) {
8991
var doc = await IdeApp.Workbench.OpenDocument (file, null, line, 1, OpenDocumentOptions.Debugger);
90-
if (doc != null) {
92+
if (doc != null)
9193
return;
92-
}
9394
}
94-
bool alternateLocationExists = false;
95+
9596
if (frame.SourceLocation.FileHash != null) {
9697
var newFilePath = SourceCodeLookup.FindSourceFile (file, frame.SourceLocation.FileHash);
9798
if (newFilePath != null && File.Exists (newFilePath)) {
9899
frame.UpdateSourceFile (newFilePath);
99100
var doc = await IdeApp.Workbench.OpenDocument (newFilePath, null, line, 1, OpenDocumentOptions.Debugger);
100-
if (doc != null) {
101+
if (doc != null)
101102
return;
102-
}
103103
}
104104
}
105-
var debuggerOptions = DebuggingService.GetUserOptions ();
105+
106106
var automaticSourceDownload = debuggerOptions.AutomaticSourceLinkDownload;
107107

108108
var sourceLink = frame.SourceLocation.SourceLink;
@@ -111,53 +111,23 @@ async void OnFrameChanged (object s, EventArgs a)
111111
Document doc = null;
112112
// ~/Library/Caches/VisualStudio/8.0/Symbols/org/projectname/git-sha/path/to/file.cs
113113
if (!File.Exists (downloadLocation)) {
114-
if (automaticSourceDownload == AutomaticSourceDownload.Always) {
115-
doc = await DownloadAndOpenFileAsync (frame, line, sourceLink);
116-
} else {
117-
var hyperlink = $"<a href='{ sourceLink.Uri }'>{ Path.GetFileName (sourceLink.RelativeFilePath) }</a>";
118-
var stackframeText = $"<b>{frame.FullStackframeText}</b>";
119-
120-
var text = GettextCatalog.GetString
121-
("{0} is a call to external source code. Would you like to get '{1}' and view it?", stackframeText, hyperlink);
122-
var message = new Ide.GenericMessage {
123-
Text = GettextCatalog.GetString ("External source code available"),
124-
SecondaryText = text
125-
};
126-
message.AddOption (nameof (automaticSourceDownload), GettextCatalog.GetString ("Always get source code automatically"), false);
127-
message.Buttons.Add (AlertButton.Cancel);
128-
message.Buttons.Add (new AlertButton (GettextCatalog.GetString ("Get and Open")));
129-
message.DefaultButton = 1;
130-
131-
var didNotCancel = MessageService.GenericAlert (message) != AlertButton.Cancel;
132-
if (didNotCancel) {
133-
if (message.GetOptionValue (nameof (automaticSourceDownload))) {
134-
debuggerOptions.AutomaticSourceLinkDownload = AutomaticSourceDownload.Always;
135-
DebuggingService.SetUserOptions (debuggerOptions);
136-
}
137-
doc = await DownloadAndOpenFileAsync (frame, line, sourceLink);
138-
}
139-
}
114+
if (automaticSourceDownload == AutomaticSourceDownload.Always)
115+
doc = await NoSourceView.DownloadAndOpenAsync (frame);
140116
} else {
141117
// The file has previously been downloaded for a different solution.
142118
// We need to map the cached location
143119
frame.UpdateSourceFile (downloadLocation);
144120
doc = await IdeApp.Workbench.OpenDocument (downloadLocation, null, line, 1, OpenDocumentOptions.Debugger);
145121
}
146-
if (doc != null) {
122+
if (doc != null)
147123
return;
148-
}
149124
}
150125
}
151126

152-
bool disassemblyNotSupported = false;
153-
// If we don't have an address space, we can't disassemble
154-
if (string.IsNullOrEmpty (frame.AddressSpace))
155-
disassemblyNotSupported = true;
156-
157-
if (!DebuggingService.CurrentSessionSupportsFeature (DebuggerFeatures.Disassembly))
158-
disassemblyNotSupported = true;
127+
bool disassemblySupported = !string.IsNullOrEmpty (frame.AddressSpace) &&
128+
DebuggingService.CurrentSessionSupportsFeature (DebuggerFeatures.Disassembly);
159129

160-
if (disassemblyNotSupported && disassemblyDoc != null) {
130+
if (!disassemblySupported && disassemblyDoc != null) {
161131
disassemblyDoc.Close ().Ignore ();
162132
disassemblyDoc = null;
163133
disassemblyView = null;
@@ -167,14 +137,14 @@ async void OnFrameChanged (object s, EventArgs a)
167137
if (disassemblyDoc == null) {
168138
if (noSourceDoc == null) {
169139
noSourceView = new NoSourceView ();
170-
noSourceView.Update (disassemblyNotSupported);
140+
noSourceView.Update (debuggerOptions, frame, disassemblySupported);
171141
noSourceDoc = await IdeApp.Workbench.OpenDocument (noSourceView, true);
172142
noSourceDoc.Closed += delegate {
173143
noSourceDoc = null;
174144
noSourceView = null;
175145
};
176146
} else {
177-
noSourceView.Update (disassemblyNotSupported);
147+
noSourceView.Update (debuggerOptions, frame, disassemblySupported);
178148
noSourceDoc.Select ();
179149
}
180150
} else {
@@ -185,34 +155,6 @@ async void OnFrameChanged (object s, EventArgs a)
185155
}
186156
}
187157

188-
async System.Threading.Tasks.Task<Document> DownloadAndOpenFileAsync (StackFrame frame, int line, SourceLink sourceLink)
189-
{
190-
var pm = IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor (
191-
GettextCatalog.GetString ("Downloading {0}", sourceLink.Uri),
192-
Stock.StatusDownload,
193-
true
194-
);
195-
196-
Document doc = null;
197-
try {
198-
var downloadLocation = sourceLink.GetDownloadLocation (symbolCachePath);
199-
Directory.CreateDirectory (Path.GetDirectoryName (downloadLocation));
200-
DocumentRegistry.SkipNextChange (downloadLocation);
201-
var client = HttpClientProvider.CreateHttpClient (sourceLink.Uri);
202-
using (var stream = await client.GetStreamAsync (sourceLink.Uri).ConfigureAwait (false))
203-
using (var fs = new FileStream (downloadLocation, FileMode.Create)) {
204-
await stream.CopyToAsync (fs).ConfigureAwait (false);
205-
}
206-
frame.UpdateSourceFile (downloadLocation);
207-
doc = await Runtime.RunInMainThread (() => IdeApp.Workbench.OpenDocument (downloadLocation, null, line, 1, OpenDocumentOptions.Debugger));
208-
} catch (Exception ex) {
209-
LoggingService.LogInternalError ("Error downloading SourceLink file", ex);
210-
} finally {
211-
pm.Dispose ();
212-
}
213-
return doc;
214-
}
215-
216158
async void OnShowDisassembly (object s, EventArgs a)
217159
{
218160
if (disassemblyDoc == null) {
@@ -230,11 +172,11 @@ async void OnShowDisassembly (object s, EventArgs a)
230172

231173
static void SetSourceCodeFrame ()
232174
{
233-
Backtrace bt = DebuggingService.CurrentCallStack;
175+
var bt = DebuggingService.CurrentCallStack;
234176

235177
if (bt != null) {
236178
for (int n = 0; n < bt.FrameCount; n++) {
237-
StackFrame sf = bt.GetFrame (n);
179+
var sf = bt.GetFrame (n);
238180

239181
if (!sf.IsExternalCode &&
240182
sf.SourceLocation.Line != -1 &&

0 commit comments

Comments
 (0)