예제 #1
0
        public async Task FormatSpansIndividuallyWithoutCollapsing()
        {
            var code     = @"class C
{
    public void M()
    {
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        [|if(true){}|]
        if(true){}
        [|if(true){}|]
    }
}";
            var expected = @"class C
{
    public void M()
    {
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if (true) { }
        if(true){}
        if (true) { }
    }
}";

            using (var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(code))
            {
                var subjectDocument = workspace.Documents.Single();
                var spans           = subjectDocument.SelectedSpans;

                var document   = workspace.CurrentSolution.Projects.Single().Documents.Single();
                var syntaxRoot = await document.GetSyntaxRootAsync();

                var node = Formatter.Format(syntaxRoot, spans, workspace);
                Assert.Equal(expected, node.ToFullString());
            }
        }
예제 #2
0
 private static async Task <TestWorkspace> CreateWorkspaceFromFileAsync(string file, bool isVisualBasic, ParseOptions parseOptions, CompilationOptions compilationOptions)
 {
     return(isVisualBasic ?
            await VisualBasicWorkspaceFactory.CreateWorkspaceFromFileAsync(file, (VB.VisualBasicParseOptions) parseOptions, (VB.VisualBasicCompilationOptions) compilationOptions) :
            await CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(file, (CS.CSharpParseOptions) parseOptions, (CS.CSharpCompilationOptions) compilationOptions));
 }
예제 #3
0
        public async Task LargeNumberOfSpans()
        {
            using (var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(@"class Program
{
    void M()
    {
        int z = 0;
        z = z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z;
    }
}"))
            {
                Callback tagProducer = (span, cancellationToken) =>
                {
                    return(new List <ITagSpan <TestTag> >()
                    {
                        new TagSpan <TestTag>(span, new TestTag())
                    });
                };
                var asyncListener = new TaggerOperationListener();

                WpfTestCase.RequireWpfFact($"{nameof(AsynchronousTaggerTests)}.{nameof(LargeNumberOfSpans)} creates asynchronous taggers");

                var notificationService = workspace.GetService <IForegroundNotificationService>();

                var eventSource    = CreateEventSource();
                var taggerProvider = new TestTaggerProvider(
                    tagProducer,
                    eventSource,
                    workspace,
                    asyncListener,
                    notificationService);

                var document   = workspace.Documents.First();
                var textBuffer = document.TextBuffer;
                var snapshot   = textBuffer.CurrentSnapshot;
                var tagger     = taggerProvider.CreateTagger <TestTag>(textBuffer);

                using (IDisposable disposable = (IDisposable)tagger)
                {
                    var spans         = Enumerable.Range(0, 101).Select(i => new Span(i * 4, 1));
                    var snapshotSpans = new NormalizedSnapshotSpanCollection(snapshot, spans);

                    eventSource.SendUpdateEvent();

                    await asyncListener.CreateWaitTask();

                    var tags = tagger.GetTags(snapshotSpans);

                    Assert.Equal(1, tags.Count());
                }
            }
        }
예제 #4
0
 internal async Task <Holder> CreateSessionAsync(string code)
 {
     return(CreateSession(
                await CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(code),
                BraceCompletionSessionProvider.Parenthesis.OpenCharacter, BraceCompletionSessionProvider.Parenthesis.CloseCharacter));
 }
예제 #5
0
 protected override Task <TestWorkspace> CreateWorkspaceFromFileAsync(string definition, ParseOptions parseOptions, CompilationOptions compilationOptions)
 {
     return(CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(definition, (CSharpParseOptions)parseOptions, (CSharpCompilationOptions)compilationOptions));
 }
 protected override Task <TestWorkspace> CreateWorkspaceFromFileAsync(string code, ParseOptions options)
 {
     return(CSharpWorkspaceFactory.CreateWorkspaceFromFileAsync(code, (CSharpParseOptions)options));
 }