public RoxygenClassifier(ITextBuffer textBuffer, IClassificationTypeRegistryService ctrs) { _textBuffer = textBuffer; _ctrs = ctrs; _rClassifier = RClassifier.FromTextBuffer(textBuffer); _commentType = _ctrs.GetClassificationType(PredefinedClassificationTypeNames.Comment); }
public IClassifier GetClassifier(ITextBuffer textBuffer) { RClassifier classifier = ServiceManager.GetService<RClassifier>(textBuffer); if (classifier == null) { classifier = new RClassifier(textBuffer, ClassificationRegistryService); ServiceManager.AddService<RClassifier>(classifier, textBuffer, Shell); } return classifier; }
public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span) { var rClassificationSpans = RClassifier.GetClassificationSpans(span); return(rClassificationSpans .Where(s => s.ClassificationType == _commentType) .SelectMany(s => ClassifyCommentSpan(s)) .ToList()); }
/// <summary> /// Tells document that massive change to text buffer is about to commence. /// Document will then stop tracking text buffer changes, will suspend /// R parser anc classifier and remove all projections. AST is no longer /// valid after this call. /// </summary> public void BeginMassiveChange() { if (_inMassiveChange == 0) { _editorTree.TreeUpdateTask.Suspend(); RClassifier colorizer = ServiceManager.GetService <RClassifier>(TextBuffer); colorizer?.Suspend(); MassiveChangeBegun?.Invoke(this, EventArgs.Empty); } _inMassiveChange++; }
/// <summary> /// Tells document that massive change to text buffer is about to commence. /// Document will then stop tracking text buffer changes, will suspend /// R parser anc classifier and remove all projections. AST is no longer /// valid after this call. /// </summary> public void BeginMassiveChange() { if (_inMassiveChange == 0) { _editorTree.TreeUpdateTask.Suspend(); RClassifier colorizer = ServiceManager.GetService <RClassifier>(TextBuffer); if (colorizer != null) { colorizer.Suspend(); } if (MassiveChangeBegun != null) { MassiveChangeBegun(this, EventArgs.Empty); } } _inMassiveChange++; }
/// <summary> /// Tells document that massive change to text buffer is complete. Document will perform full parse, /// resume tracking of text buffer changes and classification (colorization). /// </summary> /// <returns>True if changes were made to the text buffer since call to BeginMassiveChange</returns> public bool EndMassiveChange() { bool changed = _editorTree.TreeUpdateTask.TextBufferChangedSinceSuspend; if (_inMassiveChange == 1) { RClassifier colorizer = ServiceManager.GetService <RClassifier>(TextBuffer); if (colorizer != null) { colorizer.Resume(); } if (changed) { TextChangeEventArgs textChange = new TextChangeEventArgs(0, 0, TextBuffer.CurrentSnapshot.Length, 0, new TextProvider(_editorTree.TextSnapshot, partial: true), new TextStream(string.Empty)); List <TextChangeEventArgs> textChanges = new List <TextChangeEventArgs>(); textChanges.Add(textChange); _editorTree.FireOnUpdatesPending(textChanges); _editorTree.FireOnUpdateBegin(); _editorTree.FireOnUpdateCompleted(TreeUpdateType.NewTree); } _editorTree.TreeUpdateTask.Resume(); if (MassiveChangeEnded != null) { MassiveChangeEnded(this, EventArgs.Empty); } } if (_inMassiveChange > 0) { _inMassiveChange--; } return(changed); }