Example #1
0
 public RoslynDocumentProvider(
     IVisualStudioHostProjectContainer projectContainer,
     IServiceProvider serviceProvider,
     IDocumentTrackingService documentTrackingService = null)
     : base(projectContainer, serviceProvider, signUpForFileChangeNotification: true)
 {
     _documentTrackingService = documentTrackingService as VisualStudioDocumentTrackingService;
 }
        public VisualStudioErrorReportingService(
            VisualStudioWorkspaceImpl workspace, IForegroundNotificationService foregroundNotificationService, IAsynchronousOperationListener listener)
        {
            _workspace = workspace;
            _foregroundNotificationService = foregroundNotificationService;
            _listener = listener;

            _documentTrackingService = workspace.Services.GetService<IDocumentTrackingService>();
        }
            public ActiveProjectCacheManager(IDocumentTrackingService documentTrackingService, ProjectCacheService projectCacheService)
            {
                _documentTrackingService = documentTrackingService;
                _projectCacheService = projectCacheService;

                if (documentTrackingService != null)
                {
                    documentTrackingService.ActiveDocumentChanged += UpdateCache;
                    UpdateCache(null, documentTrackingService.GetActiveDocument());
                }
            }
Example #4
0
            public WorkCoordinator(
                IAsynchronousOperationListener listener,
                IEnumerable <Lazy <IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata> > analyzerProviders,
                bool initializeLazily,
                Registration registration)
            {
                _logAggregator = new LogAggregator();

                _registration = registration;
                _gate         = new object();

                _listener                = listener;
                _optionService           = _registration.GetService <IOptionService>();
                _documentTrackingService = _registration.GetService <IDocumentTrackingService>();

                // event and worker queues
                _shutdownNotificationSource = new CancellationTokenSource();
                _shutdownToken = _shutdownNotificationSource.Token;

                _eventProcessingQueue = new SimpleTaskQueue(TaskScheduler.Default);

                var activeFileBackOffTimeSpanInMS          = _optionService.GetOption(InternalSolutionCrawlerOptions.ActiveFileWorkerBackOffTimeSpanInMS);
                var allFilesWorkerBackOffTimeSpanInMS      = _optionService.GetOption(InternalSolutionCrawlerOptions.AllFilesWorkerBackOffTimeSpanInMS);
                var entireProjectWorkerBackOffTimeSpanInMS = _optionService.GetOption(InternalSolutionCrawlerOptions.EntireProjectWorkerBackOffTimeSpanInMS);

                _documentAndProjectWorkerProcessor = new IncrementalAnalyzerProcessor(
                    listener, analyzerProviders, initializeLazily, _registration,
                    activeFileBackOffTimeSpanInMS, allFilesWorkerBackOffTimeSpanInMS, entireProjectWorkerBackOffTimeSpanInMS, _shutdownToken);

                var semanticBackOffTimeSpanInMS = _optionService.GetOption(InternalSolutionCrawlerOptions.SemanticChangeBackOffTimeSpanInMS);
                var projectBackOffTimeSpanInMS  = _optionService.GetOption(InternalSolutionCrawlerOptions.ProjectPropagationBackOffTimeSpanInMS);

                _semanticChangeProcessor = new SemanticChangeProcessor(listener, _registration, _documentAndProjectWorkerProcessor, semanticBackOffTimeSpanInMS, projectBackOffTimeSpanInMS, _shutdownToken);

                // if option is on
                if (_optionService.GetOption(InternalSolutionCrawlerOptions.SolutionCrawler))
                {
                    _registration.Workspace.WorkspaceChanged += OnWorkspaceChanged;
                    _registration.Workspace.DocumentOpened   += OnDocumentOpened;
                    _registration.Workspace.DocumentClosed   += OnDocumentClosed;
                }

                // subscribe to option changed event after all required fields are set
                // otherwise, we can get null exception when running OnOptionChanged handler
                _optionService.OptionChanged += OnOptionChanged;

                // subscribe to active document changed event for active file background analysis scope.
                if (_documentTrackingService != null)
                {
                    _lastActiveDocument = _documentTrackingService.GetActiveDocument(_registration.Workspace.CurrentSolution);
                    _documentTrackingService.ActiveDocumentChanged += OnActiveDocumentChanged;
                }
            }
