예제 #1
0
        public async Task CanDoTagging(string testFile)
        {
            // Arrange.
            var sourceCode         = File.ReadAllText(testFile);
            var textBuffer         = TextBufferUtility.CreateTextBuffer(Container, sourceCode);
            var backgroundParser   = new BackgroundParser(textBuffer);
            var snapshot           = textBuffer.CurrentSnapshot;
            var syntaxTree         = snapshot.GetSyntaxTree(CancellationToken.None);
            var snapshotSyntaxTree = new SnapshotSyntaxTree(snapshot, syntaxTree);
            var tagger             = CreateTagger(backgroundParser, snapshot);

            // Act.
            await tagger.InvalidateTags(snapshotSyntaxTree, CancellationToken.None);

            var tagSpans = tagger.GetTags(new NormalizedSnapshotSpanCollection(new[]
            {
                new SnapshotSpan(snapshot, 0, snapshot.Length)
            })).ToList();

            // Assert.
            if (MustCreateTagSpans)
            {
                Assert.That(tagSpans.Any());
            }

            backgroundParser.Dispose();
        }
예제 #2
0
        public void TestUnCommentIndented()
        {
            var view = TextViewUtility.CreateTextView(Container,
                                                      TextBufferUtility.CreateTextBuffer(Container, @"void f(){
    //int i;
    //half h;
    float f;
}"));

            view.Selection.Select(
                new SnapshotSpan(
                    view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start,
                    view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(2).End
                    ),
                false
                );
            view.Selection.IsActive = true;

            view.CommentOrUncommentBlock(false);

            Assert.Equal(@"void f(){
    int i;
    half h;
    float f;
}",
                         view.TextBuffer.CurrentSnapshot.GetText());
        }
예제 #3
0
        public void TestCommentBlankLine()
        {
            var view = TextViewUtility.CreateTextView(Container,
                                                      TextBufferUtility.CreateTextBuffer(Container, @"int i;

float f;"));

            view.Caret.MoveTo(view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start);

            view.CommentOrUncommentBlock(true);

            Assert.Equal(@"int i;

float f;",
                         view.TextBuffer.CurrentSnapshot.GetText());
        }
예제 #4
0
        public void TestComment()
        {
            var view = TextViewUtility.CreateTextView(Container,
                                                      TextBufferUtility.CreateTextBuffer(Container, @"int i;
float f;"));

            view.Selection.Select(
                new SnapshotSpan(view.TextBuffer.CurrentSnapshot, new Span(0, view.TextBuffer.CurrentSnapshot.Length)),
                false
                );
            view.Selection.IsActive = true;

            view.CommentOrUncommentBlock(true);

            Assert.Equal(@"//int i;
//float f;",
                         view.TextBuffer.CurrentSnapshot.GetText());
        }
예제 #5
0
        public void TestCommentAfterCodeIsNotUncommented()
        {
            var view = TextViewUtility.CreateTextView(Container,
                                                      TextBufferUtility.CreateTextBuffer(Container, @"int i;//comment that should stay a comment;
//half h;//another comment that should stay a comment;
float f;"));

            view.Selection.Select(
                new SnapshotSpan(view.TextBuffer.CurrentSnapshot, new Span(0, view.TextBuffer.CurrentSnapshot.GetText().IndexOf("float f;"))),
                false
                );
            view.Selection.IsActive = true;

            view.CommentOrUncommentBlock(false);

            Assert.Equal(@"int i;//comment that should stay a comment;
half h;//another comment that should stay a comment;
float f;",
                         view.TextBuffer.CurrentSnapshot.GetText());
        }
        internal async Task <List <ITagSpan <TTag> > > GetTagSpans <TTagger, TTag>(string sourceCode, CreateTagger <TTagger, TTag> createTagger)
            where TTagger : AsyncTagger <TTag>
            where TTag : ITag
        {
            var textBuffer       = TextBufferUtility.CreateTextBuffer(Container, sourceCode);
            var backgroundParser = new BackgroundParser(textBuffer);
            var snapshot         = textBuffer.CurrentSnapshot;
            var tagger           = createTagger(backgroundParser, textBuffer);

            await tagger.InvalidateTags(snapshot, CancellationToken.None);

            var tags = tagger.GetTags(new NormalizedSnapshotSpanCollection(new[]
            {
                new SnapshotSpan(snapshot, 0, snapshot.Length)
            })).ToList();

            backgroundParser.Dispose();

            return(tags);
        }