public void Reanalyze(Workspace workspace, IIncrementalAnalyzer analyzer, IEnumerable<ProjectId> projectIds, IEnumerable<DocumentId> documentIds)
        {
            lock (_gate)
            {
                var coordinator = default(WorkCoordinator);
                if (!_documentWorkCoordinatorMap.TryGetValue(workspace, out coordinator))
                {
                    throw new ArgumentException("workspace");
                }

                // no specific projects or documents provided
                if (projectIds == null && documentIds == null)
                {
                    coordinator.Reanalyze(analyzer, workspace.CurrentSolution.Projects.SelectMany(p => p.DocumentIds).ToSet());
                    return;
                }

                // specific documents provided
                if (projectIds == null)
                {
                    coordinator.Reanalyze(analyzer, documentIds.ToSet());
                    return;
                }

                var solution = workspace.CurrentSolution;
                var set = new HashSet<DocumentId>(documentIds ?? SpecializedCollections.EmptyEnumerable<DocumentId>());
                set.Union(projectIds.Select(id => solution.GetProject(id)).SelectMany(p => p.DocumentIds));

                coordinator.Reanalyze(analyzer, set);
            }
        }
 public void AddAnalyzer(IIncrementalAnalyzer analyzer)
 {
     lock (_gate)
     {
         var analyzers = _lazyAnalyzers.Value;
         _lazyAnalyzers = new Lazy<ImmutableArray<IIncrementalAnalyzer>>(() => analyzers.Add(analyzer));
     }
 }
Exemplo n.º 3
0
 public void Reanalyze(Workspace workspace, IIncrementalAnalyzer analyzer, IEnumerable<ProjectId> projectIds = null, IEnumerable<DocumentId> documentIds = null, bool highPriority = false)
 {
     // if solution crawler doesn't exist for the given workspace. don't do anything
     var registration = workspace.Services.GetService<ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService;
     if (registration != null)
     {
         registration.Reanalyze(workspace, analyzer, projectIds, documentIds, highPriority);
     }
 }
Exemplo n.º 4
0
 public static void LogReanalyze(int correlationId, IIncrementalAnalyzer analyzer, IEnumerable<DocumentId> documentIds)
 {
     Logger.Log(FunctionId.WorkCoordinatorRegistrationService_Reanalyze, KeyValueLogMessage.Create(m =>
     {
         m[Id] = correlationId;
         m[Analyzer] = analyzer.ToString();
         m[DocumentCount] = documentIds == null ? 0 : documentIds.Count();
     }));
 }
Exemplo n.º 5
0
            public void AddAnalyzer(IIncrementalAnalyzer analyzer, bool highPriorityForActiveFile)
            {
                // add analyzer
                _documentAndProjectWorkerProcessor.AddAnalyzer(analyzer, highPriorityForActiveFile);

                // and ask to re-analyze whole solution for the given analyzer
                var set = _registration.CurrentSolution.Projects.SelectMany(p => p.DocumentIds).ToSet();
                Reanalyze(analyzer, set);
            }
                public void AddAnalyzer(IIncrementalAnalyzer analyzer, bool highPriorityForActiveFile)
                {
                    if (highPriorityForActiveFile)
                    {
                        _highPriorityProcessor.AddAnalyzer(analyzer);
                    }

                    _normalPriorityProcessor.AddAnalyzer(analyzer);
                    _lowPriorityProcessor.AddAnalyzer(analyzer);
                }
Exemplo n.º 7
0
            private async Task EnqueueWorkItemAsync(IIncrementalAnalyzer analyzer, ReanalyzeScope scope, bool highPriority)
            {
                var solution          = _registration.GetSolutionToAnalyze();
                var invocationReasons = highPriority ? InvocationReasons.ReanalyzeHighPriority : InvocationReasons.Reanalyze;

                foreach (var(project, documentId) in scope.GetDocumentIds(solution))
                {
                    await EnqueueWorkItemAsync(analyzer, project, documentId, document : null, invocationReasons).ConfigureAwait(false);
                }
            }
 public void AddAnalyzer(IIncrementalAnalyzer analyzer)
 {
     lock (_gate)
     {
         var analyzers = _lazyAnalyzers.Value;
         _lazyAnalyzers = new Lazy <ImmutableArray <IIncrementalAnalyzer> >(
             () => analyzers.Add(analyzer)
             );
     }
 }
Exemplo n.º 9
0
 public static void LogReanalyze(int correlationId, IIncrementalAnalyzer analyzer, IEnumerable <DocumentId> documentIds, bool highPriority)
 {
     Logger.Log(FunctionId.WorkCoordinatorRegistrationService_Reanalyze, KeyValueLogMessage.Create(m =>
     {
         m[Id]            = correlationId;
         m[Analyzer]      = analyzer.ToString();
         m[DocumentCount] = documentIds == null ? 0 : documentIds.Count();
         m[HighPriority]  = highPriority;
     }));
 }
