private void UpdateAtCaretPosition(CaretPosition caretPos) { currentCharSnapPoint = caretPos.Point.GetPoint(this.textBuffer, caretPos.Affinity); if (currentCharSnapPoint.HasValue) { if (TagsChanged != null) { ITextSnapshot currentSnapshot = this.textBuffer.CurrentSnapshot; TagsChanged.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(currentSnapshot, 0, currentSnapshot.Length))); } } }
private void SynchronousUpdate(SnapshotPoint request, NormalizedSnapshotSpanCollection wordSpans, SnapshotSpan?token) { lock (_updateLock) { if (request == _requestedPoint) { _wordSpans = wordSpans; _currentToken = token; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length))); } } }
protected override void OnParseResultChanged(object sender, SnapshotSpanEventArgs e) { var syntaxTreeAndSnapshot = ParserService.SyntaxTreeAndSnapshot; if (syntaxTreeAndSnapshot == null) { return; } UpdateOutliningRegionTags(syntaxTreeAndSnapshot); TagsChanged?.Invoke(this, e); }
public void UpdateErrors(IEnumerable <ShaderLogLine> errorLog) { errors = errorLog; ErrorList.GetInstance().Clear(); foreach (var error in errors) { var lineNumber = error.LineNumber.HasValue ? error.LineNumber.Value - 1 : 0; ErrorList.GetInstance().Write(error.Message, lineNumber, filePath, error.Type); } var span = new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span)); }
private void Storage_OnStoreChange(object sender, StoreChangeEventArgs e) { if (e.ChangedFileType.IsSet(ChangedFileTypeFlag.CSharp)) { if (TagsChanged != null) { var span = new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length); _validator.OnChange(span); _validator.AddToErrorList(); TagsChanged.Invoke(sender, new SnapshotSpanEventArgs(span)); } } }
void UpdateOptions() { bool newValue = textView.Options.GetOptionValue(DefaultTextViewOptions.DisplayUrlsAsHyperlinksId); if (newValue == enableLinks) { return; } enableLinks = newValue; var snapshot = textView.TextSnapshot; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length))); }
private void StartParsing() { ThreadHelper.Generic.BeginInvoke(DispatcherPriority.ApplicationIdle, () => { if (TagsChanged == null || _document.IsParsing) { return; } Regions.Clear(); ReParse(); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(_snapshot, 0, _snapshot.Length))); }); }
public HighlighterTagger(ITextView textView, ITextBuffer buffer, CurrentWordPosition currentWordPosition) { _textView = textView; _buffer = buffer; currentWordPosition.WordUnderMouseChanged += (start, end) => { _clearing = true; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(new SnapshotPoint(_buffer.CurrentSnapshot, Start), (End - Start)))); _clearing = false; Start = start; End = end; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(new SnapshotPoint(_buffer.CurrentSnapshot, Start), (End - Start)))); }; }
private void UpdateAtCaretPosition(CaretPosition caretPosition) { SnapshotPoint?point = caretPosition.Point.GetPoint(SourceBuffer, caretPosition.Affinity); if (point == null) { return; } NormalizedSnapshotSpanCollection newHighlightedSpans = null; NormalizedSnapshotSpanCollection newDefinitionSpans = null; this.HtmlDocument.HtmlEditorTree.GetPositionElement(point.Value.Position, out ElementNode element, out AttributeNode attribute); if ((attribute?.ValueRangeUnquoted.Contains(point.Value.Position) ?? false) || attribute?.ValueRangeUnquoted.End == point.Value.Position) { if ( FrameElementsWithName.Any(n => element?.Name?.Equals(n, StringComparison.InvariantCultureIgnoreCase) ?? false) && (attribute.Name?.Equals("name", StringComparison.InvariantCultureIgnoreCase) ?? false)) { // find definitions string name = attribute.Value; newDefinitionSpans = new NormalizedSnapshotSpanCollection(FindDefinitions(name, point.Value.Snapshot)); // find references newHighlightedSpans = new NormalizedSnapshotSpanCollection(FindReferences(name, point.Value.Snapshot)); } else if ( ElementsWithTarget.Any(n => element?.Name?.Equals(n, StringComparison.InvariantCultureIgnoreCase) ?? false) && (attribute.Name?.Equals("target", StringComparison.InvariantCultureIgnoreCase) ?? false) ) { if (!PredefinedFrameNames.Contains(attribute.Value)) { // find definitions string name = attribute.Value; newDefinitionSpans = new NormalizedSnapshotSpanCollection(FindDefinitions(name, point.Value.Snapshot)); // find references newHighlightedSpans = new NormalizedSnapshotSpanCollection(FindReferences(name, point.Value.Snapshot)); } } } _highlightedSpans = newHighlightedSpans; _definitionSpans = newDefinitionSpans; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(SourceBuffer.CurrentSnapshot, 0, SourceBuffer.CurrentSnapshot.Length))); }
private void UpdateAtCaretPosition(CaretPosition caretPosition) { var point = caretPosition.Point.GetPoint(this.theBuffer, caretPosition.Affinity); if (!point.HasValue) { return; } // get the tag beneath our position: this.currentSpan = GetTagAtPoint(point.Value); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(this.theBuffer.CurrentSnapshot.GetSpan())); }
async Task ScanBufferAsync(ITextSnapshot snapshot) { //Stop and blow away the old scan (even if it didn't finish, the results are not interesting anymore). SyncHelper.CancelAndDispose(ref _Cancellation, true); var cancellationToken = _Cancellation.GetToken(); //The underlying buffer could be very large, meaning that doing the scan for all matches on the UI thread //is a bad idea. Do the scan on the background thread and use a callback to raise the changed event when //the entire scan has completed. _root = await ParseAsync(snapshot, cancellationToken); //This delegate is executed on a background thread. await Task.Run(() => TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length))), cancellationToken); }
private void BufferChanged(object caller, TextContentChangedEventArgs args) { // if current change does not correspond to latest version of buffer, ignore until newer if (args.After != _buffer.CurrentSnapshot) { return; } _snapshot = _buffer.CurrentSnapshot; PerformReTag(); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(_snapshot.GetLineFromLineNumber(0).Start, _snapshot.GetLineFromLineNumber(_snapshot.LineCount - 1).End).TranslateTo(_snapshot, SpanTrackingMode.EdgeExclusive))); }
private void OnDocumentationAdded(DocumentationAddedEvent e) { string filepath = e.Filepath; if (filepath == CodyDocsFilename) { var span = e.DocumentationFragment.GetSpan(); var trackingSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive); _trackingSpans.Add(trackingSpan, e.DocumentationFragment.Documentation); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs( new SnapshotSpan(_buffer.CurrentSnapshot, span))); MarkDocumentAsUnsaved(); } }
void SynchronousUpdate(SnapshotPoint currentRequest, List <NormalizedSnapshotSpanCollection> newSpans) { lock (updateLock) { if (currentRequest != RequestedPoint) { return; } WordSpans = newSpans; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(SourceBuffer.CurrentSnapshot, 0, SourceBuffer.CurrentSnapshot.Length))); } }
void ScanBuffer(ITextSnapshot snapshot) { //Stop and blow away the old scan (even if it didn't finish, the results are not interesting anymore). Interlocked.Exchange(ref _scanner, null)?.Cancel(); //The underlying buffer could be very large, meaning that doing the scan for all matches on the UI thread //is a bad idea. Do the scan on the background thread and use a callback to raise the changed event when //the entire scan has completed. _scanner = new BackgroundScan <CodeBlock>(snapshot, ParseAsync, (CodeBlock newRoot) => { //This delegate is executed on a background thread. _root = newRoot; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length))); }); }
public ErrorTagger(IWpfTextView view) { _view = view; _document = EditorConfigDocument.FromTextBuffer(view.TextBuffer); _validator = EditorConfigValidator.FromDocument(_document); _validator.Validated += DocumentValidated; ThreadHelper.Generic.BeginInvoke(DispatcherPriority.ApplicationIdle, () => { _hasLoaded = true; var span = new SnapshotSpan(view.TextBuffer.CurrentSnapshot, 0, view.TextBuffer.CurrentSnapshot.Length); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span)); }); }
private void MarkdownParsed(object sender, ParsingEventArgs e) { if (string.IsNullOrEmpty(e.File) || e.Snapshot != _buffer.CurrentSnapshot) { return; } // Clear cache if document is updated _errorsCached = null; _errors = e.Document.Validate(e.File); SnapshotSpan span = new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span)); }
private void BufferChanged(object sender, TextContentChangedEventArgs e) { foreach (var change in e.Changes) { // If there is a change in the number of brackets, we need to re-tag everything if (change.OldText.Count(c => c == '}' || c == '{') != change.NewText.Count(c => c == '}' || c == '{')) { TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(buffer.CurrentSnapshot, new Span(0, buffer.CurrentSnapshot.Length)))); } else { TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(e.After, change.NewSpan))); } } }
protected void RefreshAllTags(ITextSnapshot snapshot) { Debug.Assert(!(snapshot is null)); if (snapshot is null) { return; } lock (lockObj) { lastSnapshotState?.Cancel(); lastSnapshotState?.FreeRef(); lastSnapshotState = null; cachedTags.Clear(); } TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length))); }
/// <summary> /// Perform a synchronous update, in case multiple background threads are running /// </summary> private void SynchronousUpdate(SnapshotPoint currentRequest, NormalizedSnapshotSpanCollection newSpans, string newCurrentWord, SnapshotSpan?newCurrentWordSpan) { lock (this._updateLock) { if (currentRequest != this.RequestedPoint) { return; } this._wordSpans = newSpans; this.CurrentWord = newCurrentWord; this._currentWordSpan = newCurrentWordSpan; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(this._sourceBuffer.CurrentSnapshot, 0, this._sourceBuffer.CurrentSnapshot.Length))); } }
private void UpdateTags(NormalizedSnapshotSpanCollection newSpans) { m_Tag = FocusDimmer.Mode == Modes.DimGray ? BuildTag(m_Registry, "Alpzy/DimGray") : BuildTag(m_Registry, "Alpzy/Transparent"); m_CurrentSpans = newSpans; TagsChanged?.Invoke( this, new SnapshotSpanEventArgs( new SnapshotSpan(m_SourceBuffer.CurrentSnapshot, 0, m_SourceBuffer.CurrentSnapshot.Length) ) ); }
private void UpdateAtCaretPosition() { // Check for disposal, this can be disposed while waiting for idle if (!IsDisposed && BraceMatcher != null && !_textView.Caret.InVirtualSpace) { var caretPosition = _textView.Caret.Position; _currentChar = caretPosition.Point.GetPoint(_textBuffer, caretPosition.Affinity); // We need to clear current highlight if caret went to another buffer _highlighted = false; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs( new SnapshotSpan(_textBuffer.CurrentSnapshot, 0, _textBuffer.CurrentSnapshot.Length))); } }
public void UpdateTags() { if (Tags != null) { PreviousTags = Tags.ToArray(); } Tags = SortTags(DataSourceAdapter.GetTags()).ToArray(); if (PreviousTags == null) { PreviousTags = Tags; } TagsChanged?.Invoke(this, EventArgs.Empty); }
private void TokenizerUpdated(ITokenizerResult result, CancellationToken ct) { var tokens = result.UpdatedTokens; if (!tokens.Any()) { return; } _currentResult = result; var start = tokens.First().GetStart(result.Snapshot); var end = tokens.Last().GetEnd(result.Snapshot); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(result.Snapshot, new Span(start, end - start)))); }
private void SynchronousUpdate(SnapshotPoint currentRequest, NormalizedSnapshotSpanCollection newSpans, SnapshotSpan?newCurrentWord, SnapshotSpan?navigationTokenSpan) { lock (updateLock) { if (currentRequest != requestedPoint) { return; } wordSpans = newSpans; currentWord = newCurrentWord; navigationWordSpans = navigationTokenSpan; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length))); } }
private async void OnNewParseTree(AnalysisEntry entry) { var snapshot = _buffer.CurrentSnapshot; var tags = await entry.Analyzer.GetOutliningTagsAsync(snapshot); if (tags != null) { _tags = tags.Concat(ProcessRegionTags(snapshot)).ToArray(); TagsChanged?.Invoke( this, new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length)) ); } }
internal GLSLTagger(ITextBuffer buffer) { _buffer = buffer; _buffer.Changed += (s, args) => { if (args.After == buffer.CurrentSnapshot) { // We must feed the GLSLTagSpanCollection ALL tagSpans, old and new, and it will determine what the appropriate differences are ParseBufferChanges(args.Changes, _buffer.CurrentSnapshot); } }; _tagSpans.TagsChanged += (s, args) => TagsChanged?.Invoke(this, args); ParseBuffer(_buffer.CurrentSnapshot); }
public void Refresh(long version, List <ALanguageErrorInfo> info_list) { // 获取版本号 if (!m_view.Properties.TryGetProperty("version", out long id)) { return; } if (version != id) { return; } if (m_view.TextSnapshot.Length == 0) { return; } m_error_map.Clear(); foreach (var info in info_list) { if (!m_error_map.TryGetValue(info.line, out List <ITagSpan <IErrorTag> > list)) { list = new List <ITagSpan <IErrorTag> >(); m_error_map.Add(info.line, list); } int e_start = info.start; if (e_start >= m_view.TextSnapshot.Length) { e_start = m_view.TextSnapshot.Length - 1; } int length = info.end - e_start; if (length <= 0) { length = 1; } else if (length + e_start >= m_view.TextSnapshot.Length) { length = m_view.TextSnapshot.Length - e_start; } var span = new SnapshotSpan(m_view.TextSnapshot, e_start, length); list.Add(new TagSpan <IErrorTag>(span, new ErrorTag(PredefinedErrorTypeNames.SyntaxError, info.error))); } { var span = new SnapshotSpan(m_view.TextSnapshot, 0, m_view.TextSnapshot.Length); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span)); } }
private void UpdateAtCaretPosition(CaretPosition caretPosition) { SnapshotPoint?point = caretPosition.Point.GetPoint(SourceBuffer, caretPosition.Affinity); if (point == null) { return; } NormalizedSnapshotSpanCollection newHighlightedSpans = null; NormalizedSnapshotSpanCollection newDefinitionSpans = null; this.HtmlDocument.HtmlEditorTree.GetPositionElement(point.Value.Position, out _, out AttributeNode attribute); if ((attribute?.ValueRangeUnquoted.Contains(point.Value.Position) ?? false) || (attribute?.ValueRangeUnquoted.End == point.Value.Position)) { if (new string[] { "id", "for", "aria-labelledby", "aria-describedby", "aria-controls" }.Any(n => attribute.Name?.Equals(n, StringComparison.InvariantCultureIgnoreCase) ?? false )) { // find definitions string id = attribute.Value; newDefinitionSpans = new NormalizedSnapshotSpanCollection(FindDefinitions(id, point.Value.Snapshot)); // find references newHighlightedSpans = new NormalizedSnapshotSpanCollection(FindReferences(id, point.Value.Snapshot)); } else if (attribute.Name?.Equals("href", StringComparison.InvariantCultureIgnoreCase) ?? false) { if (attribute.Value?.StartsWith("#") ?? false) { // find definitions string id = attribute.Value.Substring(1); newDefinitionSpans = new NormalizedSnapshotSpanCollection(FindDefinitions(id, point.Value.Snapshot)); // find references newHighlightedSpans = new NormalizedSnapshotSpanCollection(FindReferences(id, point.Value.Snapshot)); } } } _highlightedSpans = newHighlightedSpans; _definitionSpans = newDefinitionSpans; TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(SourceBuffer.CurrentSnapshot, 0, SourceBuffer.CurrentSnapshot.Length))); }
internal void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e) { try { if (!Enabled) { return; } _errorTags.Clear(); TagsChanged?.Invoke( this, new SnapshotSpanEventArgs( new SnapshotSpan( _view.TextSnapshot, new Span(0, _view.TextSnapshot.Length)))); foreach (ITextViewLine line in e.NewOrReformattedLines) { int lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber; _editedLines[lineNumber] = line; } ResetTimer(); // Sometimes, on loading a file in an editor view, the line transform gets triggered before the image adornments // have been added, so the lines don't resize to the image height. So here's a workaround: // Changing the zoom level triggers the required update. // Need to do it twice - once to trigger the event, and again to change it back to the user's expected level. if (!_initialised1) { _view.ZoomLevel++; _initialised1 = true; } if (!_initialised2) { _view.ZoomLevel--; _initialised2 = true; } } catch (Exception ex) { ExceptionHandler.Notify(ex, true); } }