예제 #1
0
 protected override void InitializeWorker(AnalysisContext context)
 {
     context.RegisterSyntaxTreeAction(c =>
     {
         var codingConventionsManager = new AnalyzerConfigCodingConventionsManager(c.Tree, c.Options);
         AnalyzeSyntaxTree(c, codingConventionsManager);
     });
 }
예제 #2
0
        private async Task <OptionSet> GetOptionsAsync(Document document, CancellationToken cancellationToken)
        {
            OptionSet options = CompilerAnalyzerConfigOptions.Empty;

            // The in-IDE workspace supports .editorconfig without special handling. However, the AdhocWorkspace used
            // in testing requires manual handling of .editorconfig.
            if (File.Exists(document.FilePath ?? document.Name))
            {
                var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);

                var codingConventionsManager = new AnalyzerConfigCodingConventionsManager(tree, document.Project.AnalyzerOptions);
                var codingConventionContext  = await codingConventionsManager.GetConventionContextAsync(document.FilePath ?? document.Name, cancellationToken).ConfigureAwait(false);

                options = ApplyFormattingOptions(options, codingConventionContext);
            }

            return(options);
        }