Exemplo n.º 10
0
            public void AddAnalyzer(IIncrementalAnalyzer analyzer, bool highPriorityForActiveFile)
            {
                // add analyzer
                _documentAndProjectWorkerProcessor.AddAnalyzer(analyzer, highPriorityForActiveFile);

                // and ask to re-analyze whole solution for the given analyzer
                var set = _registration.CurrentSolution.Projects.SelectMany(p => p.DocumentIds).ToSet();

                Reanalyze(analyzer, set);
            }
Exemplo n.º 11
0
            public void AddAnalyzer(IIncrementalAnalyzer analyzer, bool highPriorityForActiveFile)
            {
                // add analyzer
                _documentAndProjectWorkerProcessor.AddAnalyzer(analyzer, highPriorityForActiveFile);

                // and ask to re-analyze whole solution for the given analyzer
                var scope = new ReanalyzeScope(_registration.GetSolutionToAnalyze().Id);

                Reanalyze(analyzer, scope);
            }
Exemplo n.º 12
0
        public static BackgroundAnalysisScope GetOverriddenBackgroundAnalysisScope(this IIncrementalAnalyzer incrementalAnalyzer, OptionSet options, BackgroundAnalysisScope defaultBackgroundAnalysisScope)
        {
            // Unit testing analyzer has special semantics for analysis scope.
            if (incrementalAnalyzer is UnitTestingIncrementalAnalyzer)
            {
                return(UnitTestingIncrementalAnalyzer.GetBackgroundAnalysisScope(options));
            }

            return(defaultBackgroundAnalysisScope);
        }
Exemplo n.º 13
0
            public void Reanalyze(Workspace workspace, IIncrementalAnalyzer analyzer, IEnumerable <ProjectId> projectIds = null, IEnumerable <DocumentId> documentIds = null)
            {
                // if solution crawler doesn't exist for the given workspace. don't do anything
                var registration = workspace.Services.GetService <ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService;

                if (registration != null)
                {
                    registration.Reanalyze(workspace, analyzer, projectIds, documentIds);
                }
            }
Exemplo n.º 14
0
            private async Task EnqueueWorkItemAsync(IIncrementalAnalyzer analyzer, ReanalyzeScope scope, bool highPriority)
            {
                var solution          = _registration.CurrentSolution;
                var invocationReasons = highPriority ? InvocationReasons.ReanalyzeHighPriority : InvocationReasons.Reanalyze;

                foreach (var document in scope.GetDocuments(solution))
                {
                    await EnqueueWorkItemAsync(analyzer, document, invocationReasons).ConfigureAwait(false);
                }
            }
Exemplo n.º 15
0
            private async Task EnqueueWorkItemAsync(
                IIncrementalAnalyzer analyzer, Project project, DocumentId documentId, Document?document, InvocationReasons invocationReasons)
            {
                var priorityService = project.GetLanguageService <IWorkCoordinatorPriorityService>();
                var isLowPriority   = priorityService != null && await priorityService.IsLowPriorityAsync(
                    GetRequiredDocument(project, documentId, document), _shutdownToken).ConfigureAwait(false);

                _documentAndProjectWorkerProcessor.Enqueue(
                    new WorkItem(documentId, project.Language, invocationReasons,
                                 isLowPriority, analyzer, _listener.BeginAsyncOperation("WorkItem")));
            }
Exemplo n.º 16
0
 static async Task AnalyzeSyntaxAsync(IIncrementalAnalyzer analyzer, TextDocument textDocument, InvocationReasons reasons, CancellationToken cancellationToken)
 {
     if (textDocument is Document document)
     {
         await analyzer.AnalyzeSyntaxAsync((Document)document, reasons, cancellationToken).ConfigureAwait(false);
     }
     else if (analyzer is IIncrementalAnalyzer2 analyzer2)
     {
         await analyzer2.AnalyzeNonSourceDocumentAsync(textDocument, reasons, cancellationToken).ConfigureAwait(false);
     }
 }
Exemplo n.º 17
0
 static async Task DocumentResetAsync(IIncrementalAnalyzer analyzer, TextDocument textDocument, CancellationToken cancellationToken)
 {
     if (textDocument is Document document)
     {
         await analyzer.DocumentResetAsync(document, cancellationToken).ConfigureAwait(false);
     }
     else if (analyzer is IIncrementalAnalyzer2 analyzer2)
     {
         await analyzer2.NonSourceDocumentResetAsync(textDocument, cancellationToken).ConfigureAwait(false);
     }
 }
        private bool TryGetAnalyzer(Project project, out IIncrementalAnalyzer analyzer)
        {
            if (!this.Analyzers.TryGetValue(project.Language, out var lazyAnalyzer))
            {
                analyzer = null;
                return(false);
            }

            analyzer = lazyAnalyzer.Value;
            return(true);
        }
        private bool TryGetAnalyzer(Project project, out IIncrementalAnalyzer analyzer)
        {
            Lazy<IIncrementalAnalyzer> lazyAnalyzer;
            if (!this.Analyzers.TryGetValue(project.Language, out lazyAnalyzer))
            {
                analyzer = null;
                return false;
            }

            analyzer = lazyAnalyzer.Value;
            return true;
        }
