void AddMarker(int line, int coverage, List <IUnitTestMarker> documentMarkers) { var unitTextMarker = TextMarkerFactory.CreateUnitTestMarker(Editor, new CoverageUnitTestHost(coverage), new UnitTestLocation(-1)); Editor.AddMarker(line, unitTextMarker); documentMarkers.Add(unitTextMarker); }
void UpdateCurrentLineMarker(bool moveCaret) { if (currentDebugLineMarker != null) { editor.RemoveMarker(currentDebugLineMarker); currentDebugLineMarker = null; } StackFrame sf = DebuggingService.CurrentFrame; int line; if (addressLines.TryGetValue(GetAddrId(sf.Address, sf.AddressSpace), out line)) { var docLine = editor.GetLine(line); currentDebugLineMarker = TextMarkerFactory.CreateCurrentDebugLineTextMarker(editor, docLine.Offset, docLine.Length); editor.AddMarker(line, currentDebugLineMarker); if (moveCaret) { editor.CaretLine = line; GLib.Timeout.Add(100, delegate { editor.CenterToCaret(); return(false); }); } } }
void UnderLineError(Error info) { var error = TextMarkerFactory.CreateErrorMarker(Editor, info); Editor.AddMarker(error); errors.Add(error); }
public DisassemblyView() { DocumentTitle = GettextCatalog.GetString("Disassembly"); sw = new Gtk.ScrolledWindow(); editor = TextEditorFactory.CreateNewEditor(); editor.IsReadOnly = true; asmMarker = TextMarkerFactory.CreateAsmLineMarker(editor); editor.Options = DefaultSourceEditorOptions.PlainEditor; sw.AddWithViewport(editor); sw.HscrollbarPolicy = Gtk.PolicyType.Automatic; sw.VscrollbarPolicy = Gtk.PolicyType.Automatic; sw.ShowAll(); sw.Vadjustment.ValueChanged += OnScrollEditor; sw.VScrollbar.ButtonPressEvent += OnPress; sw.VScrollbar.ButtonReleaseEvent += OnRelease; sw.VScrollbar.Events |= Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask; sw.ShadowType = Gtk.ShadowType.In; sw.Sensitive = false; DebuggingService.StoppedEvent += OnStop; }
void HandleDocumentParsed(object sender, EventArgs e) { if (!IdeApp.Preferences.EnableUnitTestEditorIntegration) { return; } src.Cancel(); src = new CancellationTokenSource(); var token = src.Token; ThreadPool.QueueUserWorkItem(delegate { if (token.IsCancellationRequested || DocumentContext == null) { return; } try { GatherUnitTests(unitTestMarkers, token).ContinueWith(task => { var foundTests = task.Result; if (foundTests == null || DocumentContext == null) { return; } Application.Invoke((o, args) => { if (token.IsCancellationRequested || DocumentContext == null) { return; } foreach (var oldMarker in currentMarker) { Editor.RemoveMarker(oldMarker); } var newMarkers = new List <IUnitTestMarker> (); foreach (var foundTest in foundTests) { if (foundTest == null) { continue; } var unitTestMarker = TextMarkerFactory.CreateUnitTestMarker(Editor, new UnitTestMarkerHostImpl(this), foundTest); newMarkers.Add(unitTestMarker); var line = Editor.GetLineByOffset(foundTest.Offset); if (line != null) { Editor.AddMarker(line, unitTestMarker); } } currentMarker = newMarkers; }); }, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.NotOnFaulted); } catch (OperationCanceledException) { } }); }
void ShowDiagnostics(Diagnostic[] diagnostics) { ClearDiagnostics(); foreach (Error error in diagnostics.Select(diagnostic => diagnostic.CreateError())) { IErrorMarker marker = TextMarkerFactory.CreateErrorMarker(Editor, error); Editor.AddMarker(marker); errorMarkers.Add(marker); } }
void CreateSmartTag(CodeActionContainer fixes, int offset) { if (!AnalysisOptions.EnableFancyFeatures || fixes.IsEmpty) { RemoveWidget(); return; } var editor = Editor; if (editor == null) { RemoveWidget(); return; } if (DocumentContext.ParsedDocument == null || DocumentContext.ParsedDocument.IsInvalid) { RemoveWidget(); return; } bool first = true; var smartTagLocBegin = offset; foreach (var fix in fixes.CodeFixActions.Concat(fixes.CodeRefactoringActions)) { var textSpan = fix.ValidSegment; if (textSpan.IsEmpty) { continue; } if (first || offset < textSpan.Start) { smartTagLocBegin = textSpan.Start; } first = false; } if (currentSmartTag != null && currentSmartTagBegin == smartTagLocBegin) { return; } RemoveWidget(); currentSmartTagBegin = smartTagLocBegin; var realLoc = Editor.OffsetToLocation(smartTagLocBegin); currentSmartTag = TextMarkerFactory.CreateSmartTagMarker(Editor, smartTagLocBegin, realLoc); currentSmartTag.CancelPopup += CurrentSmartTag_CancelPopup; currentSmartTag.ShowPopup += CurrentSmartTag_ShowPopup; currentSmartTag.Tag = fixes; currentSmartTag.IsVisible = fixes.CodeFixActions.Count > 0; editor.AddMarker(currentSmartTag); }
private void OnTextBufferChanged(object sender, TextContentChangedEventArgs e) { int newPosition = _trackingPoint.GetPosition(_trackingPoint.TextBuffer.CurrentSnapshot) - 1; if (newPosition != _marker.Offset) { TextEditor.RemoveMarker(_marker); _marker = TextMarkerFactory.CreateGenericTextSegmentMarker(TextEditor, TextSegmentMarkerEffect.Underline, _marker.Color, newPosition, 1); TextEditor.AddMarker(_marker); } }
void ShowReferences(IEnumerable <MemberReference> references) { RemoveMarkers(); var lineNumbers = new HashSet <int> (); usages = ImmutableArray <Usage> .Empty; var editor = Editor; if (editor != null /*&& editor.TextViewMargin != null*/) { if (references != null) { var builder = ImmutableArray <Usage> .Empty.ToBuilder(); foreach (var r in references) { if (r == null) { continue; } var start = r.Offset; var end = r.Offset + r.Length; if (end > editor.Length) { continue; } var usage = new Usage(TextSegment.FromBounds(start, end), r.ReferenceUsageType); builder.Add(usage); var marker = TextMarkerFactory.CreateUsageMarker(editor, usage); markers.Add(marker); lineNumbers.Add(editor.OffsetToLineNumber(start)); editor.AddMarker(marker); } usages = builder.ToImmutable(); } } OnUsagesUpdated(EventArgs.Empty); }
//this runs as a glib idle handler so it can add/remove text editor markers //in order to to block the GUI thread, we batch them in UPDATE_COUNT bool IdleHandler() { if (cancellationToken.IsCancellationRequested) { return(false); } var editor = ext.Editor; if (editor == null) { return(false); } if (id == null) { foreach (var markerQueue in ext.markers) { while (markerQueue.Value.Count != 0) { editor.RemoveMarker(markerQueue.Value.Dequeue()); } } ext.markers.Clear(); return(false); } //clear the old results out at the same rate we add in the new ones for (int i = 0; oldMarkers > 0 && i < UPDATE_COUNT; i++) { if (cancellationToken.IsCancellationRequested) { return(false); } editor.RemoveMarker(ext.markers [id].Dequeue()); oldMarkers--; } //add in the new markers for (int i = 0; i < UPDATE_COUNT; i++) { if (!enumerator.MoveNext()) { ext.tasks [id] = builder.ToImmutable(); ext.OnTasksUpdated(EventArgs.Empty); return(false); } if (cancellationToken.IsCancellationRequested) { return(false); } var currentResult = (Result)enumerator.Current; if (currentResult.InspectionMark != IssueMarker.None) { int start = currentResult.Region.Start; int end = currentResult.Region.End; if (start >= end) { continue; } var marker = TextMarkerFactory.CreateGenericTextSegmentMarker(editor, GetSegmentMarkerEffect(currentResult.InspectionMark), TextSegment.FromBounds(start, end)); marker.Tag = currentResult; marker.IsVisible = currentResult.Underline; if (currentResult.InspectionMark != IssueMarker.GrayOut) { marker.Color = GetColor(editor, currentResult); marker.IsVisible &= currentResult.Level != DiagnosticSeverity.Hidden; } editor.AddMarker(marker); ext.markers [id].Enqueue(marker); } builder.Add(new QuickTask(currentResult.Message, currentResult.Region.Start, currentResult.Level)); } return(true); }
void CreateSmartTag(CodeActionContainer fixes, int offset) { if (!AnalysisOptions.EnableFancyFeatures || fixes.IsEmpty) { RemoveWidget(); return; } var editor = Editor; if (editor == null) { RemoveWidget(); return; } if (DocumentContext.ParsedDocument == null || DocumentContext.ParsedDocument.IsInvalid) { RemoveWidget(); return; } // var container = editor.Parent; // if (container == null) { // RemoveWidget (); // return; // } bool first = true; var smartTagLocBegin = offset; foreach (var fix in fixes.CodeFixActions.Concat(fixes.CodeRefactoringActions)) { var textSpan = fix.ValidSegment; if (textSpan.IsEmpty) { continue; } if (first || offset < textSpan.Start) { smartTagLocBegin = textSpan.Start; } first = false; } // if (smartTagLocBegin.Line != loc.Line) // smartTagLocBegin = new DocumentLocation (loc.Line, 1); // got no fix location -> try to search word start // if (first) { // int offset = document.Editor.LocationToOffset (smartTagLocBegin); // while (offset > 0) { // char ch = document.Editor.GetCharAt (offset - 1); // if (!char.IsLetterOrDigit (ch) && ch != '_') // break; // offset--; // } // smartTagLocBegin = document.Editor.OffsetToLocation (offset); // } if (currentSmartTag != null && currentSmartTagBegin == smartTagLocBegin) { return; } RemoveWidget(); currentSmartTagBegin = smartTagLocBegin; var realLoc = Editor.OffsetToLocation(smartTagLocBegin); currentSmartTag = TextMarkerFactory.CreateSmartTagMarker(Editor, smartTagLocBegin, realLoc); currentSmartTag.CancelPopup += CurrentSmartTag_CancelPopup; currentSmartTag.ShowPopup += CurrentSmartTag_ShowPopup; currentSmartTag.Tag = fixes; currentSmartTag.IsVisible = fixes.CodeFixActions.Count > 0; editor.AddMarker(currentSmartTag); }
//this runs as a glib idle handler so it can add/remove text editor markers //in order to to block the GUI thread, we batch them in UPDATE_COUNT bool IdleHandler() { if (cancellationToken.IsCancellationRequested) { return(false); } var editor = ext.Editor; if (editor == null) { return(false); } //clear the old results out at the same rate we add in the new ones for (int i = 0; oldMarkers > 0 && i < UPDATE_COUNT; i++) { if (cancellationToken.IsCancellationRequested) { return(false); } editor.RemoveMarker(ext.markers.Dequeue()); oldMarkers--; } //add in the new markers for (int i = 0; i < UPDATE_COUNT; i++) { if (!enumerator.MoveNext()) { ext.tasks = builder.ToImmutable(); ext.OnTasksUpdated(EventArgs.Empty); return(false); } if (cancellationToken.IsCancellationRequested) { return(false); } var currentResult = (Result)enumerator.Current; if (currentResult.InspectionMark != IssueMarker.None) { int start = currentResult.Region.Start; int end = currentResult.Region.End; if (start >= end) { continue; } if (currentResult.InspectionMark == IssueMarker.GrayOut) { var marker = TextMarkerFactory.CreateGenericTextSegmentMarker(editor, TextSegmentMarkerEffect.GrayOut, TextSegment.FromBounds(start, end)); marker.IsVisible = currentResult.Underline; marker.Tag = currentResult; editor.AddMarker(marker); ext.markers.Enqueue(marker); // editor.Parent.TextViewMargin.RemoveCachedLine (editor.GetLineByOffset (start)); // editor.Parent.QueueDraw (); } else { var effect = currentResult.InspectionMark == IssueMarker.DottedLine ? TextSegmentMarkerEffect.DottedLine : TextSegmentMarkerEffect.WavedLine; var marker = TextMarkerFactory.CreateGenericTextSegmentMarker(editor, effect, TextSegment.FromBounds(start, end)); marker.Color = GetColor(editor, currentResult); marker.IsVisible = currentResult.Underline; marker.Tag = currentResult; editor.AddMarker(marker); ext.markers.Enqueue(marker); } } builder.Add(new QuickTask(currentResult.Message, currentResult.Region.Start, currentResult.Level)); } return(true); }
//this runs as a glib idle handler so it can add/remove text editor markers //in order to to block the GUI thread, we batch them in UPDATE_COUNT bool IdleHandler() { var editor = ext.Editor; if (editor == null) { return(false); } if (id == null) { foreach (var markerQueue in ext.markers) { foreach (var marker in markerQueue.Value) { editor.RemoveMarker(marker); } PutBackCachedList(markerQueue.Value); } ext.markers.Clear(); lock (ext.tasks) ext.tasks.Clear(); ext.OnTasksUpdated(EventArgs.Empty); return(false); } if (cancellationToken.IsCancellationRequested) { FinishUpdateRun(); return(false); } //clear the old results out at the same rate we add in the new ones for (int i = 0; oldMarkerIndex < oldMarkers.Count && i < UPDATE_COUNT; i++) { var oldMarker = oldMarkers [oldMarkerIndex++]; var oldResult = (Result)oldMarker.Tag; if (curResult < results.Count) { Result currentResult = results [curResult]; if (currentResult.Equals(oldResult, oldMarker.Offset)) { oldMarker.Tag = currentResult; newMarkers.Add(oldMarker); if (oldResult.QuickTask != null) { currentResult.QuickTask = oldResult.QuickTask; builder.Add(currentResult.QuickTask); } curResult++; continue; } } editor.RemoveMarker(oldMarker); } //add in the new markers for (int i = 0; i < UPDATE_COUNT; i++) { if (curResult >= results.Count) { FinishUpdateRun(); return(false); } var currentResult = results [curResult++]; if (currentResult.InspectionMark != IssueMarker.None) { int start = currentResult.Region.Start; int end = currentResult.Region.End; if (start > end) { continue; } // In case a diagnostic has a 0 length span, force it to 1. if (start == end) { end = end + 1; } var marker = TextMarkerFactory.CreateGenericTextSegmentMarker(editor, GetSegmentMarkerEffect(currentResult.InspectionMark), TextSegment.FromBounds(start, end)); marker.Tag = currentResult; marker.IsVisible = currentResult.Underline; if (currentResult.InspectionMark != IssueMarker.GrayOut) { marker.Color = GetColor(editor, currentResult); marker.IsVisible &= currentResult.Level != DiagnosticSeverity.Hidden; } editor.AddMarker(marker); newMarkers.Add(marker); } builder.Add(currentResult.QuickTask = new QuickTask(currentResult.Message, currentResult.Region.Start, currentResult.Level)); } return(true); }
//this runs as a glib idle handler so it can add/remove text editor markers //in order to to block the GUI thread, we batch them in UPDATE_COUNT bool IdleHandler() { try { var editor = ext.Editor; if (editor == null) { return(false); } if (id == null) { ext.RemoveMarkersAndTasks(); return(false); } //clear the old results out at the same rate we add in the new ones if (oldMarkers != null) { for (int i = 0; oldMarkerIndex < oldMarkers.Count && i < UPDATE_COUNT; i++) { var oldMarker = oldMarkers [oldMarkerIndex++]; var oldResult = (Result)oldMarker.Tag; if (oldResult != null && curResult < results.Count) { Result currentResult = results [curResult]; if (currentResult.Equals(oldResult, oldMarker.Offset)) { oldMarker.Tag = currentResult; newMarkers.Add(oldMarker); if (oldResult.QuickTask != null) { currentResult.QuickTask = oldResult.QuickTask; builder.Add(currentResult.QuickTask); } curResult++; continue; } } editor.RemoveMarker(oldMarker); } } //add in the new markers for (int i = 0; i < UPDATE_COUNT; i++) { if (curResult >= results.Count) { FinishUpdateRun(); return(false); } var currentResult = results [curResult++]; if (currentResult.InspectionMark != IssueMarker.None) { int start = currentResult.Region.Start; int end = currentResult.Region.End; if (start > end) { continue; } // In case a diagnostic has a 0 length span, force it to 1. if (start == end) { end = end + 1; } var marker = TextMarkerFactory.CreateGenericTextSegmentMarker(editor, GetSegmentMarkerEffect(currentResult.InspectionMark), TextSegment.FromBounds(start, end)); marker.Tag = currentResult; marker.IsVisible = currentResult.Underline; if (currentResult.InspectionMark != IssueMarker.GrayOut) { marker.Color = GetColor(editor, currentResult); marker.IsVisible &= currentResult.Level != DiagnosticSeverity.Hidden; } editor.AddMarker(marker); newMarkers.Add(marker); } builder.Add(currentResult.QuickTask = new QuickTask(currentResult.Message, currentResult.Region.Start, currentResult.Level)); } return(true); } catch (Exception ex) { LoggingService.LogInternalError("Error while ResutsUpdater.IdleHandler", ex); return(false); } }