Example #5
0
            private async Task SearchProjectsInPriorityOrder(IDocumentTrackingService docTrackingService)
            {
                var processedProjects = new HashSet <Project>();

                var activeDocOpt = docTrackingService.GetActiveDocument(_solution);
                var visibleDocs  = docTrackingService.GetVisibleDocuments(_solution)
                                   .Where(d => d != activeDocOpt)
                                   .ToImmutableArray();

                // First, if there's an active document, search that project first, prioritizing
                // that active document and all visible documents from it.
                if (activeDocOpt != null)
                {
                    var activeProject = activeDocOpt.Project;
                    processedProjects.Add(activeProject);

                    var visibleDocsFromProject = visibleDocs.Where(d => d.Project == activeProject);
                    var priorityDocs           = ImmutableArray.Create(activeDocOpt).AddRange(visibleDocsFromProject);

                    // Search the active project first.  That way we can deliver results that are
                    // closer in scope to the user quicker without forcing them to do something like
                    // NavToInCurrentDoc
                    await Task.Run(() => SearchAsync(activeProject, priorityDocs), _cancellationToken).ConfigureAwait(false);
                }

                // Now, process all visible docs that were not from the active project.
                var tasks = new List <Task>();

                foreach (var(currentProject, priorityDocs) in visibleDocs.GroupBy(d => d.Project))
                {
                    // make sure we only process this project if we didn't already process it above.
                    if (processedProjects.Add(currentProject))
                    {
                        tasks.Add(Task.Run(() => SearchAsync(currentProject, priorityDocs.ToImmutableArray()), _cancellationToken));
                    }
                }

                await Task.WhenAll(tasks).ConfigureAwait(false);

                // Now, process the remainder of projects
                tasks.Clear();
                foreach (var currentProject in _solution.Projects)
                {
                    // make sure we only process this project if we didn't already process it above.
                    if (processedProjects.Add(currentProject))
                    {
                        tasks.Add(Task.Run(() => SearchAsync(currentProject, ImmutableArray <Document> .Empty), _cancellationToken));
                    }
                }

                await Task.WhenAll(tasks).ConfigureAwait(false);
            }
        public FxCopAnalyzersSuggestedActionCallback(
            IThreadingContext threadingContext,
            VisualStudioWorkspace workspace,
            SVsServiceProvider serviceProvider)
            : base(threadingContext)
        {
            _workspace               = workspace;
            _serviceProvider         = serviceProvider;
            _documentTrackingService = workspace.Services.GetService <IDocumentTrackingService>();
            _packageInstallerService = workspace.Services.GetService <IPackageInstallerService>();

            _workspace.WorkspaceChanged += OnWorkspaceChanged;
        }
Example #7
0
            public ActiveProjectCacheManager(
                IDocumentTrackingService documentTrackingService,
                ProjectCacheService projectCacheService
                )
            {
                _projectCacheService = projectCacheService;

                if (documentTrackingService != null)
                {
                    documentTrackingService.ActiveDocumentChanged += UpdateCache;
                    UpdateCache(null, documentTrackingService.TryGetActiveDocument());
                }
            }
Example #8
0
        public NavigateToItemProvider(
            Workspace workspace,
            IAsynchronousOperationListener asyncListener,
            IDocumentTrackingService documentTrackingService)
        {
            Contract.ThrowIfNull(workspace);
            Contract.ThrowIfNull(asyncListener);

            _workspace               = workspace;
            _asyncListener           = asyncListener;
            _documentTrackingService = documentTrackingService;
            _displayFactory          = new NavigateToItemDisplayFactory();
        }
