Beispiel #1
0
        public async Task ApplyProjectBuildAsync(IProjectVersionedValue <IProjectSubscriptionUpdate> update,
                                                 IProjectBuildSnapshot buildSnapshot,
                                                 ContextState state,
                                                 CancellationToken cancellationToken)
        {
            Requires.NotNull(update, nameof(update));

            VerifyInitializedAndNotDisposed();

            IProjectChangeDescription projectChange = update.Value.ProjectChanges[ProjectBuildRuleName];

            if (projectChange.Difference.AnyChanges)
            {
                IComparable version = GetConfiguredProjectVersion(update);

                ProcessOptions(buildSnapshot);
                await ProcessCommandLineAsync(version, projectChange.Difference, state, cancellationToken);

                ProcessProjectBuildFailure(projectChange.After);
            }
        }
        private void ProcessProjectBuildFailure(IProjectRuleSnapshot snapshot, ContextState state)
        {
            Assumes.NotNull(_context);

            // If 'CompileDesignTime' didn't run due to a preceding failed target, or a failure in itself, IsEvaluationSucceeded returns false.
            //
            // We still forward those 'removes' of references, sources, etc onto Roslyn to avoid duplicate/incorrect results when the next
            // successful build occurs, because it will be diff between it and this failed build.

            bool succeeded = snapshot.IsEvaluationSucceeded();

            if (!succeeded)
            {
                _languageServiceTelemetryService.PostDesignTimeBuildFailureEvent();
            }

            if (_context.LastDesignTimeBuildSucceeded != succeeded)
            {
                _logger.WriteLine(succeeded ? "Last design-time build succeeded, turning semantic errors back on." : "Last design-time build failed, turning semantic errors off.");
                _context.LastDesignTimeBuildSucceeded = succeeded;
            }
        }
            private async Task ApplyProjectChangesUnderLockAsync(ProjectChange change, WorkspaceContextHandlerType handlerType, CancellationToken cancellationToken)
            {
                // NOTE we cannot call CheckForInitialized here, as this method may be invoked during initialization
                Assumes.NotNull(_contextAccessor);

                IWorkspaceProjectContext context = _contextAccessor.Context;
                bool isActiveEditorContext       = _activeWorkspaceProjectContextTracker.IsActiveEditorContext(_contextAccessor.ContextId);
                bool isActiveConfiguration       = change.Project == _project;

                var state = new ContextState(isActiveEditorContext, isActiveConfiguration);

                context.StartBatch();

                try
                {
                    switch (handlerType)
                    {
                    case WorkspaceContextHandlerType.Evaluation:
                        await _applyChangesToWorkspaceContext !.Value.ApplyProjectEvaluationAsync(change.Subscription, state, cancellationToken);
                        break;

                    case WorkspaceContextHandlerType.ProjectBuild:
                        Assumes.NotNull(change.BuildSnapshot);
                        await _applyChangesToWorkspaceContext !.Value.ApplyProjectBuildAsync(change.Subscription, change.BuildSnapshot, state, cancellationToken);
                        break;

                    case WorkspaceContextHandlerType.SourceItems:
                        await _applyChangesToWorkspaceContext !.Value.ApplySourceItemsAsync(change.Subscription, state, cancellationToken);
                        break;
                    }
                }
                finally
                {
                    await context.EndBatchAsync();

                    NotifyOutputDataCalculated(change.DataSourceVersions, handlerType);
                }
            }
        public Task ApplyProjectEvaluationAsync(IProjectVersionedValue <IProjectSubscriptionUpdate> update, ContextState state, CancellationToken cancellationToken)
        {
            Requires.NotNull(update, nameof(update));

            VerifyInitializedAndNotDisposed();

            IComparable version = GetConfiguredProjectVersion(update);

            return(ProcessProjectEvaluationHandlersAsync(version, update, state, cancellationToken));
        }
        private Task ProcessProjectEvaluationHandlersAsync(IComparable version, IProjectVersionedValue <IProjectSubscriptionUpdate> update, ContextState state, CancellationToken cancellationToken)
        {
            int invokedHandlers = 0;

            foreach (ExportLifetimeContext <IWorkspaceContextHandler> handler in _handlers)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (handler.Value is IProjectEvaluationHandler evaluationHandler)
                {
                    IProjectChangeDescription projectChange = update.Value.ProjectChanges[evaluationHandler.ProjectEvaluationRule];
                    if (!projectChange.Difference.AnyChanges)
                    {
                        continue;
                    }

                    evaluationHandler.Handle(version, projectChange, state, _logger);
                    invokedHandlers++;
                }
            }

            _languageServiceTelemetryService.PostLanguageServiceEvent(LanguageServiceOperationNames.ProjectEvaluationHandlersProcessed, invokedHandlers);

            return(Task.CompletedTask);
        }
        private Task ProcessCommandLineHandlersAsync(IComparable version, BuildOptions added, BuildOptions removed, ContextState state, CancellationToken cancellationToken)
        {
            int invokedHandlers = 0;

            foreach (ExportLifetimeContext <IWorkspaceContextHandler> handler in _handlers)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (handler.Value is ICommandLineHandler commandLineHandler)
                {
                    commandLineHandler.Handle(version, added, removed, state, _logger);
                    invokedHandlers++;
                }
            }

            _languageServiceTelemetryService.PostLanguageServiceEvent(LanguageServiceOperationNames.CommandLineParsersProcessed, invokedHandlers);

            return(Task.CompletedTask);
        }
        private Task ProcessCommandLineAsync(IComparable version, IProjectChangeDiff differences, ContextState state, CancellationToken cancellationToken)
        {
            ICommandLineParserService?parser = CommandLineParsers.FirstOrDefault()?.Value;

            Assumes.Present(parser);

            string baseDirectory = Path.GetDirectoryName(_project.UnconfiguredProject.FullPath);

            BuildOptions added   = parser !.Parse(differences.AddedItems, baseDirectory);
            BuildOptions removed = parser.Parse(differences.RemovedItems, baseDirectory);

            return(ProcessCommandLineHandlersAsync(version, added, removed, state, cancellationToken));
        }