Exemplo n.º 20
0
            public void Reanalyze(IIncrementalAnalyzer analyzer, ISet <DocumentId> documentIds, bool highPriority = false)
            {
                var asyncToken = _listener.BeginAsyncOperation("Reanalyze");

                _eventProcessingQueue.ScheduleTask(
                    () => EnqueueWorkItemAsync(analyzer, documentIds, highPriority), _shutdownToken).CompletesAsyncOperation(asyncToken);

                if (documentIds?.Count > 1)
                {
                    // log big reanalysis request from things like fix all, suppress all or option changes
                    // we are not interested in 1 file re-analysis request which can happen from like venus typing
                    SolutionCrawlerLogger.LogReanalyze(CorrelationId, analyzer, documentIds, highPriority);
                }
            }
Exemplo n.º 21
0
            public void Reanalyze(IIncrementalAnalyzer analyzer, ReanalyzeScope scope, bool highPriority = false)
            {
                _eventProcessingQueue.ScheduleTask("Reanalyze",
                                                   () => EnqueueWorkItemAsync(analyzer, scope, highPriority), _shutdownToken);

                if (scope.HasMultipleDocuments)
                {
                    // log big reanalysis request from things like fix all, suppress all or option changes
                    // we are not interested in 1 file re-analysis request which can happen from like venus typing
                    var solution = _registration.CurrentSolution;
                    SolutionCrawlerLogger.LogReanalyze(
                        CorrelationId, analyzer, scope.GetDocumentCount(solution), scope.GetLanguagesStringForTelemetry(solution), highPriority);
                }
            }
Exemplo n.º 22
0
 public static void LogReanalyze(
     int correlationId,
     IIncrementalAnalyzer analyzer,
     int documentCount,
     string languages,
     bool highPriority)
 {
     Logger.Log(FunctionId.WorkCoordinatorRegistrationService_Reanalyze, KeyValueLogMessage.Create(m =>
     {
         m[Id]            = correlationId;
         m[Analyzer]      = analyzer.ToString();
         m[DocumentCount] = documentCount;
         m[HighPriority]  = highPriority;
         m[Languages]     = languages;
     }));
 }
Exemplo n.º 23
0
            private void EnqueueWorkItem(IIncrementalAnalyzer analyzer, IEnumerable <DocumentId> documentIds)
            {
                var solution = _workspace.CurrentSolution;

                foreach (var documentId in documentIds)
                {
                    var document = solution.GetDocument(documentId);
                    if (document == null)
                    {
                        continue;
                    }

                    var priorityService = document.GetLanguageService <IWorkCoordinatorPriorityService>();

                    _documentAndProjectWorkerProcessor.Enqueue(
                        new WorkItem(documentId, document.Project.Language, InvocationReasons.Reanalyze,
                                     priorityService != null && priorityService.IsLowPriority(document),
                                     analyzer, _listener.BeginAsyncOperation("WorkItem")));
                }
            }
Exemplo n.º 24
0
            private async Task EnqueueWorkItemAsync(IIncrementalAnalyzer analyzer, IEnumerable <DocumentId> documentIds)
            {
                var solution = _registration.CurrentSolution;

                foreach (var documentId in documentIds)
                {
                    var document = solution.GetDocument(documentId);
                    if (document == null)
                    {
                        continue;
                    }

                    var priorityService = document.GetLanguageService <IWorkCoordinatorPriorityService>();
                    var isLowPriority   = priorityService != null && await priorityService.IsLowPriorityAsync(document, _shutdownToken).ConfigureAwait(false);

                    _documentAndProjectWorkerProcessor.Enqueue(
                        new WorkItem(documentId, document.Project.Language, InvocationReasons.Reanalyze,
                                     isLowPriority, analyzer, _listener.BeginAsyncOperation("WorkItem")));
                }
            }
        public void Reanalyze(Workspace workspace, IIncrementalAnalyzer analyzer, IEnumerable <ProjectId>?projectIds, IEnumerable <DocumentId>?documentIds, bool highPriority)
        {
            lock (_gate)
            {
                if (!_documentWorkCoordinatorMap.TryGetValue(workspace, out var coordinator))
                {
                    // this can happen if solution crawler is already unregistered from workspace.
                    // one of those example will be VS shutting down so roslyn package is disposed but there is a pending
                    // async operation.
                    return;
                }

                // no specific projects or documents provided
                if (projectIds == null && documentIds == null)
                {
                    coordinator.Reanalyze(analyzer, new ReanalyzeScope(workspace.CurrentSolution.Id), highPriority);
                    return;
                }

                coordinator.Reanalyze(analyzer, new ReanalyzeScope(projectIds, documentIds), highPriority);
            }
        }