Example #9
0
        public BackgroundParser(Workspace workspace)
        {
            _workspace = workspace;

            var listenerProvider = workspace.Services.GetRequiredService <IWorkspaceAsynchronousOperationListenerProvider>();

            _taskQueue = new TaskQueue(listenerProvider.GetListener(), TaskScheduler.Default);

            _documentTrackingService = workspace.Services.GetService <IDocumentTrackingService>();

            _workspace.WorkspaceChanged += OnWorkspaceChanged;

            workspace.DocumentOpened += OnDocumentOpened;
            workspace.DocumentClosed += OnDocumentClosed;
        }
Example #10
0
        public BackgroundParser(Workspace workspace)
        {
            _workspace = workspace;

            var taskSchedulerFactory = workspace.Services.GetService <IWorkspaceTaskSchedulerFactory>();

            _taskScheduler = taskSchedulerFactory.CreateBackgroundTaskScheduler();

            _documentTrackingService = workspace.Services.GetService <IDocumentTrackingService>();

            _workspace.WorkspaceChanged += OnWorkspaceChanged;

            workspace.DocumentOpened += OnDocumentOpened;
            workspace.DocumentClosed += OnDocumentClosed;
        }
        public DiagnosticIncrementalAnalyzer(
            DiagnosticAnalyzerService analyzerService,
            int correlationId,
            Workspace workspace,
            DiagnosticAnalyzerInfoCache analyzerInfoCache)
        {
            Contract.ThrowIfNull(analyzerService);

            AnalyzerService          = analyzerService;
            Workspace                = workspace;
            _documentTrackingService = workspace.Services.GetRequiredService <IDocumentTrackingService>();

            _correlationId = correlationId;

            _stateManager = new StateManager(workspace, analyzerInfoCache);
            _stateManager.ProjectAnalyzerReferenceChanged += OnProjectAnalyzerReferenceChanged;
            _telemetry = new DiagnosticAnalyzerTelemetry();

            _diagnosticAnalyzerRunner         = new InProcOrRemoteHostAnalyzerRunner(analyzerInfoCache, analyzerService.Listener);
            _projectCompilationsWithAnalyzers = new ConditionalWeakTable <Project, CompilationWithAnalyzers?>();
        }
