public XamarinStackFrame(XamarinEngine engine, XamarinThread thread, Mono.Debugging.Client.StackFrame stackFrame) { _engine = engine; _thread = thread; _stackFrame = stackFrame; _parameters = _stackFrame.GetParameters(); _locals = _stackFrame.GetLocalVariables(); _thisObject = _stackFrame.GetThisReference(); }
public async Task <Mono.Debugging.Client.CompletionData> GetExpressionCompletionData(string exp, Mono.Debugging.Client.StackFrame frame, CancellationToken token) { var location = frame.SourceLocation; var document = DocumentContext.AnalysisDocument; if (document == null) { return(null); } var solution = DocumentContext.RoslynWorkspace.CurrentSolution; var originalSnapshot = Editor.TextView.TextBuffer.CurrentSnapshot; var text = originalSnapshot.GetText(new Span(0, originalSnapshot.Length)); var insertOffset = GetAdjustedContextPoint(originalSnapshot.GetLineFromLineNumber(location.EndLine - 1).Start.Position + location.EndColumn - 1, document); text = text.Insert(insertOffset, ";" + exp + ";"); insertOffset++; //advance for 1 which represents `;` before expression var textBuffer = PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer(text, Editor.TextView.TextBuffer.ContentType); var snapshot = textBuffer.CurrentSnapshot; try { //Workaround Mono bug: https://github.com/mono/mono/issues/8700 snapshot.AsText(); } catch (Exception) { } // Fork the solution using this new primary buffer for the document and all of its linked documents. var forkedSolution = solution.WithDocumentText(document.Id, snapshot.AsText(), PreservationMode.PreserveIdentity); foreach (var link in document.GetLinkedDocumentIds()) { forkedSolution = forkedSolution.WithDocumentText(link, snapshot.AsText(), PreservationMode.PreserveIdentity); } // Put it into a new workspace, and open it and its related documents // with the projection buffer as the text. var forkedWorkspace = new DebuggerIntelliSenseWorkspace(forkedSolution); forkedWorkspace.OpenDocument(document.Id, textBuffer.AsTextContainer()); foreach (var link in document.GetLinkedDocumentIds()) { forkedWorkspace.OpenDocument(link, textBuffer.AsTextContainer()); } var cs = forkedWorkspace.Services.GetLanguageServices(LanguageNames.CSharp).GetService <CompletionService> (); var trigger = new CompletionTrigger(CompletionTriggerKind.Invoke, '\0'); var roslynCompletions = await cs.GetCompletionsAsync(forkedWorkspace.CurrentSolution.GetDocument(document.Id), insertOffset + exp.Length, trigger, cancellationToken : token).ConfigureAwait(false); if (roslynCompletions == null) { return(null); } var result = new Mono.Debugging.Client.CompletionData(); foreach (var roslynCompletion in roslynCompletions.Items) { if (roslynCompletion.Tags.Contains(WellKnownTags.Snippet)) { continue; } result.Items.Add(new Mono.Debugging.Client.CompletionItem(roslynCompletion.DisplayText, RoslynTagsToDebuggerFlags(roslynCompletion.Tags))); } result.ExpressionLength = roslynCompletions.Span.Length; return(result); }