Esempio n. 1
0
        public async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
        {
            Contract.ThrowIfFalse(project.IsFromPrimaryBranch());
            cancellationToken.ThrowIfCancellationRequested();

            var vsWorkspace = project.Solution.Workspace as VisualStudioWorkspaceImpl;

            if (vsWorkspace == null)
            {
                return;
            }

            if (!vsWorkspace.Options.GetOption(InternalFeatureOnOffOptions.DesignerAttributes))
            {
                return;
            }

            // CPS projects do not support designer attributes.  So we just skip these projects entirely.
            var isCPSProject = await Task.Factory.StartNew(
                () => vsWorkspace.IsCPSProject(project),
                cancellationToken,
                TaskCreationOptions.None,
                this.ForegroundTaskScheduler).ConfigureAwait(false);

            if (isCPSProject)
            {
                return;
            }

            var service = project.LanguageServices.GetService <IDesignerAttributeService>();

            if (service == null)
            {
                // project doesn't support designer attribute service.
                return;
            }

            // Try to compute this data in the remote process.  If that fails, then compute
            // the results in the local process.
            var pathToResult = await TryAnalyzeProjectInRemoteProcessAsync(project, cancellationToken).ConfigureAwait(false);

            if (pathToResult == null)
            {
                pathToResult = await AbstractDesignerAttributeService.TryAnalyzeProjectInCurrentProcessAsync(
                    project, cancellationToken).ConfigureAwait(false);
            }

            cancellationToken.ThrowIfCancellationRequested();

            // Once we get the current data, diff it and report the results to VS.
            RegisterDesignerAttributes(project, pathToResult);
        }
        /// <summary>
        /// This is top level entry point for DesignerAttribute service from client (VS).
        ///
        /// This will be called by ServiceHub/JsonRpc framework
        /// </summary>
        public async Task <ImmutableArray <DesignerAttributeDocumentData> > ScanDesignerAttributesAsync(ProjectId projectId)
        {
            using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_GetDesignerAttributesAsync, projectId.DebugName, CancellationToken))
            {
                var solution = await GetSolutionAsync().ConfigureAwait(false);

                var project = solution.GetProject(projectId);
                var data    = await AbstractDesignerAttributeService.TryAnalyzeProjectInCurrentProcessAsync(
                    project, CancellationToken).ConfigureAwait(false);

                return(data.Values.ToImmutableArray());
            }
        }
        /// <summary>
        /// This is top level entry point for DesignerAttribute service from client (VS).
        ///
        /// This will be called by ServiceHub/JsonRpc framework
        /// </summary>
        public async Task <IList <DesignerAttributeDocumentData> > ScanDesignerAttributesAsync(ProjectId projectId, CancellationToken cancellationToken)
        {
            using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_GetDesignerAttributesAsync, projectId.DebugName, cancellationToken))
            {
                var solution = await GetSolutionAsync(cancellationToken).ConfigureAwait(false);

                var project = solution.GetProject(projectId);

                var data = await AbstractDesignerAttributeService.TryAnalyzeProjectInCurrentProcessAsync(
                    project, cancellationToken).ConfigureAwait(false);

                if (data.Count == 0)
                {
                    return(SpecializedCollections.EmptyList <DesignerAttributeDocumentData>());
                }

                return(data.Values.ToList());
            }
        }