Example #12
0
                public IncrementalAnalyzerProcessor(
                    IAsynchronousOperationListener listener,
                    IEnumerable <Lazy <IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata> > analyzerProviders,
                    bool initializeLazily,
                    Registration registration,
                    int highBackOffTimeSpanInMs,
                    int normalBackOffTimeSpanInMs,
                    int lowBackOffTimeSpanInMs,
                    CancellationToken shutdownToken)
                {
                    _logAggregator = new LogAggregator();

                    _listener     = listener;
                    _registration = registration;
                    _cacheService = registration.GetService <IProjectCacheService>();

                    _lazyDiagnosticAnalyzerService = new Lazy <IDiagnosticAnalyzerService?>(() => GetDiagnosticAnalyzerService(analyzerProviders));

                    var analyzersGetter = new AnalyzersGetter(analyzerProviders);

                    // create analyzers lazily.
                    var lazyActiveFileAnalyzers = new Lazy <ImmutableArray <IIncrementalAnalyzer> >(() => GetIncrementalAnalyzers(_registration, analyzersGetter, onlyHighPriorityAnalyzer: true));
                    var lazyAllAnalyzers        = new Lazy <ImmutableArray <IIncrementalAnalyzer> >(() => GetIncrementalAnalyzers(_registration, analyzersGetter, onlyHighPriorityAnalyzer: false));

                    if (!initializeLazily)
                    {
                        // realize all analyzer right away
                        _ = lazyActiveFileAnalyzers.Value;
                        _ = lazyAllAnalyzers.Value;
                    }

                    // event and worker queues
                    _documentTracker = _registration.GetService <IDocumentTrackingService>();

                    var globalNotificationService = _registration.GetService <IGlobalOperationNotificationService>();

                    _highPriorityProcessor   = new HighPriorityProcessor(listener, this, lazyActiveFileAnalyzers, highBackOffTimeSpanInMs, shutdownToken);
                    _normalPriorityProcessor = new NormalPriorityProcessor(listener, this, lazyAllAnalyzers, globalNotificationService, normalBackOffTimeSpanInMs, shutdownToken);
                    _lowPriorityProcessor    = new LowPriorityProcessor(listener, this, lazyAllAnalyzers, globalNotificationService, lowBackOffTimeSpanInMs, shutdownToken);
                }
        protected AbstractVisualStudioErrorTaskList(
            SVsServiceProvider serviceProvider,
            VisualStudioWorkspace workspace,
            IForegroundNotificationService notificationService,
            IDiagnosticService diagnosticService,
            IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > asyncListeners) :
            base(serviceProvider, notificationService, FeatureAttribute.ErrorList, asyncListeners)
        {
            _gate = new object();

            _workspace = workspace;

            // we should have document tracking service in visual studio host
            _documentTracker = _workspace.Services.GetService <IDocumentTrackingService>();
            Contract.ThrowIfNull(_documentTracker);

            _taskQueue = new SimpleTaskQueue(TaskScheduler.Default);

            _reportedItemsMap           = new Dictionary <object, VisualStudioTaskItem[]>();
            _notReportedProjectItemsMap = new Dictionary <ProjectId, Dictionary <object, VisualStudioTaskItem[]> >();
            _notReportedDocumentItemMap = new Dictionary <DocumentId, Dictionary <object, VisualStudioTaskItem[]> >();

            _openedFiles  = new HashSet <DocumentId>();
            _inProcessSet = new HashSet <object>();

            _lastNewItemAddedOrRemoved = Environment.TickCount;
            _lastReported = Environment.TickCount;

            _reportRequestRunning = false;
            _reportedCount        = 0;

            if (ErrorListInstalled)
            {
                return;
            }

            // this should be called after all fields are initialized
            InitializeTaskList();
            diagnosticService.DiagnosticsUpdated += this.OnDiagnosticUpdated;
        }
                public IncrementalAnalyzerProcessor(
                    IAsynchronousOperationListener listener,
                    IEnumerable <Lazy <IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata> > analyzerProviders,
                    Registration registration,
                    int highBackOffTimeSpanInMs, int normalBackOffTimeSpanInMs, int lowBackOffTimeSpanInMs, CancellationToken shutdownToken)
                {
                    _logAggregator = new LogAggregator();

                    _listener     = listener;
                    _registration = registration;

                    var lazyActiveFileAnalyzers = new Lazy <ImmutableArray <IIncrementalAnalyzer> >(() => GetActiveFileIncrementalAnalyzers(_registration, analyzerProviders));
                    var lazyAllAnalyzers        = new Lazy <ImmutableArray <IIncrementalAnalyzer> >(() => GetIncrementalAnalyzers(_registration, analyzerProviders));

                    // event and worker queues
                    _documentTracker = _registration.GetService <IDocumentTrackingService>();

                    var globalNotificationService = _registration.GetService <IGlobalOperationNotificationService>();

                    _highPriorityProcessor   = new HighPriorityProcessor(listener, this, lazyActiveFileAnalyzers, highBackOffTimeSpanInMs, shutdownToken);
                    _normalPriorityProcessor = new NormalPriorityProcessor(listener, this, lazyAllAnalyzers, globalNotificationService, normalBackOffTimeSpanInMs, shutdownToken);
                    _lowPriorityProcessor    = new LowPriorityProcessor(listener, this, lazyAllAnalyzers, globalNotificationService, lowBackOffTimeSpanInMs, shutdownToken);
                }