Beispiel #8
0
        private Task ProcessProjectEvaluationHandlersAsync(IComparable version, IProjectVersionedValue <IProjectSubscriptionUpdate> update, ContextState state, CancellationToken cancellationToken)
        {
            foreach (ExportLifetimeContext <IWorkspaceContextHandler> handler in _handlers)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (handler.Value is IProjectEvaluationHandler evaluationHandler)
                {
                    IProjectChangeDescription projectChange = update.Value.ProjectChanges[evaluationHandler.ProjectEvaluationRule];
                    if (!projectChange.Difference.AnyChanges)
                    {
                        continue;
                    }

                    evaluationHandler.Handle(version, projectChange, state, _logger);
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #9
0
        private Task ProcessCommandLineHandlersAsync(IComparable version, BuildOptions added, BuildOptions removed, ContextState state, CancellationToken cancellationToken)
        {
            foreach (ExportLifetimeContext <IWorkspaceContextHandler> handler in _handlers)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (handler.Value is ICommandLineHandler commandLineHandler)
                {
                    commandLineHandler.Handle(version, added, removed, state, _logger);
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #10
0
        private Task ProcessSourceItemsHandlersAsync(IComparable version, IProjectVersionedValue <IProjectSubscriptionUpdate> update, ContextState state, CancellationToken cancellationToken)
        {
            foreach (ExportLifetimeContext <IWorkspaceContextHandler> handler in _handlers)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (handler.Value is ISourceItemsHandler sourceItemsHandler)
                {
                    sourceItemsHandler.Handle(version, update.Value.ProjectChanges, state, _logger);
                }
            }

            return(Task.CompletedTask);
        }