コード例 #1
0
        public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
        {
            context.CancellationToken.ThrowIfCancellationRequested();

            AcuminatorVsixPackageLoader.EnsurePackageLoaded();

            if (!_settingsProvidedExternally)
            {
                CodeAnalysisSettings = AnalyzersOutOfProcessSettingsProvider.GetCodeAnalysisSettings();                 //Initialize settings from global values after potential package load
            }
            if (!CodeAnalysisSettings.StaticAnalysisEnabled)
            {
                return;
            }

            SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);

            if (semanticModel?.Compilation == null)
            {
                return;
            }

            var pxContext = new PXContext(semanticModel.Compilation, CodeAnalysisSettings);

            if (ShouldAnalyze(semanticModel, pxContext))
            {
                await ComputeRefactoringsAsync(context, semanticModel, pxContext).ConfigureAwait(false);
            }
        }
コード例 #2
0
        public override void Initialize(AnalysisContext context)
        {
            AcuminatorVsixPackageLoader.EnsurePackageLoaded();

            if (!_settingsProvidedExternally)
            {
                CodeAnalysisSettings = AnalyzersOutOfProcessSettingsProvider.GetCodeAnalysisSettings();                 //Initialize settings from global values after potential package load
            }
            if (!CodeAnalysisSettings !.StaticAnalysisEnabled)
            {
                return;
            }

            context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
            context.EnableConcurrentExecution();

            context.RegisterCompilationStartAction(compilationStartContext =>
            {
                var pxContext = new PXContext(compilationStartContext.Compilation, CodeAnalysisSettings);

                if (ShouldAnalyze(pxContext))
                {
                    AnalyzeCompilation(compilationStartContext, pxContext);
                }
            });
        }