コード例 #1
0
        private async Task AssertIndentUsingSmartTokenFormatterAsync(
            string code,
            char ch,
            int indentationLine,
            int?expectedIndentation)
        {
            // create tree service
            using (var workspace = await TestWorkspace.CreateCSharpAsync(code))
            {
                var hostdoc = workspace.Documents.First();

                var buffer = hostdoc.GetTextBuffer();

                var snapshot = buffer.CurrentSnapshot;
                var line     = snapshot.GetLineFromLineNumber(indentationLine);

                var document = workspace.CurrentSolution.GetDocument(hostdoc.Id);

                var root = (await document.GetSyntaxRootAsync()) as CompilationUnitSyntax;

                Assert.True(
                    CSharpIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter(
                        Formatter.GetDefaultFormattingRules(workspace, root.Language),
                        root, line, workspace.Options, CancellationToken.None));

                var actualIndentation = await GetSmartTokenFormatterIndentationWorkerAsync(workspace, buffer, indentationLine, ch);

                Assert.Equal(expectedIndentation.Value, actualIndentation);
            }
        }
コード例 #2
0
        private void AssertIndentNotUsingSmartTokenFormatterButUsingIndenter(
            string code,
            int indentationLine,
            int?expectedIndentation)
        {
            // create tree service
            using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromLines(code))
            {
                var hostdoc  = workspace.Documents.First();
                var buffer   = hostdoc.GetTextBuffer();
                var snapshot = buffer.CurrentSnapshot;

                var line = snapshot.GetLineFromLineNumber(indentationLine);

                var document = workspace.CurrentSolution.GetDocument(hostdoc.Id);

                var root = document.GetSyntaxRootAsync().Result as CompilationUnitSyntax;
                Assert.False(
                    CSharpIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter(
                        Formatter.GetDefaultFormattingRules(workspace, root.Language),
                        root, line, workspace.Options, CancellationToken.None));

                TestIndentation(indentationLine, expectedIndentation, workspace);
            }
        }
コード例 #3
0
        private async Task AssertIndentNotUsingSmartTokenFormatterButUsingIndenterAsync(
            string code,
            int indentationLine,
            int?expectedIndentation,
            bool useTabs,
            IndentStyle indentStyle)
        {
            // create tree service
            using var workspace = TestWorkspace.CreateCSharp(code);
            workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options
                                                                            .WithChangedOption(SmartIndent, LanguageNames.CSharp, indentStyle)
                                                                            .WithChangedOption(UseTabs, LanguageNames.CSharp, useTabs)));
            var hostdoc  = workspace.Documents.First();
            var buffer   = hostdoc.GetTextBuffer();
            var snapshot = buffer.CurrentSnapshot;

            var line = snapshot.GetLineFromLineNumber(indentationLine);

            var document = workspace.CurrentSolution.GetDocument(hostdoc.Id);

            var root = (await document.GetSyntaxRootAsync()) as CompilationUnitSyntax;

            var optionService = workspace.Services.GetRequiredService <IOptionService>();

            Assert.False(
                CSharpIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter(
                    Formatter.GetDefaultFormattingRules(workspace, root.Language),
                    root, line.AsTextLine(), optionService, await document.GetOptionsAsync(), out _));

            TestIndentation(workspace, indentationLine, expectedIndentation);
        }
コード例 #4
0
        private async Task AssertIndentNotUsingSmartTokenFormatterButUsingIndenterAsync(
            string code,
            int indentationLine,
            int?expectedIndentation,
            int?expectedBlankLineIndentation = null,
            IndentStyle indentStyle          = IndentStyle.Smart)
        {
            // create tree service
            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                workspace.Options = workspace.Options.WithChangedOption(SmartIndent, LanguageNames.CSharp, indentStyle);
                var hostdoc  = workspace.Documents.First();
                var buffer   = hostdoc.GetTextBuffer();
                var snapshot = buffer.CurrentSnapshot;

                var line = snapshot.GetLineFromLineNumber(indentationLine);

                var document = workspace.CurrentSolution.GetDocument(hostdoc.Id);

                var root = (await document.GetSyntaxRootAsync()) as CompilationUnitSyntax;
                Assert.False(
                    CSharpIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter(
                        Formatter.GetDefaultFormattingRules(workspace, root.Language),
                        root, line.AsTextLine(), await document.GetOptionsAsync(), CancellationToken.None));

                TestIndentation(
                    workspace, indentationLine,
                    expectedIndentation, expectedBlankLineIndentation);
            }
        }