public void SimpleSingle() { Create("cat dog", "fish"); var tags = _tagger.GetTags(_textBuffer.GetExtent()).ToList(); var expected = new [] { _textBuffer.GetSpan(4, 3) }; if (tags.Count == 0) { // Fine for the result to be delayed but we must see a TagsChanged event occur // to signal the new tags. The SnapshotSpan values which occur in that list // must include the expected span Assert.False(IsComplete()); WaitUntilCompleted(); Assert.True(_tagsChangedList.Any(x => x.Span.Contains(expected[0]))); tags = _tagger.GetTags(_textBuffer.GetExtent()).ToList(); } else { // If the tags returned promptly they shouldn't have raised any tags changed // events Assert.Equal(0, _tagsChangedList.Count); } Assert.Equal(expected, tags.Select(x => x.Span)); }
public async Task AssertNoTag() { await WaitForAsyncOperationsAsync(); var tags = _tagger.GetTags(_view.TextBuffer.CurrentSnapshot.GetSnapshotSpanCollection()); Assert.Equal(0, tags.Count()); }
public void AssertNoTag() { WaitForAsyncOperations(); var tags = _tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan(_view.TextBuffer.CurrentSnapshot, new Span(0, _view.TextBuffer.CurrentSnapshot.Length)))); Assert.Equal(0, tags.Count()); }
/// <summary> /// Enumerates all of the classifications in reverse starting at start to the beginning of the file. /// </summary> private static IEnumerator <ITagSpan <ClassificationTag> > EnumerateClassificationsInReverse(ITagger <ClassificationTag> classifier, SnapshotPoint start) { var curLine = start.GetContainingLine(); var spanEnd = start; for (; ;) { var classifications = classifier.GetTags( new NormalizedSnapshotSpanCollection(new SnapshotSpan(curLine.Start, spanEnd)) ); foreach (var classification in classifications.Reverse()) { yield return(classification); } yield return(null); if (curLine.LineNumber == 0) { break; } curLine = start.Snapshot.GetLineFromLineNumber(curLine.LineNumber - 1); spanEnd = curLine.End; } }
IList <ClassificationSpan> IClassifier.GetClassificationSpans(SnapshotSpan span) { return(_tagger .GetTags(new NormalizedSnapshotSpanCollection(span)) .Select(x => new ClassificationSpan(x.Span, x.Tag.ClassificationType)) .ToList()); }
public void ShouldClassifyScenarioWithExamples() { TestInitialise("Features/gherkin.feature"); var snapShotSpan = new SnapshotSpan(new MockTextSnapshot(featureFileContent), new Span(0, 15)); var spanCollection = new NormalizedSnapshotSpanCollection(new[] { snapShotSpan }); var tags = playTagger.GetTags(spanCollection); var tag = tags.First(span => span.Span.GetText().StartsWith(" Scenario: SC1")).Tag; Assert.AreEqual("Scenario: SC1" + Environment.NewLine + " Given numbers [left] and [right]" + Environment.NewLine + " When I add the numbers" + Environment.NewLine + " Then the sum is [sum]" + Environment.NewLine + "Examples:" + Environment.NewLine + " | left | right | sum |" + Environment.NewLine + " | 1 | 2 | 3 |" + Environment.NewLine + " | 3 | 4 | 7 |", tag.GetText()); }
public IEnumerable <IMappingTagSpan <T> > GetTags(SnapshotSpan span) { foreach (var tagSpan in _tagger.GetTags(new NormalizedSnapshotSpanCollection(span.Snapshot, new Span[] { span }))) { var mappingSpan = VsxStubObjects.CreateObject <IMappingSpan>("Microsoft.VisualStudio.Text.Utilities.MappingSpanSnapshot, Microsoft.VisualStudio.Platform.VSEditor", span.Snapshot, tagSpan.Span, SpanTrackingMode.EdgeExclusive, _bufferGraph); yield return(new MappingTagSpan <T>(mappingSpan, tagSpan.Tag)); } }
private void Classify(SnapshotSpan span, IList <ClassificationSpan> list, string text, Regex regex) { foreach (Match match in regex.Matches(text)) { var name = match.Groups["keyword"]; var matchSpan = new SnapshotSpan(span.Snapshot, span.Start + name.Index, name.Length); var tags = _tagger.GetTags(new NormalizedSnapshotSpanCollection(matchSpan)).Select(s => s.Tag.ClassificationType); if (tags.Contains(_identifier)) { list.Add(new ClassificationSpan(matchSpan, _keyword)); } } }
public GlslCompletionSource(ITextBuffer buffer, IEnumerable <Completion> staticCompletions, ImageSource identifier, ITagger <GlslTokenTag> tagger) { currentBuffer = buffer; this.staticCompletions = staticCompletions; imgIdentifier = identifier; queryIdentifiers = (snapshotSpan) => { var tokens = tagger.GetTags(new NormalizedSnapshotSpanCollection(snapshotSpan)); //only those tokens that are identifiers and do not overlap the input position because we do not want to add char that started session to completions var filtered = from token in tokens where token.Tag.Type == GlslTokenTypes.Identifier && !token.Span.Contains(snapshotSpan.End - 1) let text = token.Span.GetText() orderby text select text; return(filtered.Distinct()); }; }
/// <summary> /// Get the ITagSpan values for the given SnapshotSpan /// </summary> public static IEnumerable <ITagSpan <T> > GetTags <T>(this ITagger <T> tagger, SnapshotSpan span) where T : ITag { return(tagger.GetTags(new NormalizedSnapshotSpanCollection(span))); }
/// <summary> /// Enumerates all of the classifications in reverse starting at start to the beginning of the file. /// </summary> private static IEnumerator<ITagSpan<ClassificationTag>> EnumerateClassificationsInReverse(ITagger<ClassificationTag> classifier, SnapshotPoint start) { if (classifier == null) { yield break; } var curLine = start.GetContainingLine(); var spanEnd = start; for (; ; ) { var classifications = classifier.GetTags( new NormalizedSnapshotSpanCollection(new SnapshotSpan(curLine.Start, spanEnd)) ); foreach (var classification in classifications.Reverse()) { yield return classification; } yield return null; if (curLine.LineNumber == 0) { break; } curLine = start.Snapshot.GetLineFromLineNumber(curLine.LineNumber - 1); spanEnd = curLine.End; } }
private IEnumerable <IMappingTagSpan <T> > GetTagsForBuffer(KeyValuePair <ITextBuffer, IList <ITagger <T> > > bufferAndTaggers, NormalizedSnapshotSpanCollection snapshotSpans, ITextSnapshot root, CancellationToken?cancel) { ITextSnapshot snapshot = snapshotSpans[0].Snapshot; for (int t = 0; t < bufferAndTaggers.Value.Count; ++t) { ITagger <T> tagger = bufferAndTaggers.Value[t]; IEnumerator <ITagSpan <T> > tags = null; try { IEnumerable <ITagSpan <T> > tagEnumerable; if (cancel.HasValue) { cancel.Value.ThrowIfCancellationRequested(); var tagger2 = tagger as IAccurateTagger <T>; if (tagger2 != null) { tagEnumerable = tagger2.GetAllTags(snapshotSpans, cancel.Value); } else { tagEnumerable = tagger.GetTags(snapshotSpans); } } else { tagEnumerable = tagger.GetTags(snapshotSpans); } if (tagEnumerable != null) { tags = tagEnumerable.GetEnumerator(); } } catch (OperationCanceledException) { // Rethrow cancellation exceptions since we expect our callers to deal with it. throw; } catch (Exception e) { this.TagAggregatorFactoryService.GuardedOperations.HandleException(tagger, e); } if (tags != null) { try { while (true) { ITagSpan <T> tagSpan = null; try { if (tags.MoveNext()) { tagSpan = tags.Current; } } catch (Exception e) { this.TagAggregatorFactoryService.GuardedOperations.HandleException(tagger, e); } if (tagSpan == null) { break; } var snapshotSpan = tagSpan.Span; if (snapshotSpans.IntersectsWith(snapshotSpan.TranslateTo(snapshot, SpanTrackingMode.EdgeExclusive))) { yield return(new MappingTagSpan <T>( (root == null) ? this.BufferGraph.CreateMappingSpan(snapshotSpan, SpanTrackingMode.EdgeExclusive) : MappingSpanSnapshot.Create(root, snapshotSpan, SpanTrackingMode.EdgeExclusive, this.BufferGraph), tagSpan.Tag)); } else { #if DEBUG Debug.WriteLine("tagger provided an extra (non-intersecting) tag at " + snapshotSpan + " when queried for tags over " + snapshotSpans); #endif } } } finally { try { tags.Dispose(); } catch (Exception e) { this.TagAggregatorFactoryService.GuardedOperations.HandleException(tagger, e); } } } } }
async Task InitializeAsync(ITextBuffer buffer, string code, MetadataReference[] refs, string languageName, ITagger <IClassificationTag> tagger, CompilationOptions compilationOptions, ParseOptions parseOptions) { using (var workspace = new AdhocWorkspace(RoslynMefHostServices.DefaultServices)) { var documents = new List <DocumentInfo>(); var projectId = ProjectId.CreateNewId(); documents.Add(DocumentInfo.Create(DocumentId.CreateNewId(projectId), "main.cs", null, SourceCodeKind.Regular, TextLoader.From(buffer.AsTextContainer(), VersionStamp.Create()))); var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), "compilecodeproj", Guid.NewGuid().ToString(), languageName, compilationOptions: compilationOptions .WithOptimizationLevel(OptimizationLevel.Release) .WithPlatform(Platform.AnyCpu) .WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default), parseOptions: parseOptions, documents: documents, metadataReferences: refs, isSubmission: false, hostObjectType: null); workspace.AddProject(projectInfo); foreach (var doc in documents) { workspace.OpenDocument(doc.Id); } buffer.Replace(new Span(0, buffer.CurrentSnapshot.Length), code); { // Initialize classification code paths var spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)); foreach (var tagSpan in tagger.GetTags(spans)) { } } { // Initialize completion code paths var info = CompletionInfo.Create(buffer.CurrentSnapshot); Debug.Assert(info != null); if (info != null) { var completionTrigger = CompletionTrigger.Default; var completionList = await info.Value.CompletionService.GetCompletionsAsync(info.Value.Document, 0, completionTrigger); } } { // Initialize signature help code paths var info = SignatureHelpInfo.Create(buffer.CurrentSnapshot); Debug.Assert(info != null); if (info != null) { int sigHelpIndex = code.IndexOf("sighelp"); Debug.Assert(sigHelpIndex >= 0); var triggerInfo = new SignatureHelpTriggerInfo(SignatureHelpTriggerReason.InvokeSignatureHelpCommand); var items = await info.Value.SignatureHelpService.GetItemsAsync(info.Value.Document, sigHelpIndex, triggerInfo); } } { // Initialize quick info code paths var info = QuickInfoState.Create(buffer.CurrentSnapshot); Debug.Assert(info != null); if (info != null) { int quickInfoIndex = code.IndexOf("Equals"); Debug.Assert(quickInfoIndex >= 0); var item = await info.Value.QuickInfoService.GetItemAsync(info.Value.Document, quickInfoIndex); } } } }
public IEnumerable <ITagSpan <TTagType> > GetTags(NormalizedSnapshotSpanCollection spans) => wrappedTagger.GetTags(spans);
private IEnumerable <ITagSpan <TextMarkerTag> > GetTags() { var span = _buffer.TextSnapshot.GetExtent(); return(_tagger.GetTags(new NormalizedSnapshotSpanCollection(span))); }