Example #15
0
        private static bool AnalysisEnabled(TextDocument document, IDocumentTrackingService documentTrackingService)
        {
            if (document.Services.GetService <DocumentPropertiesService>()?.DiagnosticsLspClientName != null)
            {
                // This is a generated Razor document, and they want diagnostics, so let's report it
                return(true);
            }

            if (!document.SupportsDiagnostics())
            {
                return(false);
            }

            // change it to check active file (or visible files), not open files if active file tracking is enabled.
            // otherwise, use open file.
            if (SolutionCrawlerOptions.GetBackgroundAnalysisScope(document.Project) == BackgroundAnalysisScope.ActiveFile)
            {
                return(documentTrackingService.TryGetActiveDocument() == document.Id);
            }
            else
            {
                return(document.IsOpen());
            }
        }
                public IncrementalAnalyzerProcessor(
                    IAsynchronousOperationListener listener,
                    int correlationId, Workspace workspace,
                    IEnumerable <Lazy <IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata> > analyzerProviders,
                    int highBackOffTimeSpanInMs, int normalBackOffTimeSpanInMs, int lowBackOffTimeSpanInMs, CancellationToken shutdownToken)
                {
                    this.logAggregator = new LogAggregator();
                    this.listener      = listener;

                    var lazyActiveFileAnalyzers = new Lazy <ImmutableArray <IIncrementalAnalyzer> >(() => GetActiveFileIncrementalAnalyzers(correlationId, workspace, analyzerProviders));
                    var lazyAllAnalyzers        = new Lazy <ImmutableArray <IIncrementalAnalyzer> >(() => GetIncrementalAnalyzers(correlationId, workspace, analyzerProviders));

                    // event and worker queues
                    this.correlationId = correlationId;
                    this.workspace     = workspace;

                    this.documentTracker = workspace.Services.GetService <IDocumentTrackingService>();

                    var globalNotificationService = workspace.Services.GetService <IGlobalOperationNotificationService>();

                    this.highPriorityProcessor   = new HighPriorityProcessor(listener, this, lazyActiveFileAnalyzers, highBackOffTimeSpanInMs, shutdownToken);
                    this.normalPriorityProcessor = new NormalPriorityProcessor(listener, this, lazyAllAnalyzers, globalNotificationService, normalBackOffTimeSpanInMs, shutdownToken);
                    this.lowPriorityProcessor    = new LowPriorityProcessor(listener, this, lazyAllAnalyzers, globalNotificationService, lowBackOffTimeSpanInMs, shutdownToken);
                }
Example #17
0
 internal void InitializeWorkspace(
     TestWorkspace workspace, IDocumentTrackingService documentTrackingService)
 {
     _provider   = new NavigateToItemProvider(workspace, AsynchronousOperationListenerProvider.NullListener, documentTrackingService);
     _aggregator = new NavigateToTestAggregator(_provider);
 }
Example #18
0
 public DocumentTrackingService(IDocumentTrackingService inner)
 {
     _inner = inner;
 }
 public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
 {
     return(_singleton ?? (_singleton = new VisualStudioDocumentTrackingService(_serviceProvider)));
 }
Example #20
0
 public VisualStudioErrorReportingService(VisualStudioWorkspaceImpl workspace, IForegroundNotificationService foregroundNotificationService)
 {
     _workspace = workspace;
     _foregroundNotificationService = foregroundNotificationService;
     _documentTrackingService       = workspace.Services.GetService <IDocumentTrackingService>();
 }
 public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
 {
     return _singleton ?? (_singleton = new VisualStudioDocumentTrackingService(_serviceProvider));
 }
Example #22
0
 /// <summary>
 /// Get a read only collection of all the unique visible documents in the workspace that are
 /// contained within <paramref name="solution"/>.
 /// </summary>
 public static ImmutableArray <Document> GetVisibleDocuments(this IDocumentTrackingService service, Solution solution)
 => service.GetVisibleDocuments()
 .Select(d => solution.GetDocument(d))
 .WhereNotNull()
 .Distinct()
 .ToImmutableArray();
Example #23
0
 /// <summary>
 /// Gets the active <see cref="Document"/> the user is currently working in. May be null if
 /// there is no active document or the active document is not in this <paramref name="solution"/>.
 /// </summary>
 public static Document GetActiveDocument(this IDocumentTrackingService service, Solution solution)
 {
     // Note: GetDocument checks that the DocId is contained in the solution, and returns null if not.
     return(solution.GetDocument(service.TryGetActiveDocument()));
 }
 public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
 {
     return(service ?? (service = new MonoDevelopDocumentTrackingService()));
 }