Exemplo n.º 26
0
 public void Reanalyze(
     Workspace workspace,
     IIncrementalAnalyzer analyzer,
     IEnumerable <ProjectId>?projectIds   = null,
     IEnumerable <DocumentId>?documentIds = null,
     bool highPriority = false
     )
 {
     // if solution crawler doesn't exist for the given workspace. don't do anything
     if (
         workspace.Services.GetService <ISolutionCrawlerRegistrationService>()
         is SolutionCrawlerRegistrationService registration
         )
     {
         registration.Reanalyze(
             workspace,
             analyzer,
             projectIds,
             documentIds,
             highPriority
             );
     }
 }
Exemplo n.º 27
0
            private void EnqueueWorkItem(IIncrementalAnalyzer analyzer, IEnumerable<DocumentId> documentIds)
            {
                var solution = _workspace.CurrentSolution;
                foreach (var documentId in documentIds)
                {
                    var document = solution.GetDocument(documentId);
                    if (document == null)
                    {
                        continue;
                    }

                    var priorityService = document.GetLanguageService<IWorkCoordinatorPriorityService>();

                    _documentAndProjectWorkerProcessor.Enqueue(
                        new WorkItem(documentId, document.Project.Language, InvocationReasons.Reanalyze,
                        priorityService != null && priorityService.IsLowPriority(document),
                        analyzer, _listener.BeginAsyncOperation("WorkItem")));
                }
            }
 public WorkItem(
     DocumentId documentId, string language, InvocationReasons invocationReasons, bool isLowPriority,
     IIncrementalAnalyzer analyzer, IAsyncToken asyncToken)
     : this(documentId, documentId.ProjectId, language, invocationReasons, isLowPriority,
            null, analyzer == null ? ImmutableHashSet.Create<IIncrementalAnalyzer>() : ImmutableHashSet.Create<IIncrementalAnalyzer>(analyzer),
            false, asyncToken)
 {
 }
Exemplo n.º 29
0
            public void Reanalyze(IIncrementalAnalyzer analyzer, IEnumerable<DocumentId> documentIds)
            {
                var asyncToken = _listener.BeginAsyncOperation("Reanalyze");
                _eventProcessingQueue.ScheduleTask(
                    () => EnqueueWorkItemAsync(analyzer, documentIds), _shutdownToken).CompletesAsyncOperation(asyncToken);

                SolutionCrawlerLogger.LogReanalyze(CorrelationId, analyzer, documentIds);
            }
Exemplo n.º 30
0
            private async Task EnqueueWorkItemAsync(IIncrementalAnalyzer analyzer, IEnumerable<DocumentId> documentIds)
            {
                var solution = _registration.CurrentSolution;
                foreach (var documentId in documentIds)
                {
                    var document = solution.GetDocument(documentId);
                    if (document == null)
                    {
                        continue;
                    }

                    var priorityService = document.GetLanguageService<IWorkCoordinatorPriorityService>();
                    var isLowPriority = priorityService != null && await priorityService.IsLowPriorityAsync(document, _shutdownToken).ConfigureAwait(false);

                    _documentAndProjectWorkerProcessor.Enqueue(
                        new WorkItem(documentId, document.Project.Language, InvocationReasons.Reanalyze,
                        isLowPriority, analyzer, _listener.BeginAsyncOperation("WorkItem")));
                }
            }
 public void Reanalyze(Workspace workspace, IIncrementalAnalyzer analyzer, IEnumerable<ProjectId> projectIds = null, IEnumerable<DocumentId> documentIds = null)
 {
     var registration = workspace.Services.GetService<IWorkCoordinatorRegistrationService>() as WorkCoordinatorRegistrationService;
     if (registration != null)
     {
         registration.Reanalyze(workspace, analyzer, projectIds, documentIds);
     }
 }
 private static async Task RunAllAnalysisAsync(IIncrementalAnalyzer analyzer, Document document)
 {
     await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None).ConfigureAwait(false);
     await analyzer.AnalyzeDocumentAsync(document, bodyOpt: null, reasons: InvocationReasons.Empty, cancellationToken: CancellationToken.None).ConfigureAwait(false);
     await analyzer.AnalyzeProjectAsync(document.Project, semanticsChanged: true, reasons: InvocationReasons.Empty, cancellationToken: CancellationToken.None).ConfigureAwait(false);
 }