Exemplo n.º 1
0
        private async Task FormatCodeAsync()
        {
            try
            {
                Document activeDocument = await VisualStudioHelper.GetActiveDocumentAsync();

                if (VisualStudioHelper.FileIsExcludedType(activeDocument.FilePath))
                {
                    return;
                }
                SyntaxNode root = await VisualStudioHelper.GetDocumentRootAsync(activeDocument);

                bool isCSharpDocument = root.Language == VisualStudioHelper.CSharpLanguageName;
                if (!isCSharpDocument)
                {
                    return;
                }

                var        longLineFormatter = new LongLineFormatter(CSharpenerConfigSettings.LengthOfLineToBreakOn);
                SyntaxNode formattedRoot     = longLineFormatter.Visit(root);

                Document newDocument = activeDocument.WithSyntaxRoot(formattedRoot);
                bool     success     = await VisualStudioHelper.ApplyDocumentChangesAsync(newDocument);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
0
        public void CodeText_WhenHeaderFormatterRun_OutputsExpectedText(string inputString, string expectedOutput)
        {
            TestHelper.InitializeConfig(TestData.TestConfig);
            var root = TestHelper.CreateCSharpSyntaxRoot(inputString);

            var        llf     = new LongLineFormatter(CSharpenerConfigSettings.LengthOfLineToBreakOn);
            SyntaxNode llfRoot = llf.Visit(root);

            string actualOutput = llfRoot.ToFullString();

            Debug.WriteLine(actualOutput);
            Assert.That(actualOutput, Is.EqualTo(expectedOutput));
        }