private void FindAndUpdateSpans(TextExtent extent, SnapshotPoint request) { var wordSpans = new List <SnapshotSpan>(); var text = request.Snapshot.GetText(extent.Span); if (!IsComment(extent)) { if (text.Any(c => char.IsLetter(c))) { if (!_currentToken.HasValue || extent.Span != _currentToken) { // Find the new spans var findData = new FindData(extent.Span.GetText(), extent.Span.Snapshot) { FindOptions = FindOptions.WholeWord | FindOptions.MatchCase }; var tagger = new GLSLTaggerProvider().CreateTagger <IGLSLTag>(_buffer) as GLSLTagger; var scope = tagger.GetScope(extent.Span); var spans = _textSearchService.FindAll(findData); foreach (var span in spans) { var spanScope = tagger.GetScope(span); if (spanScope == scope || spanScope.IsDescendentOf(scope) || spanScope.IsAncestorOf(scope)) { lock (_spanLock) { if (!_commentSpans.CloneAndTrackTo(extent.Span.Snapshot, SpanTrackingMode.EdgePositive).OverlapsWith(span) && _tokenSpans.CloneAndTrackTo(extent.Span.Snapshot, SpanTrackingMode.EdgePositive).OverlapsWith(span)) { wordSpans.Add(span); } } } } } } else { var span = GetMatchingBracketSpan(extent, text); if (span.HasValue && (!_currentToken.HasValue || extent.Span != _currentToken)) { wordSpans.Add(span.Value); } } } // If another change hasn't happened, do a real update if (request == _requestedPoint) { SynchronousUpdate(request, new NormalizedSnapshotSpanCollection(wordSpans), extent.Span); } }
public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets) { if (_disposed) { throw new ObjectDisposedException("GLSLCompletionSource"); } ITextSnapshot snapshot = _buffer.CurrentSnapshot; var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot); if (triggerPoint != null) { var line = triggerPoint.GetContainingLine(); var start = triggerPoint; while (start > line.Start && !char.IsWhiteSpace((start - 1).GetChar())) { start -= 1; } var span = new SnapshotSpan(start, triggerPoint); var applicableTo = snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive); // Now that we have the span we want, get all tokens from the GLSLTokenTagger, then build our completion set based on those // We have our trigger span, but we want to get ALL tokens from the GLSLTokenTagger, because we need to search for our token in those /*if (session != null) * { * session.SelectedCompletionSet.SelectBestMatch(); * session.SelectedCompletionSet.Recalculate(); * }*/ var tagger = new GLSLTaggerProvider().CreateTagger <IGLSLTag>(_buffer) as GLSLTagger; var completions = tagger.GetCompletions(span); completionSets.Add(new CompletionSet("All", "All", applicableTo, completions, Enumerable.Empty <Completion>())); } }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { if (_disposed) { throw new ObjectDisposedException(nameof(GLSLQuickInfoSource)); } var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot); if (triggerPoint != null) { var tagger = new GLSLTaggerProvider().CreateTagger <IGLSLTag>(_buffer) as GLSLTagger; var triggerSpan = new SnapshotSpan(triggerPoint, triggerPoint); var quickInfo = await GetQuickInfoAsync(tagger, triggerSpan, cancellationToken); if (quickInfo != null) { return(quickInfo); } } return(null); }